Skip to content

fix(map): trace stream layer from resolved anchors, not a guessed region - #27

Merged
prayaslashkari merged 1 commit into
mainfrom
bug/stream-layers
Aug 18, 2026
Merged

fix(map): trace stream layer from resolved anchors, not a guessed region#27
prayaslashkari merged 1 commit into
mainfrom
bug/stream-layers

Conversation

@prayaslashkari

@prayaslashkari prayaslashkari commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

What

The stream layer drew the wrong rivers.

For the question "what samples in Maine are downstream of Solid Waste Landfill facilities", the blue stream layer covered most of the eastern United States, including the whole Ohio basin. The samples and facilities layers were correct. Only the streams were wrong.

How

The cause

The step that loads stream shapes built its own list of facilities to trace from, instead of using the list the pipeline had already resolved. It then applied whichever region filter it happened to be handed.

That guess is wrong either way:

  • No region. The trace starts from every matching facility in the country, so the layer covers the USA.
  • Region taken from the sample side. It drops facilities that sit outside the region but genuinely drain into it. For the Maine landfill question, 16 of the 39 contributing landfills are in New Hampshire. So 41 percent of the traces vanished, and sample points along the Androscoggin were left with no river beneath them.

The fix

FIND_ANCHOR_IRIS runs earlier and has already worked out the correct facilities. They passed the filters on both sides of the question.

So this change binds those IRIs directly and drops the region clause. The stream layer now matches the facility layer by construction. There is no guess left to get wrong.

Verified against the live federation endpoint

Using the Maine landfill question:

Check Result
Flowlines returned 1,446
Area covered 71.30W to 67.72W, 42.97N to 46.88N (Maine plus the New Hampshire border strip)
Points near Ohio 0
Rumford coverage 249 points, previously empty
Jay coverage 203 points, previously empty
Query time 0.84s, faster than the version it replaces

The speedup is because the database no longer rebuilds the facility set.

Build passes. No new lint errors.

Caveats

  • Rivers do not stop at state lines, so a genuine trace can leave the region. Blue crossing a border is expected. Blue in a separate river basin is not.
  • If a question returns no facilities, the query sends an empty VALUES block. The endpoint accepts this and returns nothing, so the layer is simply empty.
  • This PR does not fix a separate issue found while testing. About 15 percent of the sample points in that Maine answer, 56 of 364, qualify as downstream without any water actually travelling. The data treats a river segment as being downstream of itself, so a facility and a sample sitting beside the same stretch of water count as a match. The ecomaine landfill and its own monitoring wells are one example. Those readings are real and worth keeping, but calling them downstream overstates what the data shows. Worth labelling on the map in a follow up.
  • Many of these samples are groundwater. Groundwater moves on its own path, so even a genuine downstream match along a river is not proof the river carried anything.

The GET_FLOWLINE_GEOMETRIES step re-derived its own anchor set and applied
whichever region it happened to be handed, which is a guess the other two
layers never make. Both guesses produce a visibly wrong map:

  - anchor region (previous behaviour): the downstream prebuilts and the
    editor both put the region on the *target* block, so the facility side
    came through unfiltered. The trace started from every matching facility
    in the country and the stream layer covered the USA — blue flowlines
    across the Ohio basin for a Maine question.

  - target region (first attempt at a fix): drops anchors sitting outside
    the region that genuinely drain into it. For "samples in Maine
    downstream of Solid Waste Landfills", 16 of the 39 contributing
    landfills are in New Hampshire, so 41% of the traces vanished and Maine
    sample points along the Androscoggin were left with no stream beneath
    them.

FIND_ANCHOR_IRIS has already resolved the correct anchors by this point —
they passed both the anchor-side and target-side filters — so bind those
IRIs directly and drop the region clause. The layer is now consistent with
the facility layer by construction.

Verified against the live federation endpoint for the question above:
1,446 flowlines, bbox lon -71.30..-67.72 / lat 42.97..46.88, zero vertices
west of -80, Rumford and Jay coverage restored (249 and 203 vertices, both
previously empty), 0.84s. Reusing the resolved IRIs is faster than the
re-derivation it replaces. Empty anchor sets emit `VALUES ?x { }`, which the
endpoint accepts and returns no rows for.
@railway-app

railway-app Bot commented Aug 18, 2026

Copy link
Copy Markdown

This PR was not deployed automatically as @prayaslashkari does not have access to the Railway project.

In order to get automatic PR deploys, please add @prayaslashkari to your workspace on Railway.

@prayaslashkari
prayaslashkari merged commit 254a656 into main Aug 18, 2026
@prayaslashkari
prayaslashkari deleted the bug/stream-layers branch August 27, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant