0

I was trying to follow this kriging exercise and ended up going on a 6 hour adventure in an attempt to create a grid file like meuse.grid in the link. I'm very new to R and geostats in general so I'd really appreciate any help. I managed to create a SpatialPolygonsDataFrame using a shapefile to get: this

cishape <- st_read("data/files/cishape.shp")
map <- as_Spatial(cishape)
plot(map)

I then managed to get this which seems to be closer to correct although the shape is now more off:

grd <- makegrid(poly, n=10000); colnames(grd) <-c("x", "y"); 
grd_pts <- SpatialPoints(coords=grd, proj4string = CRS(proj4string(poly))); 
grd_pts_in <- grd_pts[poly,];
gdf <- as.data.frame(coordinates(grd_pts_in));
ggplot(gdf) + geom_point(aes(x=x, y=y))

I can't seem to make this work following the kriging exercise though. When I make it to the bit where: grd <- as(grd, "SpatialPixelsDataFrame

plot(grd), I get the error: Error in .subset2(x, i, exact = exact) : subscript out of bounds. I read that it is because my spdf is actually has no data and should use SpatialPixels instead, but then I get the error Error in matrix(FALSE, ncells[2], ncells[1]) : invalid 'nrow' value (too large or NA). So then I tried SpatialPoints instead and got this chunk.

Please help, I don't know what I'm doing wrong and I feel like I'm losing my sanity.

0 Answers0