How to do kriging with polygon data? (Do not want block kriging)

1.4k views Asked by At

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!

2

There are 2 answers

1
RobinLovelace On

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)
0
Jared Smith On

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)