libgeos / geos

Geometry Engine, Open Source
https://libgeos.org
GNU Lesser General Public License v2.1
1.1k stars 339 forks source link

ST_Relate gives incorrect result for interior-interior intersection dimension #1053

Open cuteDen-ECNU opened 2 months ago

cuteDen-ECNU commented 2 months ago

Considering the following statement:

SELECT ST_Relate(g1, g2)
  FROM (VALUES
  ('MULTILINESTRING((2 4, 10 10),(15 10,10 5,5 10))'::geometry, 
   'MULTILINESTRING((2 4, 10 10))'::geometry)
  ) AS sdb(g1, g2);

--expected{ 1F1F001F2}; actual{ 0F1F001F2}
bin/geosop -a 'MULTILINESTRING((2 4, 10 10),(15 10,10 5,5 10))' -b 'MULTILINESTRING((2 4, 10 10))' relate
# expected{ 1F1F001F2}; actual{ 0F1F001F2}

The intersection of interior-interior of g1 and g2 is LINESTRING(2 4, 10 10) whose dimension is 1. Thus the de9im code should be 1F1F001F2 instead of 0F1F001F2.

The version of Geos is the latest one: bdceea6

dr-jts commented 2 months ago

This is an example of a long-standing design issue with the current topological predicate algorithm. See also:

While https://github.com/libgeos/geos/pull/937 was a fix for some cases of this type, it was not a fully general fix.

There is a new topological predicate algorithm being worked on which solves this problem. It should be ready by mid-2024.

dr-jts commented 4 weeks ago

Actually the expected result is 1F1F00FF2 (since A contains B, the Exterior of A does not interact with the Interior of B).

This result is correctly computed by the RelateNG algorithm.