]> granicus.if.org Git - postgis/commitdiff
ST_AddIsoEdge: set containing_face of nodes connected by the newly added edge to...
authorSandro Santilli <strk@keybit.net>
Mon, 23 May 2011 12:49:51 +0000 (12:49 +0000)
committerSandro Santilli <strk@keybit.net>
Mon, 23 May 2011 12:49:51 +0000 (12:49 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@7212 b70326c6-7e19-0410-871a-916f4a2858ee

topology/sql/sqlmm.sql
topology/test/regress/st_addisoedge.sql
topology/test/regress/st_addisoedge_expected

index c397c13ea78fa44acf7eccf3e9727f86b13f55b5..b0c33ff2bdaf24267af8885eec0140807dbf6ad7 100644 (file)
@@ -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
 $$
index fe4484935d0ef2b25aa13893d9167cd080f860e7..2c1e4dbbe36171579e02c1aa792da4e2b3f54575 100644 (file)
@@ -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');
index 16963d86493173649f525b8cf5edab16b2aa6918..78dabd108d2383f89b1937ef37ac7aadc2eaa23d 100644 (file)
@@ -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