Skip to contents

This function calculates the representation of each feature across raster cells, and can optionally summarize results within a specified area.

Usage

feature_representation(feature_layers, area_mask = NULL)

Arguments

feature_layers

A terra::SpatRaster with one or more layers representing feature distributions (e.g., species distributions, habitat suitability).

area_mask

Optional. A terra::SpatRaster or terra::SpatVector defining the analysis area. If a raster is provided, it should follow the Zonation analysis area mask convention, where cells with value 1 represent the area of interest and cells with value 0 or NA are excluded. If a SpatVector is provided, it will be rasterized to match the resolution and extent of feature_layers.

Value

A list with two elements:

representation_layers

A terra::SpatRaster where each layer contains the fractional representation of the corresponding feature across the landscape. Each cell value represents the proportion of the global total representation of that feature occurring in that cell.

representation_in_area

A named numeric vector containing the representation of each feature within the specified area_mask. If no area is provided, this element returns NULL.

Examples

r <- terra::rast(nrows = 10, ncols = 10)
f1 <- terra::setValues(r, runif(terra::ncell(r)))
f2 <- terra::setValues(r, runif(terra::ncell(r)))
features <- c(f1, f2)
names(features) <- c("feature_1", "feature_2")

mask <- r
terra::values(mask) <- sample(c(0,1), terra::ncell(mask), replace = TRUE)

result <- feature_representation(features, mask)
result$representation_in_area
#> feature_1 feature_2 
#> 0.4622109 0.4387114