You are confusing terms and thus, confusing us. The expected input for kriging prediction in the gstat
krige function is a systematic array of points and not polygons. It would also be nice if you provided a reproducible code example of what you have tried.
You can use the extent of an sp object to create an array of points for the kriging prediction using the
rasterToPoints functions in the raster package.
First, we add our libraries and example data (meuse SpatialPointsDataFrame data from sp library).
coordinates(meuse) <- ~x + y
proj4string(meuse) <- CRS("+init=epsg:28992")
Here we create an extent polygon using a bounding extent of any relevant sp or raster class object. You can then use this extent polygon to create a dummy raster object that is coerced into a SpatialPoints object using
rasterToPoints. The resulting sp SpatialPoints object can act as the kriging prediction grid.
ext <- as(extent(meuse), "SpatialPolygons")
r <- rasterToPoints(raster(ext, resolution = 30), spatial = TRUE)
proj4string(r) <- proj4string(meuse)
Now we can specify a kriging model using our point (meuse) and prediction grid (r) objects.
# krige model log(copper):
v1 <- variogram(log(copper) ~ 1, meuse)
x1 <- fit.variogram(v1, vgm(1, "Sph", 800, 1))
G1 <- krige(copper ~ 1, meuse, r, x1, nmax = 30)
gridded(G1) <- TRUE
G1@data = as.data.frame(G1@data[,-2])
For some reason the
raster function was not always honoring the crs argument. I fixed it by assigning the projection, using
proj4string, after the points were created.