Learn R Programming

landmap (version 0.0.13)

sample.grid,SpatialPointsDataFrame-method: Sample spatial points by grids

Description

Get a subset of a object of class "SpatialPoints" or "SpatialPointsDataFrame" avoiding spatial clustering.

Usage

# S4 method for SpatialPointsDataFrame
sample.grid(obj, cell.size, n, bbox, ...)

Arguments

obj

"SpatialPoints*" object,

cell.size

numeric; the cell size of the overlayed "SpatialGridDataFrame" in the form of c(x,y),

n

integer; specifies maximum number points in each grid,

bbox

matrix; the bounding box of output "SpatialPoints" or "SpatialPointsDataFrame"; it is set the same as the obj if missing

...

other optional arguments that can be passed to over

Value

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.

References

  • 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. 10.1002/2016MS000686

Examples

Run this code
# NOT RUN {
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)
# }

Run the code above in your browser using DataLab