Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contains gives the error answer, but ContainsPrep gives the correct one #1033

Open
cuteDen-ECNU opened this issue Jan 25, 2024 · 3 comments
Open

Comments

@cuteDen-ECNU
Copy link

Consider the statement:

DROP TABLE IF EXISTS t0;
CREATE TABLE t0 (id int, geom geometry, valid boolean);
INSERT INTO t0 (id, geom) VALUES (1,ST_GeomFromText('LINESTRING(1 2,1 1)',0));
INSERT INTO t0 (id, geom) VALUES (2,ST_GeomFromText('GEOMETRYCOLLECTION(POINT(2 2),POINT(1 0),LINESTRING(1 2,1 1))',0));
INSERT INTO t0 (id, geom) VALUES (3,ST_GeomFromText('POLYGON((1 0,0 4,2 2,1 0))',0));
SELECT a1.id, a2.id FROM t0 As a1 JOIN t0 As a2 ON ST_Contains(a1.geom, a2.geom);      
-- result: {1,1; 2,1; 2,2; 3,1; 3,2; 3, 3}   
SELECT  ST_Contains(a1.geom, a2.geom) FROM t0 as a1, t0 as a2 WHERE a1.id = 3 and a2.id = 2;
-- expected: true; actual: false

g3 contains g2 because POINTs of g2 lie in the boundary of g3 and LINESTRING of g2 lies in the interior of g3, which satisfied the sematics of contains:

ST_Contains(A, B) ⇔ (A ⋂ B = B) ∧ (Int(A) ⋂ Int(B) ≠ ∅)

I consider the issue different from #982 because the boundary of g3 is not ambiguous.

The predicate of ContainsPrep gives the correct answer. A simple statement reproduced in Geos:

bin/geosop -a 'POLYGON((1 0,0 4,2 2,1 0))' -b 'GEOMETRYCOLLECTION(POINT(2 2),POINT(1 0),LINESTRING(1 2,1 1))' contains
# false
bin/geosop -a 'POLYGON((1 0,0 4,2 2,1 0))' -b 'GEOMETRYCOLLECTION(POINT(2 2),POINT(1 0),LINESTRING(1 2,1 1))' containsPrep
# true

The version of Geos is the latest one:
6f70b63

@pramsey
Copy link
Member

pramsey commented Feb 8, 2024

Interesting, same result in covers/coversPrep.

@pramsey
Copy link
Member

pramsey commented Feb 12, 2024

This is a problem relatively deep in the IM calculation, so we are going to instead focus on the RelateNG work, which hopefully removes this inconsistency in future releases (and is faster).

@cuteDen-ECNU
Copy link
Author

Looking forward to the new releases! 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants