Description Usage Arguments Value Note Author(s) References Examples
Get a subset of a object of class "SpatialPoints"
or "SpatialPointsDataFrame"
avoiding spatial clustering.
1 2 | ## S4 method for signature 'SpatialPointsDataFrame'
sample.grid(obj, cell.size, n, bbox, ...)
|
obj |
|
cell.size |
numeric; the cell size of the overlayed |
n |
integer; specifies maximum number points in each grid, |
bbox |
matrix; the bounding box of output |
... |
other optional arguments that can be passed to |
Returns a list of two objects: (1) an object of type "SpatialPoints"
or "SpatialPointsDataFrame"
that contains a subset of the obj, and (2) resulting grid.
Spatial points are overlaid with spatial grids with a specified cell size and then get a subset from each grid with a specified number at most. If one grid has less points than the specified number, all the points are taken. If one grid has more points than the specified number, only this number of points are taken by sample
. This function can be used when there are too much point observations to be handled, especially for spatially clustered observations. The total number of sampled points are determined by cell.size
and n
together. You will get fewer the sampled points when cell.size
is larger, or/and when n
is smaller. Similar sample sizes can be achieved by different combinations of cell.size
and n
.
Wei Shangguan
Shangguan, W., Hengl, T., de Jesus, J. M., Yuan, H., & Dai, Y. (2017). Mapping the global depth to bedrock for land surface modeling. Journal of Advances in Modeling Earth Systems, 9(1), 65-88. doi: 10.1002/2016MS000686
1 2 3 4 5 6 7 8 9 10 11 12 13 | library(sp)
data(edgeroi)
profs <- edgeroi[["sites"]]
coordinates(profs) <- ~ LONGDA94 + LATGDA94
proj4string(profs) <- CRS("+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs")
## sample SpatialPointsDataFrame:
prof1 <- sample.grid(profs, cell.size = c(0.02,0.02), n = 1)
l0 <- list("sp.points", profs, pch=1, col="red")
l1 <- list("sp.points", prof1$subset, pch="+", col="black", cex=1.2)
spplot(prof1$grid, scales=list(draw=TRUE),
col.regions="grey", sp.layout=list(l0, l1))
## Subsampling ratio in percent:
round(length(prof1$subset)/length(profs)*100, 1)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.