cuteDen-ECNU / bugs-record

1 stars 0 forks source link

ST_Covers give incorrect answer after mutating POLYGON to MULTIPOLYGON. #41

Open cuteDen-ECNU opened 9 months ago

cuteDen-ECNU commented 9 months ago

Considering the following statement:

SELECT ST_Covers(g2, g1), ST_Covers(g3, g1) FROM
(SELECT 
ST_GeomFromText('GEOMETRYCOLLECTION ( LINESTRING (1 2, 1 1), POINT (0 0))') As g1
, ST_GeomFromText(' MULTIPOLYGON (((0 0, 3 0, 3 3, 0 3, 0 0)))  ') As g2
, ST_GeomFromText(' POLYGON ((0 0, 3 0, 3 3, 0 3, 0 0))  ') As g3
);
-- expected: {true, true}; actual: {false, true}

The 2nd geometry covers the 1st one, because each point in the 1st geometry lies inside the 2nd one, according to the definition of ST_Covers:

ST_Covers(A, B) ⇔ A ⋂ B = B

However, PostGIS doesn't consider the ST_Covers relation, which seems to be a bug. After normalizing MULTIPOLYGON to POLYGON as g3, ST_Covers(g3, g1) gives the correct answer.

Here is a simple reproduction for libgeos:

bin/geosop -a 'GEOMETRYCOLLECTION ( LINESTRING (1 2, 1 1), POINT (0 0))' -b 'MULTIPOLYGON (((0 0, 3 0, 3 3, 0 3, 0 0)))' covers
# false

geos version is the latest one in GitHub: 6f70b63a0d976ce31dd2952094bc1a39209f8a20

cuteDen-ECNU commented 9 months ago

bugtracker link: https://github.com/libgeos/geos/issues/1027