]> granicus.if.org Git - postgis/commitdiff
ST_ChangeEdgeGeom: check existence of given edge, reduce scans used to check start...
authorSandro Santilli <strk@keybit.net>
Tue, 24 May 2011 08:45:55 +0000 (08:45 +0000)
committerSandro Santilli <strk@keybit.net>
Tue, 24 May 2011 08:45:55 +0000 (08:45 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@7227 b70326c6-7e19-0410-871a-916f4a2858ee

topology/sql/sqlmm.sql
topology/test/regress/st_changeedgegeom.sql
topology/test/regress/st_changeedgegeom_expected

index 6e110bdd4aa42a71785082f49dd8a55639d26f29..e82ccf82bbab3907e2673ac95c85d2ce50aa5920 100644 (file)
@@ -1778,41 +1778,33 @@ BEGIN
      'SQL/MM Spatial exception - curve not simple';
   END IF;
 
+  --
+  -- Get data about existing edge
+  --
+  BEGIN
+    EXECUTE 'SELECT * FROM ' || quote_ident(atopology) || '.edge_data  '
+      || ' WHERE edge_id = ' || anedge
+    INTO STRICT oldedge;
+  EXCEPTION
+    WHEN NO_DATA_FOUND THEN
+      RAISE EXCEPTION 'SQL/MM Spatial exception - non-existent edge %', anedge;
+  END;
+
   --
   -- e) Check StartPoint consistency
   --
-  FOR rec IN EXECUTE 'SELECT * FROM '
-    || quote_ident(atopology) || '.edge_data e, '
-    || quote_ident(atopology) || '.node n '
-    || ' WHERE e.edge_id = ' || anedge
-    || ' AND n.node_id = e.start_node '
-    || ' AND ( ST_X(n.geom) != '
-    || ST_X(ST_StartPoint(acurve))
-    || ' OR ST_Y(n.geom) != '
-    || ST_Y(ST_StartPoint(acurve))
-    || ')'
-  LOOP 
+  IF NOT ST_Equals(ST_StartPoint(acurve), ST_StartPoint(oldedge.geom)) THEN
     RAISE EXCEPTION
-    'SQL/MM Spatial exception - start node not geometry start point.';
-  END LOOP;
+      'SQL/MM Spatial exception - start node not geometry start point.';
+  END IF;
 
   --
   -- f) Check EndPoint consistency
   --
-  FOR rec IN EXECUTE 'SELECT * FROM '
-    || quote_ident(atopology) || '.edge_data e, '
-    || quote_ident(atopology) || '.node n '
-    || ' WHERE e.edge_id = ' || anedge
-    || ' AND n.node_id = e.end_node '
-    || ' AND ( ST_X(n.geom) != '
-    || ST_X(ST_EndPoint(acurve))
-    || ' OR ST_Y(n.geom) != '
-    || ST_Y(ST_EndPoint(acurve))
-    || ')'
-  LOOP 
+  IF NOT ST_Equals(ST_EndPoint(acurve), ST_EndPoint(oldedge.geom)) THEN
     RAISE EXCEPTION
-    'SQL/MM Spatial exception - end node not geometry end point.';
-  END LOOP;
+      'SQL/MM Spatial exception - end node not geometry end point.';
+  END IF;
 
   --
   -- g) Check if curve crosses any node
index 789619c07dafddfa39b0f3d2456d3d641a7f30e8..179bca4784ab8b82896e43ab1d8af68c6465ea3c 100644 (file)
@@ -17,7 +17,10 @@ SELECT topology.ST_ChangeEdgeGeom('city_data', 25,
 SELECT topology.ST_ChangeEdgeGeom('city_data', 3,
   'LINESTRING(25 30, 20 36, 20 38, 25 35)');
 
+-- Non-existent edge (#979)
+SELECT topology.ST_ChangeEdgeGeom('city_data', 666,
+  'LINESTRING(25 30, 20 36, 20 38, 25 35)');
+
 -- TODO: test edge crossing
--- TODO: test non-existent edge (#979)
 
 SELECT topology.DropTopology('city_data');
index 41c8d11c5066223a79237109e1af9224ece256c5..667550ab7126408226f2f40eb24ec8a99b5ccf6b 100644 (file)
@@ -8,4 +8,5 @@ Edge 25 changed
 ERROR:  SQL/MM Spatial exception - start node not geometry start point.
 ERROR:  SQL/MM Spatial exception - end node not geometry end point.
 ERROR:  SQL/MM Spatial exception - geometry crosses a node
+ERROR:  SQL/MM Spatial exception - non-existent edge 666
 Topology 'city_data' dropped