Take a regular sample of a SpatRaster. Either get cell values, or a new SpatRaster with the same extent, but fewer cells.
# S4 method for SpatRaster
spatSample(x, size, method="regular", replace=FALSE, as.raster=FALSE, ...)
SpatRaster
numeric. The sample size
character. Should be "regular" or "random"
logical. If TRUE
, sampling is with replacement (if method="random"
logical. If TRUE
and method="regular"
, a SpatRaster is returned
additional arguments. None implemented
numeric or SpatRaster
# NOT RUN {
f <- system.file("exdata/test.tif", package="terra")
r <- rast(f)
s <- spatSample(r, 10, as.raster=TRUE)
spatSample(r, 10)
spatSample(r, 10, "random")
# }
Run the code above in your browser using DataLab