Fix within-distance check between a point and a linestring - #11
Merged
Conversation
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.
There was a problem hiding this comment.
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
minDistfor point–XSortedLineusing an effectively unboundeddistFunc(..., numeric_limits<double>::max())for endpoint probes. - Keep search/sweep behavior stable by continuing to clamp the distance passed into
paddingFunctomin(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
added a commit
to ad-freiburg/spatialjoin
that referenced
this pull request
Aug 14, 2026
…st case fixed in util with ad-freiburg/util#11
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.
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.
So far, the
within-distancecheck 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 inspatialjoincompares 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, awithin-distancejoin 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.