Computes Euclidean distance from non-NA cells in a raster and returns a
binary mask where distance is within the threshold. Useful for constraining
analysis to a corridor around streams (e.g., max_width parameter in VCA).
Details
Distance is computed with terra::distance() which calculates Euclidean
distance from the nearest non-NA cell. Feature cells themselves receive
distance 0 and are always included in the mask.
Examples
dem <- terra::rast(system.file("testdata/dem.tif", package = "flooded"))
streams <- sf::st_read(
system.file("testdata/streams.gpkg", package = "flooded"),
quiet = TRUE
)
stream_r <- fl_stream_rasterize(streams, dem, field = "upstream_area_ha")
corridor <- fl_mask_distance(stream_r, threshold = 1000)
terra::plot(corridor, col = c("grey90", "steelblue"), main = "Within 1 km of stream")
