Learn R Programming

prioritizr (version 8.1.0)

category_layer: Category layer

Description

Convert a multi-layer terra::rast() object into a single-layer terra::rast() object where pixel values indicate which input layer had the greatest value.

Usage

category_layer(x)

# S3 method for Raster category_layer(x)

# S3 method for default category_layer(x)

Value

A terra::rast() object.

Arguments

x

terra::rast() object containing multiple layers.

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

See Also

The binary_stack() function performs the reverse of this function.

Examples

Run this code
# 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
if (FALSE) {
plot(y)
}

Run the code above in your browser using DataLab