[geos-devel] [GEOS] #668: Inconsistent ST_Intersection and ST_Intersects results

GEOS geos-trac at osgeo.org
Tue Oct 8 05:13:56 PDT 2013


#668: Inconsistent ST_Intersection and ST_Intersects results
------------------------+---------------------------------------------------
 Reporter:  sdebionne   |       Owner:  geos-devel@…              
     Type:  defect      |      Status:  new                       
 Priority:  major       |   Milestone:  3.4.3                     
Component:  Default     |     Version:  3.4.2                     
 Severity:  Unassigned  |    Keywords:  ST_Intersects             
------------------------+---------------------------------------------------
 When intersecting two linestrings l1 and l2 with ST_Intersection resulting
 in an intersection point p, the expected results of ST_Intersects(l1, p)
 or ST_Intersects(l2, p) is TRUE.

 The following test cases shows that it's hardly the case.

 == First a working test case ==

 In this (very simple) case we effectively get a reasonable result; both
 segments do intersect at Point(5,5) as expected, and this point
 intersects both segments.


 {{{
 SELECT ST_AsText(p), ST_Intersects(p, l1), ST_Intersects(p, l2),
 CASE WHEN ST_Distance(p, l1) = 0.0 THEN 'dist1 is ZERO'
      WHEN ST_Distance(p, l1) <> 0.0 THEN 'dist1 is not ZERO' END,
 CASE WHEN ST_Distance(p, l2) = 0.0 THEN 'dist2 is ZERO'
      WHEN ST_Distance(p, l2) <> 0.0 THEN 'dist2 is not ZERO' END
 FROM (SELECT *, ST_Intersection(l1, l2) as p  FROM
      (SELECT ST_LineStringFromText('LINESTRING(0 10, 10.00000 0)') AS l1),
      (SELECT ST_LineStringFromText('LINESTRING(0 0, 10.00000 10)') AS
 l2));
 }}}


 == A broken test case ==

 One extreme point is shifted by a very small amount. Now the intersection
 Point(5.000002 5.000002) is reported to intersect only one segment and we
 have an unexpected distance (an incredibly small one, of course)
 separating this point and the other segment.


 {{{
 SELECT ST_AsText(p),
 ST_Intersects(p, l1), ST_Intersects(p, l2),
 CASE WHEN ST_Distance(p, l1) = 0.0 THEN 'dist1 is ZERO'
       WHEN ST_Distance(p, l1) <> 0.0 THEN 'dist1 is not ZERO' END,
 CASE WHEN ST_Distance(p, l2) = 0.0 THEN 'dist2 is ZERO'
       WHEN ST_Distance(p, l2) <> 0.0 THEN 'dist2 is not ZERO' END
 FROM (SELECT *, ST_Intersection(l1, l2) as p  FROM
      (SELECT ST_LineStringFromText('LINESTRING(0 10, 10.00001 0)') AS l1),
      (SELECT ST_LineStringFromText('LINESTRING(0 0, 10.00000 10)') AS
 l2));
 }}}


 == An other broken test case ==

 Just a further slight shift factor applied to another end-point; and
 this time we still continue to get back an intersection Point(5.000007
 4.999998), this Point doesn't overlaps at all none of the two segments due
 to some ultra-minimal distance.


 {{{
 SELECT ST_AsText(p),
 ST_Intersects(p, l1), ST_Intersects(p, l2),
 CASE WHEN ST_Distance(p, l1) = 0.0 THEN 'dist1 is ZERO'
       WHEN ST_Distance(p, l1) <> 0.0 THEN 'dist1 is not ZERO' END,
 CASE WHEN ST_Distance(p, l2) = 0.0 THEN 'dist2 is ZERO'
       WHEN ST_Distance(p, l2) <> 0.0 THEN 'dist2 is not ZERO' END
 FROM (SELECT *, ST_Intersection(l1, l2) as p  FROM
      (SELECT ST_LineStringFromText('LINESTRING(0 10, 10.00001 0)') AS l1),
      (SELECT ST_LineStringFromText('LINESTRING(0 0, 10.00002 10)') AS
 l2));
 }}}

 '''This is probably a rounding/precision issue.'''

 See this thread on spatialite users mailing list for more info :
 https://groups.google.com/forum/#!topic/spatialite-users/jlxEL6x0tZs

-- 
Ticket URL: <http://trac.osgeo.org/geos/ticket/668>
GEOS <http://geos.refractions.net/>
GEOS (Geometry Engine - Open Source) is a C++ port of the Java Topology Suite (JTS).


More information about the geos-devel mailing list