sampleRast | R Documentation |
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.
sampleRast(x, n, adjArea = TRUE, replace = TRUE, prob = TRUE)
x |
|
n |
Positive integer. Number of points to draw. |
adjArea |
If |
replace |
If |
prob |
If |
2-column matrix with longitude and latitude of random points.
spatSample
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.