sampleRast {enmSdmX} | R Documentation |
Sample random points from a raster with/out replacement
Description
This function returns coordinates randomly located on a raster where cells can be sampled with replacement (if desired) and where the probability of selection is proportionate to the cell value, cell area, or the product of cell value times cell area.
Usage
sampleRast(x, n, adjArea = TRUE, replace = TRUE, prob = TRUE)
Arguments
x |
|
n |
Positive integer. Number of points to draw. |
adjArea |
If |
replace |
If |
prob |
If |
Value
2-column matrix with longitude and latitude of random points.
See Also
Examples
library(terra)
r <- rast()
nc <- ncell(r)
r[] <- 1:nc
rands1 <- sampleRast(r, 10000)
rands2 <- sampleRast(r, 10000, adjArea=FALSE)
rands3 <- sampleRast(r, 10000, prob=FALSE)
rands4 <- sampleRast(r, 10000, adjArea=FALSE, prob=FALSE)
oldPar <- par(mfrow=c(2, 2))
plot(r, main='adjArea = TRUE & prob = TRUE')
points(rands1, pch='.')
plot(r, main='adjArea = FALSE & prob = TRUE')
points(rands2, pch='.')
plot(r, main='adjArea = TRUE & prob = FALSE')
points(rands3, pch='.')
plot(r, main='adjArea = FALSE & prob = FALSE')
points(rands4, pch='.')
par(oldPar)
[Package enmSdmX version 1.1.6 Index]