pggeodb.nancy.inra.fr/db_toff - db_toff on pggeodb.nancy.inra.fr
Previous topic Chapter index Next topic

Function: addnode

 

 

Schema

topology

 

Owner

postgres

 

Descriptions

args: toponame, apoint, allowEdgeSplitting=false, computeContainingFace=false - Adds a point node to the node table in the specified topology schema and returns the nodeid of new node. If point already exists as node, the existing nodeid is returned.

 

Options

Option

Value

Returns

integer

Language

plpgsql

Parameters

atopology varchar

apoint public.geometry

allowedgesplitting boolean

setcontainingface boolean = false

 

Definition

CREATE OR REPLACE FUNCTION topology.addnode (
 atopology varchar,
 apoint public.geometry,
 allowedgesplitting boolean,
 setcontainingface boolean = false
)
RETURNS integer AS
$span$
DECLARE

nodeid int;
rec RECORD;
 containing_face int;
BEGIN
--
-- Atopology and apoint are required
--

IF atopology IS NULL OR apoint IS NULL THEN
RAISE EXCEPTION
'Invalid null argument';
END IF;

--
-- Apoint must be a point
--

IF substring(geometrytype(apoint), 1, 5) != 'POINT'
THEN
RAISE EXCEPTION
'Node geometry must be a point';
END IF;

--
-- Check if a coincident node already exists
--
-- We use index AND x/y equality
--

FOR rec IN EXECUTE 'SELECT node_id FROM '
|| quote_ident(atopology) || '.node ' ||
'WHERE geom && $1 AND ST_X(geom) = ST_X($1) AND ST_Y(geom) = ST_Y($1)'
   USING apoint
LOOP
RETURN  rec.node_id;
END LOOP;

--
-- Check if any edge crosses this node
-- (endpoints are fine)
--

FOR rec IN EXECUTE 'SELECT edge_id FROM '
|| quote_ident(atopology) || '.edge '
|| 'WHERE ST_DWithin($1, geom, 0) AND '
   || 'NOT ST_Equals($1, ST_StartPoint(geom)) AND '
   || 'NOT ST_Equals($1, ST_EndPoint(geom))'
   USING apoint
LOOP
   IF allowEdgeSplitting THEN
     RETURN
topology.ST_ModEdgeSplit(atopology, rec.edge_id, apoint);
   ELSE
 RAISE EXCEPTION
'An edge crosses the given node.';
   END IF;
END LOOP;

 IF setContainingFace THEN
   containing_face := topology.GetFaceByPoint(atopology, apoint, 0);
 ELSE
   containing_face := NULL;
 END IF;

--
-- Get new node id from sequence
--

FOR rec IN EXECUTE 'SELECT nextval(' ||
quote_literal(
quote_ident(atopology) || '.node_node_id_seq'
) || ')'
LOOP
nodeid = rec.nextval;
END LOOP;

--
-- Insert the new row
--

EXECUTE 'INSERT INTO ' || quote_ident(atopology)
|| '.node(node_id, containing_face, geom)
VALUES('
|| nodeid || ',' || coalesce(containing_face::text, 'NULL')
   || ',$1)' USING apoint;

RETURN nodeid;

END
$span$
LANGUAGE
'plpgsql'
VOLATILE
CALLED ON NULL INPUT
SECURITY INVOKER
COST
100;

COMMENT ON FUNCTION topology.addnode(atopology varchar, apoint public.geometry, allowedgesplitting boolean, setcontainingface boolean)
IS 'args: toponame, apoint, allowEdgeSplitting=false, computeContainingFace=false - Adds a point node to the node table in the specified topology schema and returns the nodeid of new node. If point already exists as node, the existing nodeid is returned.';

This file was generated with SQL Manager for PostgreSQL (www.pgsqlmanager.com) at 13/03/2014 13:23
Previous topic Chapter index Next topic