我有一个栅格网格,我想根据包“maptools”的数据提供的世界地图的陆地边界进行裁剪。通过进行一些研究,我发现我必须使用该crop()
功能,然后使用该mask()
功能,但我收到一条错误消息。
这是我的代码:
# load the worldmap SpatialPolygonDataFrame
library(maptools)
data(wrld_simpl)
ll=CRS("+init=epsg:4326")
world<-spTransform(wrld_simpl, ll)
ext<-extent(-10.417,31.917,34.083,71.083)
# get only region covering europe
world@bbox<-as.matrix(ext)
# create the origin in WGS84 CRS
ll = CRS("+init=epsg:4326")
origin = SpatialPoints(cbind(7,40),ll)
# create the raster grid
grid = raster()
# define extent and resolution
e = extent(5,18,40,50)
extent(grid)<-e
res(grid)=c(0.08,0.08)
# fill the raster values
grid[] = runif(1:20250)
# crop the grid with worldmap to erase sea areas
test<-crop(grid,world)
rasterize(world,test)
Found 246 region(s) and 3768 polygon(s)
Error in if (x1a > rxmx) { : argument is of length zero