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".
Usage
binary_stack(x, keep_all = TRUE)
# S3 method for Raster
binary_stack(x, keep_all = TRUE)
# S3 method for SpatRaster
binary_stack(x, keep_all = TRUE)
Arguments
- x
terra::rast()
object with a single layer that contains integer values.- keep_all
logical
value indicating if all integers should be kept in the output. IfTRUE
, the output will contain a layer for each sequential integer between 1 and the maximum value inx
. IfFALSE
, the output will only contain layers for integer values present inx
. Defaults toTRUE.
Value
A terra::rast()
object.
Details
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.