Opened 8 years ago

Closed 8 years ago

#3679 closed defect (wontfix)

Invalid geometries: equal and disjoint?

Reported by: mwtoews Owned by: pramsey
Priority: medium Milestone: PostGIS 2.3.2
Component: postgis Version: 2.2.x
Keywords: Cc:

Description

It seems that GEOS and JTS think that invalid geometries are disjoint. For example, GEOS 3.5.0 from shapely:

from shapely import geos, wkt
geos.geos_version_string  # 3.5.0-CAPI-1.9.0 r4084
g = wkt.loads('LINESTRING(1 1, 1 1)')
g.is_valid  # False, Too few points in geometry component at or near point 1 1
g.relate(g)   # FFFFFFFF2
g.equals(g)   # False
g.disjoint(g) # True

And same from JTS. This is also the same behaviour of PostGIS up to version 2.1

SELECT PostGIS_Version(), PostGIS_GEOS_Version(),
    ST_Relate(g, g), ST_Equals(g, g), ST_Disjoint(g, g)
FROM (SELECT 'LINESTRING(1 1,1 1)'::geometry g) g;
-[ RECORD 1 ]--------+--------------------------------------
postgis_version      | 2.1 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
postgis_geos_version | 3.4.2-CAPI-1.8.2 r3924
st_relate            | FFFFFFFF2
st_equals            | f
st_disjoint          | t

However, since PostGIS 2.2, the invalid geometry may also be equal:

SELECT PostGIS_Version(), PostGIS_GEOS_Version(),
    ST_Relate(g, g), ST_Equals(g, g), ST_Disjoint(g, g)
FROM (SELECT 'LINESTRING(1 1,1 1)'::geometry g) g;
-[ RECORD 1 ]--------+--------------------------------------
postgis_version      | 2.2 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
postgis_geos_version | 3.5.0-CAPI-1.9.0 r4090
st_relate            | FFFFFFFF2
st_equals            | t
st_disjoint          | t

Unless this change was intentional, I'd expect invalid geometries to always be disjoint, and never equal. Disjoint and equal are opposite, so it is surprising to see this result.

Change History (2)

comment:1 by strk, 8 years ago

Results of GEOS/JTS operations on invalid geometries are undefined by design. The only results you can count on are the ones from ST_IsValid*() and ST_MakeValid()

comment:2 by robe, 8 years ago

Resolution: wontfix
Status: newclosed

Do we have plans to do anything about this. Only peculiar thing to me is the ST_Equals bit. Seems we might not be strictly relying on GEOS for that. Which is not a bad thing.

I'm marking as won't fix for now but feel free to push if you think there is something serious like a memory leak.

Note: See TracTickets for help on using tickets.