Skip to content

Fix within-distance check between a point and a linestring - #11

Merged
patrickbr merged 2 commits into
masterfrom
fix-withindist-sentinel
Aug 14, 2026
Merged

Fix within-distance check between a point and a linestring#11
patrickbr merged 2 commits into
masterfrom
fix-withindist-sentinel

Conversation

@hannahbast

Copy link
Copy Markdown
Member

So far, the within-distance check between a point and a linestring initialized its running minimum with the distance from the point to the two endpoints of the line, clamped to the given maximum distance. When no segment of the line was within the maximum distance, this clamped value was also returned. The caller in spatialjoin compares the result inclusively against the threshold, so every candidate pair from the sweep was reported as a match, with a reported distance exactly equal to the threshold. As a consequence, a within-distance join between points and a linestring returned every point in the padded bounding box of the linestring.

For example, a query for all OSM points within 100 m of the Route d'Arlon (N 6) in Luxembourg returned 124,532 points, of which only 18,389 are actually within 100 m.

The endpoints are now probed with an unbounded distance function, exactly as the corresponding check between a point and a polygon ring already does. The returned value is then an honest distance. The clamp to the maximum distance is kept in the two arguments to the padding function, so the search behavior is unchanged. Only the point-linestring case is affected. The ring, simple-segment, line-line and collection variants already behave correctly when nothing is within range.

So far, the `within-distance` check between a point and a linestring
initialized its running minimum with the distance from the point to the
two endpoints of the line, clamped to the given maximum distance. When
no segment of the line was within the maximum distance, this clamped
value was also returned. The caller in `spatialjoin` compares the result
inclusively against the threshold, so every candidate pair from the
sweep was reported as a match, with a reported distance exactly equal to
the threshold. As a consequence, a `within-distance` join between points
and a linestring returned every point in the padded bounding box of the
linestring.

For example, a query for all OSM points within 100 m of the
Route d'Arlon (N 6) in Luxembourg returned 124,532 points, of which only
18,389 are actually within 100 m.

The endpoints are now probed with an unbounded distance function,
exactly as the corresponding check between a point and a polygon ring
already does. The returned value is then an honest distance. The clamp
to the maximum distance is kept in the two arguments to the padding
function, so the search behavior is unchanged. Only the point-linestring
case is affected. The ring, simple-segment, line-line and collection
variants already behave correctly when nothing is within range.
Copilot AI lite review requested due to automatic review settings August 14, 2026 14:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes incorrect within-distance behavior for point–linestring checks by ensuring the running minimum distance is initialized with unbounded endpoint distances, preventing “always equals threshold” results when no segment is actually within range.

Changes:

  • Initialize minDist for point–XSortedLine using an effectively unbounded distFunc(..., numeric_limits<double>::max()) for endpoint probes.
  • Keep search/sweep behavior stable by continuing to clamp the distance passed into paddingFunc to min(maxDist, minDist) (both initially and when updating padding).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@patrickbr
patrickbr merged commit 85c5631 into master Aug 14, 2026
4 checks passed
@patrickbr
patrickbr deleted the fix-withindist-sentinel branch August 14, 2026 20:55
patrickbr added a commit to ad-freiburg/spatialjoin that referenced this pull request Aug 14, 2026
hannahbast added a commit to ad-freiburg/qlever that referenced this pull request Aug 17, 2026
…ults (#3246)

This change updates the pinned `libspatialjoin` to the current master. The update fixes three bugs in `within-distance` joins. The check between a point and a linestring reported every candidate from the padded bounding box as within distance, which returned all points in a large parallelogram around the linestring (fixed in ad-freiburg/util#11). The distance between a linestring and a polygon was too large by the Web-Mercator distortion factor (ad-freiburg/util#12). An integer overflow in `distToSegment` silently lost result pairs (ad-freiburg/util#13). The update also fixes duplicate and contradictory DE-9IM results for byte-identical geometries (ad-freiburg/spatialjoin#23).

Some hardcoded distances in the tests change slightly because point-point distances are now computed with an exact haversine formula on Web-Mercator coordinates.
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.

3 participants