From: Sandro Santilli Date: Tue, 24 May 2011 08:45:55 +0000 (+0000) Subject: ST_ChangeEdgeGeom: check existence of given edge, reduce scans used to check start... X-Git-Tag: 2.0.0alpha1~1586 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=859f148607f64e6a2fe6fda17fcfd022528dd2c6;p=postgis ST_ChangeEdgeGeom: check existence of given edge, reduce scans used to check start/end point and simplify the code, regress test the fix. Fixes bug #979. git-svn-id: http://svn.osgeo.org/postgis/trunk@7227 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/topology/sql/sqlmm.sql b/topology/sql/sqlmm.sql index 6e110bdd4..e82ccf82b 100644 --- a/topology/sql/sqlmm.sql +++ b/topology/sql/sqlmm.sql @@ -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 diff --git a/topology/test/regress/st_changeedgegeom.sql b/topology/test/regress/st_changeedgegeom.sql index 789619c07..179bca478 100644 --- a/topology/test/regress/st_changeedgegeom.sql +++ b/topology/test/regress/st_changeedgegeom.sql @@ -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'); diff --git a/topology/test/regress/st_changeedgegeom_expected b/topology/test/regress/st_changeedgegeom_expected index 41c8d11c5..667550ab7 100644 --- a/topology/test/regress/st_changeedgegeom_expected +++ b/topology/test/regress/st_changeedgegeom_expected @@ -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