Fix outlet ordering + extract reusable trace#152
Merged
NewGraphEnvironment merged 4 commits intomainfrom Apr 14, 2026
Merged
Conversation
Relates to #147 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
lake_outlets CTE now orders by wscode_ltree + localcode_ltree (network topology) instead of downstream_route_measure (meaningless across BLKs). All downstream CTEs partition by waterbody_key instead of blue_line_key so cumulative distance and barrier detection work per-lake, not per-BLK. Fixes waterbody_key 329064462 (BULK) picking wrong tributary: SK spawning goes from -22.6% to +0.1% vs bcfishpass. Fixes #147 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Split .frs_connected_spawning into reusable pieces: - .frs_trace_downstream() — generic downstream trace with distance cap and gradient stop. Takes any origins SQL, returns linear_feature_ids. - .frs_connected_waterbody() — orchestrator for waterbody-connected spawning. Parameterized waterbody_poly table so the same function works for lakes (fwa_lakes_poly) or wetlands (fwa_wetlands_poly). Caller detects waterbody_type from rearing rules generically (L, W) instead of hardcoding lake detection. Relates to #147 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Owner
Author
Reservoir support needed in Phase 2bcfishpass clusters_near_rearing as (
select c.cid, bool_or(lk.waterbody_key IS NOT NULL) as wb
from clusters c
left outer join whse_basemapping.fwa_lakes_poly lk
on st_dwithin(c.geom, lk.geom, 2)
WHERE lk.area_ha >= t.rear_lake_ha_min
group by c.cid
union all
select c.cid, bool_or(res.waterbody_key IS NOT NULL) as wb
from clusters c
left outer join whse_basemapping.fwa_manmade_waterbodies_poly res
on st_dwithin(c.geom, res.geom, 2)
WHERE res.area_ha >= t.rear_lake_ha_min
group by c.cid
)The current PR accepts a single
Also: Phase 1 (downstream trace) identifies lake outlets from rearing segments. Rearing on reservoirs also needs outlets traced downstream. The |
waterbody_type L now resolves to both fwa_lakes_poly and fwa_manmade_waterbodies_poly. The FWA splits these by digitization origin (natural vs manmade), not ecology — a 200ha reservoir functions identically to a 200ha lake for fish rearing. Shared helper used by .frs_rule_to_sql (rearing classification via UNION ALL) and .frs_connected_waterbody (upstream cluster proximity via OR EXISTS). Matches bcfishpass load_habitat_linear_sk.sql behaviour. Relates to #147 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
wscode_ltree + localcode_ltree(network topology) instead ofdownstream_route_measure(meaningless across BLKs) for multi-BLK waterbodieswaterbody_keyinstead ofblue_line_keyso distance accumulates per lake trace, not per BLK.frs_trace_downstream()— reusable downstream trace with distance cap + gradient stop, takes any origins SQL.frs_connected_spawning()to.frs_connected_waterbody()— parameterizedwaterbody_polytable supports lakes and wetlandsBULK SK spawning: -22.6% → +0.1% vs bcfishpass.
Test plan
Fixes #147
Relates to NewGraphEnvironment/sred-2025-2026#16
🤖 Generated with Claude Code