Enforce upstream->downstream orientation on aggregated flowpath geometry
Source:R/enforce_flowpath_flowdir.R
enforce_flowpath_flowdir.Rdextend_flowpaths_to_mainstem() rebuilds each aggregate flowpath line with
geos_line_merge, which does not preserve flow direction, and (unlike the
reconciled flowlines, guarded by the reconciled_flow_direction invariant)
the aggregated flowpaths layer has no orientation check, so a fraction of
flowpaths ship reversed (their geometry runs downstream->upstream). This pass
re-orients every flowpath so its OUTLET is the LAST vertex.
The true outlet is located from the reliably-oriented flowlines layer: each
flowpath's outlet sub-flowline is the member whose flowline_toid leaves the
flowpath, and its downstream (end) vertex is the flowpath outlet. A flowpath
whose START is nearer that outlet than its END is reversed and is flipped with
sf::st_reverse(). Genuinely branching multi-part geometry (no single
meaningful direction) is left untouched.