[postgis-tickets] r14690 - Check for side-location conflicts when adding a new edge

Sandro Santilli strk at keybit.net
Wed Feb 24 09:25:11 PST 2016


Author: strk
Date: 2016-02-24 09:25:11 -0800 (Wed, 24 Feb 2016)
New Revision: 14690

Modified:
   trunk/liblwgeom/lwgeom_topo.c
   trunk/topology/test/regress/st_addedgemodface.sql
   trunk/topology/test/regress/st_addedgemodface_expected
Log:
Check for side-location conflicts when adding a new edge

It is possible to trigger such failure adding an edge
to a corrupted topology. Test added.

See #3464

Modified: trunk/liblwgeom/lwgeom_topo.c
===================================================================
--- trunk/liblwgeom/lwgeom_topo.c	2016-02-24 17:18:09 UTC (rev 14689)
+++ trunk/liblwgeom/lwgeom_topo.c	2016-02-24 17:25:11 UTC (rev 14690)
@@ -2561,9 +2561,27 @@
                 newedge.edge_id, newedge.next_left, prev_right);
     if ( newedge.face_right == -1 ) {
       newedge.face_right = span.ccwFace;
+    } else if ( newedge.face_right != epan.ccwFace ) {
+      /* side-location conflict */
+      lwerror("Side-location conflict: "
+              "new edge starts in face"
+               " %" PRId64 " and ends in face"
+               " %" PRId64,
+              newedge.face_right, epan.ccwFace
+      );
+      return -1;
     }
     if ( newedge.face_left == -1 ) {
       newedge.face_left = span.cwFace;
+    } else if ( newedge.face_left != epan.cwFace ) {
+      /* side-location conflict */
+      lwerror("Side-location conflict: "
+              "new edge starts in face"
+               " %" PRId64 " and ends in face"
+               " %" PRId64,
+              newedge.face_left, epan.cwFace
+      );
+      return -1;
     }
   } else {
     epan.was_isolated = 1;

Modified: trunk/topology/test/regress/st_addedgemodface.sql
===================================================================
--- trunk/topology/test/regress/st_addedgemodface.sql	2016-02-24 17:18:09 UTC (rev 14689)
+++ trunk/topology/test/regress/st_addedgemodface.sql	2016-02-24 17:25:11 UTC (rev 14690)
@@ -476,6 +476,31 @@
   ( SELECT edge_id FROM newedge WHERE id = 29 ) )
   ORDER BY edge_id;
 
+--
+-- Attempt to add an edge to a topology with conflicting
+-- side-locations (face left/right information)
+--
+-- See https://trac.osgeo.org/postgis/ticket/3464
+
+--BEGIN; prot
+-- Break face info for edge 6
+UPDATE city_data.edge_data SET left_face = left_face + 1
+  WHERE edge_id = 6;
+-- First attempt to add edge, expect to find corrupted topology
+SELECT '#3464.1', topology.ST_AddEdgeModFace('city_data', 16, 19,
+ 'LINESTRING(9 22,28 25,47 22)');
+-- Break face info for edges 21
+UPDATE city_data.edge_data SET left_face = left_face + 1
+  WHERE edge_id = 21;
+-- Second attempt to add an edge splitting the now-conflicting face
+SELECT '#3464.2', topology.ST_AddEdgeModFace('city_data', 16, 19,
+ 'LINESTRING(9 22,28 25,47 22)');
+-- Restore face info for edge 6 and 21
+UPDATE city_data.edge_data SET left_face = left_face - 1
+  WHERE edge_id in ( 6, 21 );
+
+--BEGIN; prot;
+
 ---------------------------------------------------------------------
 -- Check new relations and faces status
 ---------------------------------------------------------------------

Modified: trunk/topology/test/regress/st_addedgemodface_expected
===================================================================
--- trunk/topology/test/regress/st_addedgemodface_expected	2016-02-24 17:18:09 UTC (rev 14689)
+++ trunk/topology/test/regress/st_addedgemodface_expected	2016-02-24 17:25:11 UTC (rev 14690)
@@ -167,6 +167,8 @@
 T29|E33|-55|-6|17|3
 T29|E34|55|9|35|16
 T29|E55|-21|19|35|17
+ERROR:  Corrupted topology: adjacent edges 6 and -21 bind different face (1 and 0)
+ERROR:  Side-location conflict: new edge starts in face 1 and ends in face 0
 F17|{3:17,3:35}
 F3,F4|{3:3,3:4,3:10,3:16,3:17,3:35}
 F5,N4|{1:4,3:5,3:11}



More information about the postgis-tickets mailing list