对于小多边形和栅格,R中的提取失败

时间:2014-01-04 00:19:07

标签: r geospatial spatial polygons r-raster

此示例应该是可重现的,第一部分(使用大多边形)有效,第二部分失败:

library(raster)

USA.altitude <- getData('alt', country='USA')
lower48 <- USA.alt[[1]]

Srs1 = Polygons(list(Polygon(cbind(c(-96,-95,-95,-96),c(40,40,41,40)))), "s1")
Srs2 = Polygons(list(Polygon(cbind(c(-97,-96,-96,-97),c(40,40,41,40)))), "s2")

spdf.large <- SpatialPolygonsDataFrame( SpatialPolygons(list(Srs1,Srs2)), 
                              data.frame( z=1:2, row.names=c("s1","s2") ) )
plot(spdf.large)
usa.average.elev<-extract(lower48, spdf.large, fun=mean)

耶!一切似乎都好,是吗?现在用小多边形:

Srs3 = Polygons(list(Polygon(cbind(c(-95.01,-94.99,-94.99,-95.01),c(40,40,40.01,40)))), "s3")
Srs4 = Polygons(list(Polygon(cbind(c(-94.01,-93.99,-93.99,-94.01),c(40,40,40.01,40)))), "s4")


spdf.small <- SpatialPolygonsDataFrame( SpatialPolygons(list(Srs3,Srs4)), 
                              data.frame( z=1:2, row.names=c("s3","s4") ) )
plot(spdf.small)
usa.average.elev<-extract(lower48, spdf.small, fun=mean)

因错误而失败:

  

pmax错误(上限(10 / dim(r)[1:2]),c(1,1)):未找到对象'r'

0 个答案:

没有答案