Inverse Distance Weighing

I am trying to conduct IDW using gstat, however, I keep getting this :

Error in predict.gstat(g, newdata = newdata, block = block, nsim = nsim, : var1 : data item in gstat object and newdata have different coordinate reference systems. However, when I check the CRS of both grd and no2_spdf, they are the exact same.

Here is my code

Create an empty grid where n is the total number of cells

grd <- as.data.frame(spsample(as_Spatial(no2_spdf), "regular", n=50000))
names(grd) <- c("X", "Y")
coordinates(grd) <- c("X", "Y")
gridded(grd) <- TRUE # Create SpatialPixel object
fullgrid(grd) <- TRUE # Create SpatialGrid object

Add P's projection information to the empty grid

crs(grd) <- CRS("+init=epsg:4269")
grd

Interpolate the grid cells using a power value of 2 (idp=2.0)

inter <- gstat::idw(Arithmetic.Mean ~ 1, no2_spdf, newdata = grd, idp = 2.0)

Error in predict.gstat(g, newdata = newdata, block = block, nsim = nsim, : var1 : data item in gstat object and newdata have different coordinate reference systems.

Hi, and welcome!

Please see the FAQ: What's a reproducible example (`reprex`) and how do I create one? Using a reprex, complete with representative data will attract quicker and more answers.

Some coding questions are simple enough not to require them. This one, however, is missing the library() calls and the data objects, making it time consuming to reproduce.

The best I can offer is to compare the PROJ of the base and newdata objects:

gstat object and newdata have different coordinate reference systems.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.