Transfers ordered Reach transitions from the retained Stream reference to a terrain-derived Flowline, then prepares one continuous Flowline per Reach.

derive_reach_flowlines(
  raw_flowline,
  smoothed_flowline,
  reference_lines,
  reach_mappings,
  reaches,
  dem,
  connectivity_tolerance = 0.01
)

Arguments

raw_flowline

One projected, downstream-to-upstream sf LINESTRING selected from the synthetic Stream Network.

smoothed_flowline

A smoothed version of raw_flowline with the same fixed endpoints.

reference_lines

Ordered downstream-to-upstream retained Stream reference lines with a unique selection_id field.

reach_mappings

Data frame linking every retained selection_id to one saved reach_id.

reaches

Saved Reach features or data frame with unique reach_id and reach_name fields.

dem

A terra::SpatRaster in the Flowline CRS. It is supplied to flowline() for contract compatibility; saved topology remains the direction authority.

connectivity_tolerance

Maximum permitted gap between consecutive reference lines, in reference CRS map units. Defaults to 0.01.

Value

A list containing flowlines (one downstream-to-upstream feature per Reach with legacy ReachName, from_measure, and to_measure fields; measures are continuous kilometres from the selected Stream outlet), boundaries (transferred Reach boundary points and projection evidence), and reach_order.

Details

Each Reach must occupy one contiguous block in the ordered retained Stream reference. Every reference line must be assigned exactly once. Reach boundaries are the shared or near-coincident endpoints between consecutive reference blocks. They are projected first to the raw terrain path, then to the smoothed path. Reversed, duplicated, gapped or collapsed transitions fail closed. Reach polygon edges are not used.