Learn R Programming

GSIF (version 0.5-3)

sample.grid: sample spatial points by grids

Description

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

Usage

"sample.grid"(obj, cell.size, n, bbox, ...) "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.

Examples

Run this code
library(sp)
data(isis)
profs <- isis[["sites"]]
coordinates(profs) <- ~  LONWGS84 + LATWGS84
proj4string(profs) <- CRS("+proj=longlat +datum=WGS84")
## sample SpatialPointsDataFrame: 
#bbox <- matrix(c(-180, -90, 180, 90), nrow=2)
prof1 <- sample.grid(profs, cell.size = c(5,5), 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:
round(length(prof1$subset)/length(profs)*100, 1)

Run the code above in your browser using DataLab