r - How to cut/crop/mask autoKrige result with boundary polygon? -
i busy developing module implements autokrige (automap library) on soil sample data 20x20m cell-size. once kriging complete crop/mask kriging result field's boundary.
the problem cropping/masking (because of 20x20 cells) border of field gives "step" effect. looking smooth boundary (cutting through cells).
below code generate 2 scenarios explained above:
library(sp) library(rgeos) #create polygon r1 <- cbind(c(641777, 642290, 642276, 641794), c(7036885, 7036743, 7036154, 7036146)) r2 <- cbind(c(642320, 642478, 642494, 642314), c(7036732, 7036699, 7036296, 7036290)) sr1 <- polygons(list(polygon(r1)),"r1") sr2 <- polygons(list(polygon(r2)),"r2") boundary.sp <- spatialpolygons(list(sr1,sr2)) boundary.sp@proj4string <- crs('+proj=utm +zone=35 +south +datum=wgs84 +units=m +no_defs') #create bounding box grid bbox <- bbox(boundary.sp) boundary.grid <- expand.grid(x = seq(from = bbox[1], = bbox[3], = 20), y = seq(from = bbox[2], = bbox[4], = 20)) coordinates(boundary.grid) <- ~x + y gridded(boundary.grid) <- true boundary.grid@proj4string <- boundary.sp@proj4string #create spatialpixels grid boundary.grid.stepped <- boundary.grid[!is.na(over(boundary.grid, boundary.sp)),] plot(boundary.grid.stepped) #cut grid polygon create spatialpolygons grid boundary.poly.grid <- as.spatialpolygons.gridtopology(getgridtopology(boundary.grid), proj4string = crs('+proj=utm +zone=35 +south +datum=wgs84 +units=m +no_defs')) boundary.grid.smooth <- gintersection(boundary.poly.grid, boundary.sp, byid=true) plot(boundary.grid.smooth)
currently above grid (boundary.grid.stepped) passed 'new_data' parameter when calling autokrige.
which better approach , how go implementing it:
1) prepare target grid beforehand , use 'new_data' or,
2) kriging onto bounding box grid , cut/crop/mask afterwards?
i'd gridding directly on target grid, via feeding new_data
. kriging result depends on input data, suspect there little difference between cropping/calculating , calculating/cropping.
Comments
Post a Comment