Burns stream line features onto the grid defined by a template raster.
Each stream cell receives the value of field (typically upstream
contributing area or channel width); non-stream cells are NA.
Value
A SpatRaster with the same grid as template. Stream cells carry
the value of field; all other cells are NA.
Details
Rasterization uses terra::rasterize() with touches = FALSE (only cells
whose centre falls on a stream line are burned). When multiple features
overlap a cell, the maximum value is kept.
The output CRS matches template. If streams and template have
different CRS, streams is reprojected to match.
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")
terra::plot(stream_r, main = "Upstream area (ha)")
