]> granicus.if.org Git - postgis/commitdiff
Stub topology.ST_ModEdgeHeal [RT-SIGTA]
authorSandro Santilli <strk@keybit.net>
Wed, 4 May 2011 18:19:39 +0000 (18:19 +0000)
committerSandro Santilli <strk@keybit.net>
Wed, 4 May 2011 18:19:39 +0000 (18:19 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@7085 b70326c6-7e19-0410-871a-916f4a2858ee

topology/sql/sqlmm.sql
topology/topology.sql.in.c

index 94b076f8a1c1a6da4861d269cb18900bd04631cc..3368ad9da7c1a0fb08782068fcf3a2f0226dac70 100644 (file)
@@ -102,6 +102,104 @@ $$
 LANGUAGE 'plpgsql' VOLATILE;
 --} ST_GetFaceEdges
 
+--{
+-- Topo-Geo and Topo-Net 3: Routine Details
+-- X.3.11
+--
+--  ST_ModEdgeHeal(atopology, anedge, anotheredge)
+--
+-- Not in the specs:
+-- * Returns the id of the node being removed
+-- * Refuses to heal two edges if any of the two is closed 
+-- * Raise an exception when trying to heal an edge with itself
+-- 
+CREATE OR REPLACE FUNCTION topology.ST_ModEdgeHeal(toponame varchar, e1id integer, e2id integer)
+  RETURNS int
+AS
+$$
+DECLARE
+  e1rec RECORD;
+  e2rec RECORD;
+  rec RECORD;
+  commonnode int;
+  caseno int;
+  sql text;
+BEGIN
+  --
+  -- toponame and face_id are required
+  -- 
+  IF toponame IS NULL OR e1id IS NULL OR e2id IS NULL THEN
+    RAISE EXCEPTION 'SQL/MM Spatial exception - null argument';
+  END IF;
+
+  -- NOT IN THE SPECS: see if the same edge is given twice..
+  IF e1id = e2id THEN
+    RAISE EXCEPTION 'Cannot heal edge % with itself, try with another', e1id;
+  END IF;
+
+  BEGIN
+    EXECUTE 'SELECT * FROM ' || quote_ident(toponame)
+      || '.edge_data WHERE edge_id = ' || e1id
+      INTO STRICT e1rec;
+    EXCEPTION
+      WHEN NO_DATA_FOUND THEN
+        RAISE EXCEPTION 'SQL/MM Spatial exception – non-existent edge %', e1id;
+  END;
+
+  BEGIN
+    EXECUTE 'SELECT * FROM ' || quote_ident(toponame)
+      || '.edge_data WHERE edge_id = ' || e2id
+      INTO STRICT e2rec;
+    EXCEPTION
+      WHEN NO_DATA_FOUND THEN
+        RAISE EXCEPTION 'SQL/MM Spatial exception – non-existent edge %', e2id;
+  END;
+
+  -- NOT IN THE SPECS: See if any of the two edges are closed.
+  IF e1rec.start_node = e1rec.end_node THEN
+    RAISE EXCEPTION 'Edge % is closed, cannot heal to edge %', e1id, e2id;
+  END IF;
+  IF e2rec.start_node = e2rec.end_node THEN
+    RAISE EXCEPTION 'Edge % is closed, cannot heal to edge %', e2id, e1id;
+  END IF;
+
+  -- Find common node
+  IF e1rec.end_node = e2rec.start_node THEN
+    commonnode = e1rec.end_node;
+    caseno = 1;
+  ELSIF e1rec.end_node = e2rec.end_node THEN
+    commonnode = e1rec.end_node;
+    caseno = 2;
+  ELSIF e1rec.start_node = e2rec.start_node THEN
+    commonnode = e1rec.start_node;
+    caseno = 3;
+  ELSIF e1rec.start_node = e2rec.end_node THEN
+    commonnode = e1rec.start_node;
+    caseno = 4;
+  ELSE
+    RAISE EXCEPTION 'SQL/MM Spatial exception – non-connected edges';
+  END IF;
+
+  -- Check if any other edge is connected to the common node
+  FOR rec IN EXECUTE 'SELECT edge_id FROM ' || quote_ident(toponame)
+    || '.edge_data WHERE ( edge_id != ' || e1id
+    || ' AND edge_id != ' || e2id || ') AND ( start_node = 2 OR end_node = 2 )'
+  LOOP
+    RAISE EXCEPTION
+      'SQL/MM Spatial exception – other edges connected (ie: %)', rec.edge_id;
+  END LOOP;
+
+  -- Now: delete the common node (expect panic!)
+  EXECUTE 'DELETE FROM ' || quote_ident(toponame)
+          || '.node WHERE node_id = ' || commonnode;
+  
+
+       RAISE EXCEPTION 'Not implemented yet';
+END
+$$
+LANGUAGE 'plpgsql' VOLATILE;
+--} ST_ModEdgeHeal
+
 
 --{
 -- Topo-Geo and Topo-Net 3: Routine Details
index 17529d9ecca356fd013568dcf8e542abf8d29d2f..501535b1f961c2fb14079148c2057c26be029061 100644 (file)
 --     TODO: add entries to the History table ?
 --
 --   ST_AddEdgeNewFaces
---     Being working on. TODO: continue
+--    Being working on. TODO: continue
 --  
 --   ST_GetFaceEdges
 --     Complete
+--
+--   ST_ModEdgeHeal
+--    Being working on. TODO: continue
 --  
 --   ST_GetFaceGeometry
 --     Implemented using polygonize()