我正在尝试将 SpatialPointsDataframe 转换为 SpatialGridDataframe,以便使用 landsat 包中的 slopeasp() 函数来获取坡度值。我试图将 SpatialPointsDataframe 转换为栅格以进行转换,但它也不起作用,我得到了错误。
as(pts, "spatialGridDataFrame") 中的错误:没有将“SpatialPointsDataFrame”强制转换为“spatialGridDataFrame”的方法或默认值</p>
下面是我的代码:
#create fake data
x <- rep(rep(seq(12,36,0.5),41))
y <-rep(seq(32,52,0.5), each=49)
z <- rnorm(2009, 26.5, 44.0)
pts <- as.data.frame(matrix(c(x,y,z), ncol=3, byrow=FALSE))
colnames(pts)=c("x", "y", "z")
# create a SpatialPointsDataFrame
coordinates(pts) = ~x+y
# create an empty raster object to the extent of the points
rast <- raster(ext=extent(pts), resolution=250)
# rasterize irregular points
rasOut<-rasterize(pts, rast, pts$z, fun = mean)
#attempt from spdf to sgdf
sgdf <- as(pts, 'spatialGridDataFrame')
#atempt from raster to sgdf
sgdf <- as(rasOut, 'spatialGridDataFrame')
有人对如何获取 spatialGridDataFrame 有任何建议吗?谢谢!