Skip to content

bbox: don't load the geometry of ways whose index lies inside the bbox - #22

Open
cldellow wants to merge 1 commit into
fossgis:masterfrom
cldellow:bbox-ways-inside
Open

cldellow wants to merge 1 commit into
fossgis:masterfrom
cldellow:bbox-ways-inside

Conversation

@cldellow

Copy link
Copy Markdown

Constraints have the concept of cheap and expensive filters.

Bbox_Filter's cheap filter currently removes things that can be excluded by the filter without needing to analyze their geometry.

For ways, this includes ways whose tile index lies entirely outside of the bbox, like D in this Claude-generated image:

image

The expensive filter then runs to exactly test all the other ways.

This PR speeds up bbox filters by skipping exact geometry tests for ways that are provably inside the bbox by virtue of their tile index, as A and B are.

Then, only ways whose tile index spans the bbox's boundary need to be analyzed in the expensive filter for their exact geometry.

On a Nova Scotia extract:

  [out:csv(::count)]; way[highway](44.60,-63.66,44.70,-63.52); out count;
      112 ms -> 74 ms (-34%)

  [out:json]; way[highway](44.60,-63.66,44.70,-63.52); out geom;
      396 ms -> 333 ms (-16%)

Bboxes that cross the antimeridian or which are 180 or more degrees wide are explicitly excluded from the fast path, since the expensive filter has special handling for them.

This can likely be extended to relations, but that will be a separate PR.

Caveat/question for reviewers: this PR changes the behaviour for some ways that have a missing node. Previously, the expensive filter would call make_geometry for short ways, which returns an empty geometry if a way has a missing node. Thus, that way would be excluded by the bbox filter, even if one of its nodes did fall within the bbox. This PR will now include ways with missing nodes if their tile index falls entirely within the bbox. This is a change in behaviour, so I'm flagging it, but IMO, it's a good change in behaviour, and it's unlikely to be hit by most people if their databases are built from the planet or from well-formed extracts that maintain way integrity.

To test ways against a bbox, Bbox_Filter loads the nodes of every
candidate way and checks its segments. It uses a fast path to exclude
ways that must lie outside of the bbox by virtue of their enclosing
tile. Extend the fast path to ways that must lie inside the bbox by
virtue of their enclosing tile.

On a Nova Scotia extract:

  [out:csv(::count)]; way[highway](44.60,-63.66,44.70,-63.52); out count;
      112 ms -> 74 ms (-34%)
  [out:json]; way[highway](44.60,-63.66,44.70,-63.52); out geom;
      396 ms -> 333 ms (-16%)

Co-Authored-By: Colin Dellow <cldellow@gmail.com>
@cldellow

Copy link
Copy Markdown
Author

The CI tests failed due to a flaky race condition in the dispatcher 22 test. I re-ran them, and will submit a separate PR that resolves the race.

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.

2 participants