Reputation: 647
I am trying to apply kriging to interpolate the air pollution concentration (target variable) When I run the krige function as below, R return an error.
RSPAVE is the target variable; air is the dataset the contains the RSPAVE; TPU is the 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
It is probably because my grid data is a shapefile. But I don't want block kriging, how can I turn the polygon to point, and apply ordinary kriging?
Thank you very much!
Upvotes: 0
Views: 1604
Reputation: 280
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)
Upvotes: 0
Reputation: 4997
Assuming RSPAVE
is a SpatialPolygonsDataFrame` and that you want to krige based on geographical centroids, this should work:
Rpoint <- SpatialPointsDataFrame(coordinates(RSPAVE), data = RSPAVE@data, proj4string = CRS(proj4string(RSPAVE)))
That converts it to a point layer.
Then same as before:
k.o <- krige(Rpoint ~1, locations=air, newdata=TPU, model=m.RSPAVE.f)
Upvotes: 0