[PostGIS] #5838: Possible bug in ST_Intersects
PostGIS
trac at osgeo.org
Fri Jan 17 02:31:31 PST 2025
#5838: Possible bug in ST_Intersects
---------------------+---------------------------
Reporter: rouen | Owner: pramsey
Type: defect | Status: new
Priority: medium | Milestone: PostGIS 3.5.2
Component: postgis | Version: 3.5.x
Keywords: |
---------------------+---------------------------
{{{POSTGIS="3.5.1 48ab069" [EXTENSION] PGSQL="160" GEOS="3.8.0-CAPI-1.13.1
" PROJ="6.3.1" LIBXML="2.9.10" LIBJSON="0.13.1" LIBPROTOBUF="1.3.3"
WAGYU="0.5.0 (Internal)"}}}
Let's have 2 lines in chain (endpoint of one is startpoint of the other)
and 3rd line intersecting (one of) them very close to that point.
ST_Intersects behaves badly in this case:
{{{
WITH data AS
(
SELECT 'a' AS id, st_geomfromtext('LINESTRING(20.3580062
48.3096067,20.3579669 48.3096863)',4326) AS geom
UNION
SELECT 'b' AS id, st_geomfromtext('LINESTRING(20.3579669
48.3096863,20.3579264 48.3097684)',4326) AS geom
UNION
SELECT 'c' AS id, st_geomfromtext('LINESTRING(20.3580084
48.3097278,20.3579583 48.3096777)',4326) AS geom
)
SELECT
st_intersects(a.geom,b.geom) AS ab_intersects, -- true
st_intersects(a.geom,c.geom) AS ac_intersects, -- false
st_intersects(b.geom,c.geom) AS bc_intersects -- false
FROM data a, data b, data c
WHERE a.id = 'a' and b.id = 'b' and c.id = 'c';
}}}
This alone is wrong (c is clearly crossing the chain of a+b).
But interestingly enough, with JOIN it gives different results (c does
intersects a):
{{{
WITH data AS
(
SELECT 'a' AS id, st_geomfromtext('LINESTRING(20.3580062
48.3096067,20.3579669 48.3096863)',4326) AS geom
UNION
SELECT 'b' AS id, st_geomfromtext('LINESTRING(20.3579669
48.3096863,20.3579264 48.3097684)',4326) AS geom
UNION
SELECT 'c' AS id, st_geomfromtext('LINESTRING(20.3580084
48.3097278,20.3579583 48.3096777)',4326) AS geom
)
SELECT c.id, x.id -- 3 + 1
FROM data c
JOIN data x ON st_intersects(c.geom,x.geom)
WHERE c.id='c' and x.id<>'c'
}}}
--
Ticket URL: <https://trac.osgeo.org/postgis/ticket/5838>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.
More information about the postgis-tickets
mailing list