sampleRast | R Documentation |
This function returns coordinates randomly located on a raster where cells can be sampled more than once if desired (sampled with replacement) and where the probability of selection is proportionate to the cell value (plus maybe cell area–both if desired).
sampleRast(x, n, adjArea = TRUE, replace = TRUE, prob = TRUE)
x |
|
n |
Positive integer. Number of points to draw. |
adjArea |
Logical. If |
replace |
Logical. If |
prob |
Logical. If |
2-column matrix with longitude and latitude of random points. Points will be located at cell centers.
randomPoints
, sampleRastStrat
library(raster) r <- raster() 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) 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='.')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.