Skip to contents

Convert a terra::rast() object containing integer/categorical values into a raster object where each layer corresponds to a different integer/categorical value and pixel values denote the presence/absence of the given integer/categorical values.

Usage

binary_stack(x)

# S3 method for Raster
binary_stack(x)

# S3 method for SpatRaster
binary_stack(x)

Arguments

x

terra::rast() object with a single layer.

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().

See also

Examples

# create raster with categorical values
x <- terra::rast(matrix(c(1, 2, 3, 1, NA, 1), nrow = 3))

# plot the raster
plot(x, main = "x")


# convert to binary stack
y <- binary_stack(x)

# plot result
# \dontrun{
plot(y)

# }