我有一个SpatialPolygonsDataFrame通过readOGR在rgdal包中使用shapefile读取而创建的。我正在尝试使用它来生成采样网格spsample在该sp包中,以便从该区域收集的调查数据进行插值。但是,SpatialPointsDataFrame所包含的区域比调查范围大得多,因此,插值法预测的值远离进行任何调查的地方。调查数据和shapefile都使用相同的proj4string投影。
我想使用由测量站设置的坐标来对SpatialPolygonsDataFrame进行子集设置,但是我不确定相关值在对象中的存储位置。
恐怕我无法提供相关数据,因为shapefile不是在线托管的。但是,我将从Paul Hiemstra对此荷兰的帖子的回复中借用一些代码:
library(ggplot2)
library(sp)
library(automap)
library(rgdal)
#get the spatial data for the Netherlands
con <- url("http://gadm.org/data/rda/NLD_adm0.RData")
print(load(con))
close(con)
class(gadm)
bbox(gadm)
> min max
>r1 3.360782 7.29271
>r2 50.755165 53.55458
Run Code Online (Sandbox Code Playgroud)
假设调查是在以下领域进行的:
bbox(surveys)
> min max
>r1 4.000 7.000
>r2 51.000 53.000
Run Code Online (Sandbox Code Playgroud)
如何裁剪SpatialPolygonsDataFrame的该区域?
编辑:这个问题似乎回答了我。很抱歉,没有进行足够的搜索(尽管这些评论确实使我对使用rgeos有了一些了解)。但是,gIntersection 导致R崩溃...
fgr*_*egg -1
根据多边形的大小,你可以做类似的事情
range = cbind(c(4,7), c(51,53))
centroids <- coordinates(spdf)
spdf.subset <- spdf[centroids[,1] > range[1,1] &
centroids[,1] < range[2,1] &
centroids[,2] > range[1,2] &
centroids[,2] < range[2,2],]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3494 次 |
| 最近记录: |