From: Sandro Santilli Date: Mon, 23 May 2011 12:49:51 +0000 (+0000) Subject: ST_AddIsoEdge: set containing_face of nodes connected by the newly added edge to... X-Git-Tag: 2.0.0alpha1~1601 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c3ba1e62b5e3e9403dbe0f3bc99cc6afaa5610ba;p=postgis ST_AddIsoEdge: set containing_face of nodes connected by the newly added edge to null as the nodes are not isolated anymore. Regress test it. Closes ticket #976. git-svn-id: http://svn.osgeo.org/postgis/trunk@7212 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/topology/sql/sqlmm.sql b/topology/sql/sqlmm.sql index c397c13ea..b0c33ff2b 100644 --- a/topology/sql/sqlmm.sql +++ b/topology/sql/sqlmm.sql @@ -1493,14 +1493,16 @@ LANGUAGE 'plpgsql' VOLATILE; -- -- ST_AddIsoEdge(atopology, anode, anothernode, acurve) -- -CREATE OR REPLACE FUNCTION topology.ST_AddIsoEdge(varchar, integer, integer, geometry) +-- Not in the specs: +-- * Reset containing_face for starting and ending point, +-- as they stop being isolated nodes +-- +-- }{ +-- +CREATE OR REPLACE FUNCTION topology.ST_AddIsoEdge(atopology varchar, anode integer, anothernode integer, acurve geometry) RETURNS INTEGER AS $$ DECLARE - atopology ALIAS FOR $1; - anode ALIAS FOR $2; - anothernode ALIAS FOR $3; - acurve ALIAS FOR $4; aface INTEGER; face GEOMETRY; snodegeom GEOMETRY; @@ -1673,19 +1675,33 @@ BEGIN edgeid = rec.nextval; END LOOP; + -- TODO: this should likely be an exception instead ! + IF aface IS NULL THEN aface := 0; END IF; + -- -- Insert the new row -- - IF aface IS NULL THEN aface := 0; END IF; - - EXECUTE 'INSERT INTO ' || quote_ident(atopology) - || '.edge VALUES('||edgeid||','||anode|| - ','||anothernode||',' - ||(-edgeid)||','||edgeid||',' - ||aface||','||aface||',' - ||quote_literal(acurve::text)||')'; + EXECUTE 'INSERT INTO ' || quote_ident(atopology) + || '.edge VALUES(' || edgeid || ',' || anode + || ',' || anothernode || ',' || (-edgeid) + || ',' || edgeid || ',' + || aface || ',' || aface || ',' + || quote_literal(acurve::text) || ')'; - RETURN edgeid; + -- + -- Update Node containing_face values + -- + -- the nodes anode and anothernode are no more isolated + -- because now there is an edge connecting them + -- + EXECUTE 'UPDATE ' || quote_ident(atopology) + || '.node SET containing_face = NULL where (node_id =' + || anode + || ' OR node_id=' + || anothernode + || ')'; + + RETURN edgeid; END $$ diff --git a/topology/test/regress/st_addisoedge.sql b/topology/test/regress/st_addisoedge.sql index fe4484935..2c1e4dbbe 100644 --- a/topology/test/regress/st_addisoedge.sql +++ b/topology/test/regress/st_addisoedge.sql @@ -38,17 +38,31 @@ SELECT topology.ST_AddIsoEdge('sqlmm_topology', 1, 2, 'LINESTRING(0 1, 10 0)'); -- Node crossing SELECT topology.ST_AddIsoEdge('sqlmm_topology', 1, 2, 'LINESTRING(0 0, 10 0)'); --- Good ones -SELECT topology.ST_AddIsoEdge('sqlmm_topology', 4, 5, 'LINESTRING(5 10, 5 9, 10 10)'); -SELECT topology.ST_AddIsoEdge('sqlmm_topology', 1, 2, 'LINESTRING(0 0, 2 1, 10 5, 10 0)'); +-- Good one +SELECT 'E' || topology.ST_AddIsoEdge('sqlmm_topology', + 4, 5, 'LINESTRING(5 10, 5 9, 10 10)'); + +-- Another good one +SELECT 'E' || topology.ST_AddIsoEdge('sqlmm_topology', + 1, 2, 'LINESTRING(0 0, 2 1, 10 5, 10 0)'); + +-- Check that containing_face became NULL for the nodes which are +-- not isolated anymore (#976) +SELECT 'N' || node_id, containing_face FROM sqlmm_topology.node + ORDER BY node_id; -- Not isolated edge (shares endpoint with previous) -SELECT topology.ST_AddIsoEdge('sqlmm_topology', 4, 6, 'LINESTRING(5 10, 10 9, 20 10)'); -SELECT topology.ST_AddIsoEdge('sqlmm_topology', 5, 6, 'LINESTRING(10 10, 20 10)'); +SELECT topology.ST_AddIsoEdge('sqlmm_topology', + 4, 6, 'LINESTRING(5 10, 10 9, 20 10)'); +SELECT topology.ST_AddIsoEdge('sqlmm_topology', + 5, 6, 'LINESTRING(10 10, 20 10)'); -- Edge intersection (geometry intersects an edge) -SELECT topology.ST_AddIsoEdge('sqlmm_topology', 1, 2, 'LINESTRING(0 0, 2 20, 10 0)'); +SELECT topology.ST_AddIsoEdge('sqlmm_topology', + 1, 2, 'LINESTRING(0 0, 2 20, 10 0)'); +-- TODO: check closed edge (not-isolated I guess...) -- on different faces (TODO req. nodes contained in face) + SELECT topology.DropTopology('sqlmm_topology'); diff --git a/topology/test/regress/st_addisoedge_expected b/topology/test/regress/st_addisoedge_expected index 16963d864..78dabd108 100644 --- a/topology/test/regress/st_addisoedge_expected +++ b/topology/test/regress/st_addisoedge_expected @@ -15,8 +15,14 @@ ERROR: SQL/MM Spatial exception - non-existent node ERROR: SQL/MM Spatial exception - end node not geometry end point. ERROR: SQL/MM Spatial exception - start node not geometry start point. ERROR: SQL/MM Spatial exception - geometry crosses a node -1 -2 +E1 +E2 +N1| +N2| +N3|0 +N4| +N5| +N6|0 ERROR: SQL/MM Spatial exception - not isolated node ERROR: SQL/MM Spatial exception - not isolated node ERROR: SQL/MM Spatial exception - not isolated node