Add river-constrained D8 flow direction - #1
Draft
kongdd wants to merge 28 commits into
Draft
Conversation
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. Thanks for integrating Codecov - We've got you covered ☂️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Build hydrologically consistent D8/LDD flow direction from a coarse DEM while enforcing trusted high-resolution river centerlines.
The design deliberately separates the information sources:
Full pipeline
hydro_enforced_flowdirperforms:junction_radius);The low-memory validator avoids constructing a full Graphs.jl adjacency graph just to validate large 30 m routing rasters.
RiverGraphremains available for downstream network analysis and detailed QC.GIS vector input
ArchGDAL is now an optional Julia package extension rather than a hard dependency. It reads LineString and MultiLineString layers directly from any GDAL-supported vector source; MultiLineString parts are flattened to independent river lines. No implicit reprojection is performed.
If the source river lines are not reliably digitized upstream -> downstream, use
direction=:dem. If vector topology is already clean, keepjunction_radius=0; one-cell snapping is intentionally conservative and should only repair rasterization gaps.Priority-Flood behavior
Priority-Flood can use all trusted river cells as drainage seeds. It uses a small constant vertical epsilon per 8-neighbour step to remove flats while preserving monotone heap ordering. The implementation uses separate
Float64priority and linear-Intindex heaps, avoiding aDataStructures.jldependency.boundary_outlets=true: for a regional rectangular DEM where drainage may legitimately leave the raster boundary.boundary_outlets=false: for a clipped basin/domain that should drain only to the supplied river network; disconnected valid DEM components become explicit errors instead of silent pits.Quality control
flowdir_qcreports channel-edge agreement and classifies final sinks into trusted river sinks, active-domain boundary sinks, and interior non-river sinks. A typical accepted result should have:river_match == 1.0;interior_nonriver_sinks == 0;Main API
hydro_enforced_flowdirread_river_lines(ArchGDAL extension)priority_flood_demcondition_river_demriver_constrained_flowdird8_flowdirrasterize_flowpath/rasterize_flowpathsorient_flowpathsnap_flowpath_junctionsforce_flowpaths!validate_flowdirflowdir_qcldd_codeTests
Tests cover D8 coding, vector -> 8-connected raster paths, DEM-based orientation, confluence snapping, divergence rejection, monotonic channel conditioning, tributary confluences, river-seeded Priority-Flood, full hydro enforcement, ArchGDAL LineString/MultiLineString ingestion, direct vector-file routing, low-memory cycle validation, and QC metrics.
Remaining before merge
This PR remains draft until real-data validation and large-raster benchmarking are done.