--
-- 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;
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
$$
-- 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');