Skip to contents

Convert a terra::rast() object where each layer corresponds to a different identifier and values indicate the presence/absence of that category into a terra::rast() object containing categorical identifiers.

Usage

category_layer(x)

# S3 method for Raster
category_layer(x)

# S3 method for default
category_layer(x)

Arguments

x

terra::rast() object containing multiple layers. Note that pixels must be 0, 1 or NA values.

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 interpreting solutions for problems associated with multiple zones that have binary decisions. It is essentially a wrapper for terra::which.lyr().

See also

Examples

# create a binary raster stack
x <- terra::rast(list(
 terra::rast(matrix(c(1, 0, 0, 1, NA, 0), nrow = 3)),
 terra::rast(matrix(c(0, 1, 0, 0, NA, 0), nrow = 3)),
 terra::rast(matrix(c(0, 0, 1, 0, NA, 1), nrow = 3))
))

# plot data
plot(x)


# convert to category layer
y <- category_layer(x)

# plot result
# \dontrun{
plot(y)

# }