Repository navigation
Conversation
The nearest point was picked in flat lon/lat degrees, which is wrong away from the equator and across the antimeridian. Edges between vertices are now taken as great-circle arcs.
Great-circle arcs disagreed with the containment check, the index and spatial.intersects, which all use straight lon/lat edges. The distance is now the great-circle distance to the nearest point of the straight edge, pruning edges that cannot be closer than the best match. An empty geometry is infinitely far away.
This was referenced Nov 18, 2026
This branch has not been deployed
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.
spatial.withinDistanceandspatial.closestpicked the nearest point of a line or polygon in flat lon/lat degrees, then measured the great-circle distance to it. Away from the equator that point is wrong: from (0, 60) toLINESTRING (1 60, 0 62)it measured 62.7 km instead of 53.85 km, so geometries near the limit were dropped. Across ±180° it measured to the far end of the geometry.Edges stay straight lines in lon/lat, as in the index and
spatial.intersects. The distance is now the great-circle distance to the nearest point on them. Points inside a polygon still give 0.The math costs more than the flat-degree shortcut. For one geometry, measured: about 10 µs at 100 vertices and about 0.8 ms at 10 000, compared with 1 µs and 0.07 ms before. Parsing the same 10 000-vertex polygon from WKT takes 5 ms.
Out of scope
LINESTRING (15 60, 16 61)drops from 6.21 to 4.96 km.