binary_stack | R Documentation |
Convert a single-layer terra::rast()
object that contains integer values
into a multi-layer terra::rast()
object with pixel values denote the
presence/absence of a given integer value. This is methodology is also known
as "one-hot encoding".
binary_stack(x, keep_all = TRUE)
## S3 method for class 'Raster'
binary_stack(x, keep_all = TRUE)
## S3 method for class 'SpatRaster'
binary_stack(x, keep_all = TRUE)
x |
|
keep_all |
|
This function is provided to help manage data that encompass
multiple management zones. For instance, this function may be helpful
for preparing raster data for add_locked_in_constraints()
and
add_locked_out_constraints()
since they require binary
rasters as input arguments.
It is essentially a wrapper for terra::segregate()
.
Note that this function assumes x
contains integer values.
A terra::rast()
object.
category_layer()
, terra::segregate()
.
# create raster with categorical values
x <- terra::rast(matrix(c(1, 2, 4, 0, NA, 1), nrow = 3))
# plot the raster
## Not run:
plot(x, main = "x")
## End(Not run)
# convert to binary stack
y <- binary_stack(x)
# plot result
## Not run:
plot(y)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.