jiayuasu opened a new issue, #1156:
URL: https://github.com/apache/sedona-db/issues/1156
`ST_Distance` returns a non-zero distance for two LineStrings that properly
cross, where the correct answer is `0`. `ST_Intersects` on the same pair
correctly returns `true`, so the two functions disagree about whether the
geometries meet.
## Reproduce
```sql
SELECT
ST_Distance( ST_GeomFromText('LINESTRING (0 0, 2 2)'),
ST_GeomFromText('LINESTRING (0 2, 2 0)')) AS distance,
ST_Intersects(ST_GeomFromText('LINESTRING (0 0, 2 2)'),
ST_GeomFromText('LINESTRING (0 2, 2 0)')) AS intersects,
ST_DWithin( ST_GeomFromText('LINESTRING (0 0, 2 2)'),
ST_GeomFromText('LINESTRING (0 2, 2 0)'), 0.0) AS dwithin;
```
```
distance = 1.4142135623730951
intersects = true
dwithin = false
```
The two segments cross at `(1 1)`, so the distance is `0`. PostGIS and
Shapely both return `0.0`. The value returned, `sqrt(2)`, is the gap between
the nearest pair of *endpoints*, which suggests the kernel is only considering
vertices rather than segment interiors.
`ST_DWithin` inherits the error, so a zero-distance bound fails to match a
pair that plainly touches.
## Scope
Only the LineString/LineString crossing case is affected. These are all
correct:
| case | `ST_Distance` | expected |
| --- | --- | --- |
| LineStrings crossing in an X | **1.4142** | **0.0** |
| LineStrings touching at a shared endpoint | 0.0 | 0.0 |
| Parallel LineStrings, gap 1 | 1.0 | 1.0 |
| Point vs LineString | 1.0 | 1.0 |
| Overlapping Polygons | 0.0 | 0.0 |
| LineString crossing a Polygon | 0.0 | 0.0 |
So the gap appears to be segment-segment intersection inside the line/line
distance path; the polygon paths handle it.
## Impact
Any distance or `ST_DWithin` predicate over linework can silently miss
geometries that actually intersect — road networks crossing without a shared
node being the obvious case. It is a wrong answer rather than an error, so it
is easy to miss.
Found while implementing `sjoin(predicate="dwithin")` in
`sedonadb-geopandas`, where a pair that GeoPandas matches was dropped. That
layer currently works around it by also testing `ST_Intersects`, since anything
that crosses intersects, but the underlying distance result is still wrong.
Version: `sedonadb` 0.5.0 (development build of current `main`).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]