Skip to contents

Removes (sets to 0) cells in a binary raster that overlap with any exclusion mask. Useful for trimming floodplain by urban areas, steep terrain, waterbodies, or other features.

Usage

fl_flood_trim(x, ...)

Arguments

x

A SpatRaster with binary values (0/1).

...

One or more SpatRaster exclusion masks. Cells with value 1 in any mask are removed from x.

Value

A SpatRaster with the same grid as x. Cells overlapping any exclusion mask are set to 0.

Examples

slope <- terra::rast(system.file("testdata/slope.tif", package = "flooded"))
gentle <- fl_mask(slope, threshold = 9, operator = "<=")

# Trim: remove cells on slopes > 5% (a stricter exclusion mask)
steep <- fl_mask(slope, threshold = 5, operator = ">")
trimmed <- fl_flood_trim(gentle, steep)
terra::plot(trimmed, col = c("grey90", "darkgreen"), main = "Trimmed by steep slopes")