Validates and prepares one drawn or terrain-derived Flowline. By default, DEM endpoint elevations orient it downstream-to-upstream. An explicit topology-preserving mode retains direction already established by a routed Stream Network.

flowline(flowline, reach_name, dem, direction = c("dem", "preserve"))

Arguments

flowline

sf object; One flowline with a defined CRS.

reach_name

character; The name of the stream reach.

dem

terra SpatRaster object; A DEM in the Flowline CRS. In "dem" mode it supplies endpoint-elevation direction evidence; in "preserve" mode it remains part of the shared preparation contract.

direction

Character; "dem" retains the historical endpoint-elevation orientation. "preserve" keeps an upstream-directed line whose direction has already been established by saved network topology.

Value

One sf Flowline with only ReachName and geometry fields. Its coordinates begin downstream and end upstream when the selected direction method supplies or preserves that evidence.

Details

Uses orient_lines_from_dem() for endpoint-based upstream orientation by default. direction = "preserve" is intended for linework whose downstream-to-upstream direction is already established by topology; it retains that direction while applying the same CRS, cardinality and output field contract. Browser-drawn WGS84/Web Mercator input retains the historical GeoJSON CRS repair. Other explicitly defined projected CRSs pass through unchanged. If direction cannot be resolved, returns unchanged linework with a warning.