Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

gridSample

Stratified regular sample on a grid


Description

Sample points from xy, using a grid (raster) as stratification. Up to n points are sampled from each stratum (cell). For "chessboard" sampling (i.e. sampling from half the cells), use the argument chess='black', or chess='white'.

Usage

gridSample(xy, r, n=1, chess='')

Arguments

xy

A two column matrix or data.frame with x and y coordinates (or longitude and latitude), or a SpatialPoints* object

r

Raster* object

n

Maximum number of samples per cell

chess

Character. ”, 'black', or 'white'. If 'black' or 'white', "chess-board" sampling is used. I.e. only the 'white' fields, or only the 'black' fields are sampled. Cell number 1 (the upper left corner of r) is white.

Value

A two column matrix with x and y coordinates (or longitude and latitude)

Author(s)

Robert J. Hijmans

See Also

Examples

x <- rnorm(1000, 10, 5)
y <- rnorm(1000, 50, 5)
xy <- cbind(x,y)
res <- 5
r <- raster(extent(range(xy[,1]), range(xy[,2])) + res)
res(r) <- res

samp <- gridSample(xy, r, n=1)
plot(xy, cex=0.1)
points(samp, pch='x', col='red')

dismo

Species Distribution Modeling

v1.3-3
GPL (>= 3)
Authors
Robert J. Hijmans, Steven Phillips, John Leathwick and Jane Elith
Initial release
2020-11-16

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.