0

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!

Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
cyrusjan
  • 637
  • 1
  • 8
  • 23

2 Answers2

0

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)
RobinLovelace
  • 4,799
  • 6
  • 29
  • 40
  • Actually, RSPAVE is the target variable; and air is the dataset the contains the RSPAVE; TPU is the shapefile. – cyrusjan Nov 28 '14 at 05:31
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)
Jared Smith
  • 280
  • 3
  • 12