Opened 5 months ago

Closed 5 months ago

Last modified 5 months ago

#5634 closed defect (fixed)

ST_Contains missed one of the pairs

Reported by: Wenjing Owned by: pramsey
Priority: medium Milestone: PostGIS GEOS
Component: postgis Version: 3.4.x
Keywords: Cc:

Description

Consider the following statements:

DROP table t;
CREATE table t (id int, geom geometry);
INSERT INTO t (id, geom) VALUES (1,ST_GeomFromText('GEOMETRYCOLLECTION(MULTIPOINT((-60 -50),(-63 -49)))'));
INSERT INTO t (id, geom) VALUES (2,ST_GeomFromText('GEOMETRYCOLLECTION(MULTIPOINT((-60 -50),(-63 -49)))'));
INSERT INTO t (id, geom) VALUES (3,ST_GeomFromText('MULTIPOLYGON(((-60 -50,-70 -50,-60 -40,-60 -50)))'));
SELECT a1.id, a2.id FROM t As a1, t As a2 WHERE ST_Contains(a1.geom, a2.geom) and a1.id <> a2.id;
-- actual{1,2; 2,1; 3,1 }
-- expected{1,2; 2,1; 3,1; 3,2 }

It is noticed that the first geometry and the second geometry are equal, which means if the third geometry contains the first one, the third one contains the second as well.

However, when querying the Contains pairs, besides reporting that the first and second geometries contain each other (1,2; 2,1), PostGIS just answers that the third geometry contains the first geometry (3,1), instead of both the first and the second geometries (3,1;3,2), which seems a bug.

The version is the newest on [GitHub](https://trac.osgeo.org/postgis/wiki/GitHub):

POSTGIS="3.5.0dev 3.4.0rc1-818-g6c2e935b6" [EXTENSION] PGSQL="170" GEOS="3.13.0dev-CAPI-1.18.0" PROJ="8.2.1
NETWORK_ENABLED=OFF URL_ENDPOINT=https://cdn.proj.org/ USER_WRITABLE_DIRECTORY=/tmp/proj DATABASE_PATH=/usr/
share/proj/proj.db" LIBXML="2.9.13"

Change History (4)

comment:1 by pramsey, 5 months ago

This is probably a mistake in GEOS PreparedContains, since the PostGIS caching system is doing the first test with Contains and the second (cached) with PreparedContains

comment:2 by pramsey, 5 months ago

Confirmed, it is replicable in GEOS.

https://github.com/libgeos/geos/issues/1007

comment:3 by mdavis, 5 months ago

Resolution: fixed
Status: newclosed

Fixed with GEOS 3.13, 3.12.2, 3.11.4, 3.10.7

See https://github.com/libgeos/geos/pull/1008

comment:4 by robe, 5 months ago

Milestone: PostGIS 3.4.2PostGIS GEOS
Note: See TracTickets for help on using tickets.