From: Sandro Santilli Date: Wed, 4 May 2011 18:19:39 +0000 (+0000) Subject: Stub topology.ST_ModEdgeHeal [RT-SIGTA] X-Git-Tag: 2.0.0alpha1~1722 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=391f7897e796f4630d4cc8de84d37f9e882c5d45;p=postgis Stub topology.ST_ModEdgeHeal [RT-SIGTA] git-svn-id: http://svn.osgeo.org/postgis/trunk@7085 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/topology/sql/sqlmm.sql b/topology/sql/sqlmm.sql index 94b076f8a..3368ad9da 100644 --- a/topology/sql/sqlmm.sql +++ b/topology/sql/sqlmm.sql @@ -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 diff --git a/topology/topology.sql.in.c b/topology/topology.sql.in.c index 17529d9ec..501535b1f 100644 --- a/topology/topology.sql.in.c +++ b/topology/topology.sql.in.c @@ -152,10 +152,13 @@ -- 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()