[postgis-tickets] [PostGIS] #5426: ST_Difference produces wrong results for lines which are vertically / horizontally straight and completely contained in other input geometry

PostGIS trac at osgeo.org
Mon Jul 3 06:39:12 PDT 2023


#5426: ST_Difference produces wrong results for lines which are vertically /
horizontally straight and completely contained in other input geometry
---------------------------+---------------------
 Reporter:  22141992       |      Owner:  pramsey
     Type:  defect         |     Status:  new
 Priority:  medium         |  Milestone:
Component:  postgis        |    Version:  3.2.x
 Keywords:  ST_Difference  |
---------------------------+---------------------
 ST_Difference is not working correctly in cases when one of the input
 geometries of ST_Difference is
 - vertically / horizontally straight line
 AND
 - completely contained in other input geometry.

 The bug has been detected when trying to determine difference between line
 geometry and polygon geometry, but it is likely that similar behaviour
 appears when comparing vertically / horizontally straight line geometry
 with another line geometry completely containing the first line).

 It states in ST_Difference's documentation:
 "Returns a geometry representing the part of geometry A that does not
 intersect geometry B. This is equivalent to A - ST_Intersection(A,B). If A
 is completely contained in B then an empty atomic geometry of appropriate
 type is returned."

 With that in mind, the second and third example below should return
 LINESTRING EMPTY (since the whole example line is completely contained in
 our example polygon, there should be no difference between them).

 {{{
 -- Polygon completely containing not vertially nor horizontally straight
 line
 SELECT ST_AsText(ST_Difference('LINESTRING (5 7, 6 11)'::geometry,
 'POLYGON ((0 0, 1000 0, 1000 1000, 0 1000, 0 0))'::geometry));
 -- LINESTRING EMPTY -> CORRECT RESULT
 }}}

 {{{
 -- Polygon completely containing vertically straight line
 SELECT AsText(ST_Difference('LINESTRING (5 7, 5 11)'::geometry, 'POLYGON
 ((0 0, 1000 0, 1000 1000, 0 1000, 0 0))'::geometry));
 -- LINESTRING(5 7,5 11) -> INCORRECT RESULT
 }}}

 {{{
 -- Polygon completely containing horizontally straight line
 SELECT ST_AsText(ST_Difference('LINESTRING (5 7, 10 7)'::geometry,
 'POLYGON ((0 0, 1000 0, 1000 1000, 0 1000, 0 0))'::geometry));
 -- LINESTRING(5 7,10 7)-> INCORRECT RESULT
 }}}

 {{{
 -- Polygon partly containing vertically straight line
 SELECT ST_AsText(ST_Difference('LINESTRING(50 100, 50 200)'::geometry,
 'POLYGON((0 0, 0 150, 150 150, 150 0, 0 0))'::geometry));
 -- LINESTRING(50 150,50 200) -> CORRECT RESULT
 }}}

 {{{
 -- Polygon completely containing the interior of the vertically straight
 line, end point of the line intersects with polygon boundary
 SELECT ST_AsText(ST_Difference('LINESTRING(50 100, 50 150)'::geometry,
 'POLYGON((0 0, 0 150, 150 150, 150 0, 0 0))'::geometry));
 -- LINESTRING EMPTY -> CORRECT RESULT
 }}}
-- 
Ticket URL: <https://trac.osgeo.org/postgis/ticket/5426>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.


More information about the postgis-tickets mailing list