我正在尝试应用kriging来插入空气污染浓度(目标变量) 当我运行如下的krige函数时,R返回错误。
RSPAVE是目标变量; air是包含RSPAVE的数据集; TPU是shapefile
k.o <- krige(RSPAVE ~1, locations=air, newdata=TPU, model=m.RSPAVE.f)
Error in predict.gstat(g, newdata = newdata, block = block, nsim = nsim, :
gstat: value not allowed for: block kriging for long-lat data undefined
可能是因为我的网格数据是shapefile。但我不想要块克里金法,如何将多边形转为点,并应用普通克里金?
非常感谢!
答案 0 :(得分:0)
假设RSPAVE
是一个SpatialPolygonsDataFrame`并且您希望基于地理质心进行克里奇,这应该有效:
Rpoint <- SpatialPointsDataFrame(coordinates(RSPAVE), data = RSPAVE@data, proj4string = CRS(proj4string(RSPAVE)))
将其转换为点图层。
然后和以前一样:
k.o <- krige(Rpoint ~1, locations=air, newdata=TPU, model=m.RSPAVE.f)
答案 1 :(得分:0)
You say your TPU grid is a shapefile, but what data class is it? If TPU is not a SpatialGridDataFrame
, krige
may not know how to predict on it and default to block
.
To grid TPU, I recommend using something like spsample
followed by gridded()
to overlay a grid on the polygon with dimensions of SomeDimension
.
grid.TPU = spsample(TPU, type = "regular", cellsize = c(SomeDimension, SomeDimension))
gridded(grid.TPU) = TRUE
Then
k.o <- krige(RSPAVE ~1, locations=air, newdata=grid.TPU, model=m.RSPAVE.f)