I have a shapefile with fields (TIME, LATITUDE, LONGITUDE, RAINFALL). I am trying to generate IDW interpolation based on TIME(per day).
library(raster)
library(gstat)
library(sp)
library(sf)
library(rgdal)
shp <- readOGR(('*******\\1.shp'))
extent <- extent(shp)
##### Here I generate grid for n elements of time
grd <- list()
for (i in 1:length(shp$TIME)) {
grd[[i]] <- expand.grid(x = seq(from = round(extent@xmin),
to = round(extent@xmax),
by = 1),
y = seq(from = round(extent@ymin),
to = round(extent@ymax),
by = 1))
coordinates(grd[[i]]) <- ~x + y
gridded(grd[[i]]) <- TRUE
proj4string(grd[[i]]) <- proj4string(shp)
}
####Upto above everything works well
idw.list <- list()
for (i in 1:length(grd)){
idw.list[[i]] <- gstat::idw(RAINFALL ~ 1, shp, newdata=grd[[i]], idp=2.0)
}
#### At last the error comes as:
**[1] "+proj=longlat +datum=WGS84 +no_defs"
[1] "+proj=longlat +datum=WGS84 +no_defs"
Error in predict.gstat(g, newdata = newdata, block = block, nsim = nsim, :
var1 : data item in gstat object and newdata have different coordinate reference systems**
Even though the CRS of both objects is same.
Can someone suggest me a solution?