selectRange,GRaster-method | R Documentation |
selectRange()
selects values from GRaster
s in a "stack" based on the values in another "selection" raster. For example, if the stack has three layers (call them A, B, and C), the "selection" raster could have values of 1, 2, or 3 in each cell. The raster that is returned will have values from A wherever the selection raster is 1, B from where it is 2, and C from where it is 3.
## S4 method for signature 'GRaster'
selectRange(x, y)
x |
A |
y |
A |
A GRaster
.
if (grassStarted()) {
# Setup
library(terra)
# Example data
madElev <- fastData("madElev")
# Convert a SpatRaster to a GRaster
elev <- fast(madElev)
# Make a stack of various versions of "elev" from which to select from:
x <- c(elev, 10 * elev, ln(elev), -1 * elev)
x
# Make a layer with random numbers between 1 and 4:
fun <- "= round(rand(0.5, 4.5))"
y <- app(elev, fun = fun)
selected <- selectRange(x, y)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.