--
FOR rec IN EXECUTE 'SELECT node_id FROM '
|| quote_ident(atopology) || '.node ' ||
- 'WHERE geom && ' || quote_literal(apoint::text) || '::geometry'
- ||' AND ST_X(geom) = ST_X('||quote_literal(apoint::text)||'::geometry)'
- ||' AND ST_Y(geom) = ST_Y('||quote_literal(apoint::text)||'::geometry)'
+ '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;
--
FOR rec IN EXECUTE 'SELECT edge_id FROM '
|| quote_ident(atopology) || '.edge '
- || 'WHERE ST_DWithin('
- || quote_literal(apoint::text)
- || ', geom, 0) AND NOT ST_Equals('
- || quote_literal(apoint::text)
- || ', ST_StartPoint(geom)) AND NOT ST_Equals('
- || quote_literal(apoint::text)
- || ', ST_EndPoint(geom))'
+ || '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 ST_ModEdgeSplit(atopology, rec.edge_id, apoint);
--
EXECUTE 'INSERT INTO ' || quote_ident(atopology)
|| '.node(node_id, containing_face, geom)
- VALUES(' || nodeid || ',' || coalesce(containing_face::text, 'NULL') || ','
- || quote_literal(apoint::text) || ')';
+ VALUES(' || nodeid || ',' || coalesce(containing_face::text, 'NULL')
+ || ',$1)' USING apoint;
RETURN nodeid;
--
FOR rec IN EXECUTE 'SELECT node_id FROM '
|| quote_ident(atopology) || '.node '
- || 'WHERE ST_Crosses('
- || quote_literal(aline::text) || '::geometry, geom'
- || ')'
+ || 'WHERE ST_Crosses($1, geom)'
+ USING aline
LOOP
RAISE EXCEPTION 'Edge crosses node %', rec.node_id;
END LOOP;
-- FF1 F0F 1F2
-- FF1 F** 1*2 <-- our match
--
- FOR rec IN EXECUTE 'SELECT edge_id, geom, ST_Relate('
- || quote_literal(aline::text)
- || '::geometry, geom, 2) as im'
- || ' FROM '
- || quote_ident(atopology) || '.edge '
- || 'WHERE '
- || quote_literal(aline::text) || '::geometry && geom'
-
+ FOR rec IN EXECUTE 'SELECT edge_id, geom, ST_Relate($1, geom, 2) as im FROM '
+ || quote_ident(atopology) || '.edge WHERE $1 && geom'
+ USING aline
LOOP
IF ST_RelateMatch(rec.im, 'FF1F**1*2') THEN
-- start_node
|| 'topology.addNode('
|| quote_literal(atopology)
- || ', ST_StartPoint('
- || quote_literal(aline::text)
- || ')) ,'
+ || ', ST_StartPoint($1)), '
-- end_node
|| 'topology.addNode('
|| quote_literal(atopology)
- || ', ST_EndPoint('
- || quote_literal(aline::text)
- || ')) ,'
+ || ', ST_EndPoint($1)), '
-- next_left_edge
|| -edgeid ||','
|| '0,'
-- geom
- ||quote_literal(aline::text)
- || ')';
+ || '$1)'
+ USING aline;
RETURN edgeid;
--
bounds = ST_Boundary(rrec.geom);
- sql := 'SELECT e.geom, e.edge_id, '
- || 'e.left_face, e.right_face FROM '
- || quote_ident(atopology) || '.edge e, (SELECT '
- || quote_literal(bounds::text)
- || '::geometry as geom) r WHERE '
- || 'r.geom && e.geom'
+ sql := 'SELECT e.geom, e.edge_id, e.left_face, e.right_face FROM '
+ || quote_ident(atopology)
+ || '.edge e, (SELECT $1 as geom) r WHERE r.geom && e.geom'
;
-- RAISE DEBUG 'SQL: %', sql;
- FOR rec IN EXECUTE sql
+ FOR rec IN EXECUTE sql USING bounds
LOOP -- {
--RAISE DEBUG 'Edge % has bounding box intersection', rec.edge_id;
-- face_id
|| faceid || ','
-- minimum bounding rectangle
- || quote_literal(ST_Envelope(apoly)::text)
- || ')';
+ || '$1)'
+ USING ST_Envelope(apoly);
--
-- Update all edges having this face on the left
|| quote_literal(faceid)
|| ', left_face = '
|| quote_literal(faceid)
- || ' WHERE ST_Contains('
- || quote_literal(apoly::text)
- || ', geom)';
+ || ' WHERE ST_Contains($1, geom)'
+ USING apoly;
--
-- Set containing_face of any contained node
|| quote_ident(atopology)
|| '.node SET containing_face = '
|| quote_literal(faceid)
- || ' WHERE containing_face IS NOT NULL AND ST_Contains('
- || quote_literal(apoly::text)
- || ', geom)';
+ || ' WHERE containing_face IS NOT NULL AND ST_Contains($1, geom)'
+ USING apoly;
RETURN faceid;
-- and if so pick the closest
sql := 'SELECT a.node_id FROM '
|| quote_ident(atopology)
- || '.node as a WHERE ST_DWithin(a.geom,'
- || quote_literal(apoint::text) || '::geometry,'
- || tol || ') AND ST_Distance('
- || quote_literal(apoint::text)
- || '::geometry, a.geom) < ' || tol || ' ORDER BY ST_Distance('
- || quote_literal(apoint::text)
- || '::geometry, a.geom) LIMIT 1;';
+ || '.node as a WHERE ST_DWithin(a.geom,$1,'
+ || tol || ') AND ST_Distance($1, a.geom) < ' || tol
+ || ' ORDER BY ST_Distance($1, a.geom) LIMIT 1';
#ifdef POSTGIS_TOPOLOGY_DEBUG
RAISE DEBUG '%', sql;
#endif
- EXECUTE sql INTO id;
+ EXECUTE sql INTO id USING apoint;
IF id IS NOT NULL THEN
RETURN id;
END IF;
-- and if so split it by a point projected on it
sql := 'SELECT a.edge_id, a.geom FROM '
|| quote_ident(atopology)
- || '.edge as a WHERE ST_DWithin(a.geom,'
- || quote_literal(apoint::text) || '::geometry,'
- || tol || ') ORDER BY ST_Distance('
- || quote_literal(apoint::text)
- || '::geometry, a.geom) LIMIT 1;';
+ || '.edge as a WHERE ST_DWithin(a.geom,$1,'
+ || tol || ') ORDER BY ST_Distance($1, a.geom) LIMIT 1';
#ifdef POSTGIS_TOPOLOGY_DEBUG
RAISE DEBUG '%', sql;
#endif
- EXECUTE sql INTO rec;
+ EXECUTE sql INTO rec USING apoint;
IF rec IS NOT NULL THEN
-- project point to line, split edge by point
prj := ST_ClosestPoint(rec.geom, apoint);
-- 2. Node to edges falling within tol distance
sql := 'WITH nearby AS ( SELECT e.geom FROM '
|| quote_ident(atopology)
- || '.edge e WHERE ST_DWithin(e.geom, '
- || quote_literal(noded::text)
- || '::geometry, '
- || tol || ') ) SELECT st_collect(geom) FROM nearby;';
+ || '.edge e WHERE ST_DWithin(e.geom, $1,'
+ || tol || ') ) SELECT st_collect(geom) FROM nearby';
#ifdef POSTGIS_TOPOLOGY_DEBUG
RAISE DEBUG '%', sql;
#endif
- EXECUTE sql INTO iedges;
+ EXECUTE sql INTO iedges USING noded;
IF iedges IS NOT NULL THEN
#ifdef POSTGIS_TOPOLOGY_DEBUG
-- TODO: check if we should be only considering _isolated_ nodes!
sql := 'WITH nearby AS ( SELECT n.geom FROM '
|| quote_ident(atopology)
- || '.node n WHERE ST_DWithin(n.geom, '
- || quote_literal(noded::text)
- || '::geometry, '
+ || '.node n WHERE ST_DWithin(n.geom, $1, '
|| tol || ') ) SELECT st_collect(geom) FROM nearby;';
#ifdef POSTGIS_TOPOLOGY_DEBUG
RAISE DEBUG '%', sql;
#endif
- EXECUTE sql INTO inodes;
+ EXECUTE sql INTO inodes USING noded;
IF inodes IS NOT NULL THEN -- {
#ifdef POSTGIS_TOPOLOGY_DEBUG
-- Check if the so-snapped edge _now_ exists
sql := 'SELECT edge_id FROM ' || quote_ident(atopology)
- || '.edge_data WHERE ST_Equals(geom, ' || quote_literal(snapped::text)
- || '::geometry)';
+ || '.edge_data WHERE ST_Equals(geom, $1)';
#ifdef POSTGIS_TOPOLOGY_DEBUG
RAISE DEBUG '%', sql;
#endif
- EXECUTE sql INTO id;
+ EXECUTE sql INTO id USING snapped;
IF id IS NULL THEN
id := topology.ST_AddEdgeModFace(atopology, start_node, end_node,
snapped);
-- 3. Find faces covered by input polygon
-- NOTE: potential snapping changed polygon edges
sql := 'SELECT DISTINCT f.face_id FROM ' || quote_ident(atopology)
- || '.face f WHERE f.mbr && '
- || quote_literal(apoly::text)
- || '::geometry';
+ || '.face f WHERE f.mbr && $1';
#ifdef POSTGIS_TOPOLOGY_DEBUG
RAISE DEBUG '%', sql;
#endif
- FOR rec IN EXECUTE sql LOOP
+ FOR rec IN EXECUTE sql USING apoly LOOP
-- check for actual containment
fgeom := ST_PointOnSurface(ST_GetFaceGeometry(atopology, rec.face_id));
IF NOT ST_Covers(apoly, fgeom) THEN
sql := 'WITH er2 AS ( '
|| 'WITH er AS ( SELECT '
|| 'min(e.edge_id) over (), count(*) over () as cnt, e.edge_id, '
- || 'ST_LineLocatePoint('
- || quote_literal(bounds::text)
+ || 'ST_LineLocatePoint($1'
|| ', ST_LineInterpolatePoint(e.geom, 0.2)) as pos'
- || ', ST_LineLocatePoint('
- || quote_literal(bounds::text)
+ || ', ST_LineLocatePoint($1'
|| ', ST_LineInterpolatePoint(e.geom, 0.8)) as pos2 FROM '
|| quote_ident(toponame)
|| '.edge e WHERE ( e.left_face = ' || face_id
|| ' OR e.right_face = ' || face_id
- || ') AND ST_Covers('
- || quote_literal(bounds::text)
- || ', e.geom)';
+ || ') AND ST_Covers($1, e.geom)';
IF face_id = 0 THEN
sql := sql || ' ORDER BY POS ASC) ';
ELSE
--RAISE DEBUG 'SQL: %', sql;
- FOR rec IN EXECUTE sql
+ FOR rec IN EXECUTE sql USING bounds
LOOP
#ifdef POSTGIS_TOPOLOGY_DEBUG
|| ',' || rec.next_right_edge
|| ',' || rec.left_face
|| ',' || rec.right_face
- || ',' || quote_literal(rec.geom::text)
- || ')';
+ || ', $1)'
+ USING rec.geom;
-- End of new edge insertion }
-- Update next_left_edge/next_right_edge for
e2sign = 1;
END IF;
EXECUTE 'UPDATE ' || quote_ident(toponame)
- || '.edge_data SET geom = ' || quote_literal(rec.geom::text)
+ || '.edge_data SET geom = $1'
|| ', start_node = ' || rec.start_node
|| ', end_node = ' || rec.end_node
|| ', next_left_edge = ' || rec.next_left_edge
|| ', abs_next_left_edge = ' || abs(rec.next_left_edge)
|| ', next_right_edge = ' || rec.next_right_edge
|| ', abs_next_right_edge = ' || abs(rec.next_right_edge)
- || ' WHERE edge_id = ' || e1id;
+ || ' WHERE edge_id = ' || e1id
+ USING rec.geom;
-- End of first edge update }
-- Update next_left_edge/next_right_edge for
-- We use index AND x/y equality
--
FOR rec IN EXECUTE 'SELECT node_id FROM '
- || quote_ident(atopology) || '.node ' ||
- 'WHERE ST_Equals(geom, ' || quote_literal(apoint::text) || '::geometry)'
+ || quote_ident(atopology)
+ || '.node WHERE ST_Equals(geom, $1)'
+ USING apoint
LOOP
RAISE EXCEPTION
'SQL/MM Spatial exception - coincident node';
--
FOR rec IN EXECUTE 'SELECT edge_id FROM '
|| quote_ident(atopology) || '.edge '
- || 'WHERE ST_Intersects(geom, ' || quote_literal(apoint::text)
- || '::geometry)'
+ || 'WHERE ST_Intersects(geom, $1)'
+ USING apoint
LOOP
RAISE EXCEPTION
'SQL/MM Spatial exception - edge crosses node.';
--
sql := 'SELECT f.face_id FROM '
|| quote_ident(atopology)
- || '.face f WHERE f.face_id > 0 AND f.mbr && '
- || quote_literal(apoint::text)
- || '::geometry AND ST_Contains(topology.ST_GetFaceGeometry('
+ || '.face f WHERE f.face_id > 0 AND f.mbr && $1'
+ || ' AND ST_Contains(topology.ST_GetFaceGeometry('
|| quote_literal(atopology)
- || ', f.face_id), '
- || quote_literal(apoint::text)
- || '::geometry)';
+ || ', f.face_id), $1)'
+ ;
IF aface IS NOT NULL AND aface != 0 THEN
sql := sql || ' AND f.face_id = ' || aface;
END IF;
#ifdef POSTGIS_TOPOLOGY_DEBUG
RAISE DEBUG '%', sql;
#endif
- EXECUTE sql INTO containingface;
+ EXECUTE sql INTO containingface USING apoint;
-- If aface was specified, check that it was correct
IF aface IS NOT NULL THEN -- {
|| quote_ident(atopology)
|| '.node(node_id, geom, containing_face) SELECT nextval('
|| quote_literal( quote_ident(atopology) || '.node_node_id_seq' )
- || '),'
- ||quote_literal(apoint::text)
- || '::geometry,' || containingface
+ || '), $1, '
+ || containingface
|| ' RETURNING node_id';
#ifdef POSTGIS_TOPOLOGY_DEBUG
RAISE DEBUG '%', sql;
#endif
- EXECUTE sql INTO nodeid;
+ EXECUTE sql INTO nodeid USING apoint;
RETURN nodeid;
EXCEPTION
-- We use index AND x/y equality
--
FOR rec IN EXECUTE 'SELECT node_id FROM '
- || quote_ident(atopology) || '.node ' ||
- 'WHERE geom && ' || quote_literal(apoint::text) || '::geometry'
- ||' AND ST_X(geom) = ST_X('||quote_literal(apoint::text)||'::geometry)'
- ||' AND ST_Y(geom) = ST_Y('||quote_literal(apoint::text)||'::geometry)'
+ || quote_ident(atopology)
+ || '.node WHERE geom && $1 '
+ ||' AND ST_X(geom) = ST_X($1) AND ST_Y(geom) = ST_Y($1)'
+ USING apoint
LOOP
RAISE EXCEPTION
'SQL/MM Spatial exception - coincident node';
-- I used _intersects_ here to include boundaries (endpoints)
--
FOR rec IN EXECUTE 'SELECT edge_id FROM '
- || quote_ident(atopology) || '.edge '
- || 'WHERE geom && ' || quote_literal(apoint::text)
- || ' AND ST_Intersects(geom, ' || quote_literal(apoint::text)
- || '::geometry)'
+ || quote_ident(atopology)
+ || '.edge WHERE ST_Intersects(geom, $1)'
+ USING apoint
LOOP
RAISE EXCEPTION
'SQL/MM Spatial exception - edge crosses node.';
-- Update node point
--
EXECUTE 'UPDATE ' || quote_ident(atopology) || '.node '
- || ' SET geom = ' || quote_literal(apoint::text)
- || ' WHERE node_id = ' || anode;
+ || ' SET geom = $1 WHERE node_id = $2'
+ USING apoint, anode;
RETURN 'Isolated Node ' || anode || ' moved to location '
|| ST_X(apoint) || ',' || ST_Y(apoint);
-- Check if a coincident node already exists
--
FOR rec IN EXECUTE 'SELECT node_id FROM '
- || quote_ident(atopology) || '.node '
- || 'WHERE geom && '
- || quote_literal(apoint::text) || '::geometry'
- || ' AND ST_X(geom) = ST_X('
- || quote_literal(apoint::text) || '::geometry)'
- || ' AND ST_Y(geom) = ST_Y('
- || quote_literal(apoint::text) || '::geometry)'
+ || quote_ident(atopology) || '.node WHERE geom && $1 '
+ || ' AND ST_X(geom) = ST_X($1) AND ST_Y(geom) = ST_Y($1)'
+ USING apoint
LOOP
RAISE EXCEPTION
'SQL/MM Spatial exception - coincident node';
-- Add the new node
--
EXECUTE 'INSERT INTO ' || quote_ident(atopology)
- || '.node(node_id, geom)
- VALUES(' || nodeid || ','
- || quote_literal(apoint::text)
- || ')';
+ || '.node(node_id, geom) VALUES($1, $2)'
+ USING nodeid, apoint;
--
-- Delete the old edge
--
- EXECUTE 'DELETE FROM ' || quote_ident(atopology) || '.edge_data '
- || ' WHERE edge_id = ' || anedge;
+ EXECUTE 'DELETE FROM ' || quote_ident(atopology)
+ || '.edge_data WHERE edge_id = $1'
+ USING anedge;
--
-- Compute new edges
END
|| ',' || oldedge.left_face -- left_face
|| ',' || oldedge.right_face -- right_face
- || ',' || quote_literal(edge1::text) -- geom
- ||')';
+ || ',$1)' -- geom
+ USING edge1;
EXECUTE 'INSERT INTO ' || quote_ident(atopology)
|| '.edge VALUES('
|| ',' || -edgeid1 -- next_right_edge
|| ',' || oldedge.left_face -- left_face
|| ',' || oldedge.right_face -- right_face
- || ',' || quote_literal(edge2::text) -- geom
- ||')';
+ || ',$1)' -- geom
+ USING edge2;
--
-- Update all next edge references to match new layout
-- Check if a coincident node already exists
--
FOR rec IN EXECUTE 'SELECT node_id FROM '
- || quote_ident(atopology) || '.node ' ||
- 'WHERE geom && '
- || quote_literal(apoint::text) || '::geometry'
- ||' AND ST_X(geom) = ST_X('
- || quote_literal(apoint::text) || '::geometry)'
- ||' AND ST_Y(geom) = ST_Y('
- ||quote_literal(apoint::text)||'::geometry)'
+ || quote_ident(atopology) || '.node WHERE geom && $1'
+ ||' AND ST_X(geom) = ST_X($1) AND ST_Y(geom) = ST_Y($1)'
+ USING apoint
LOOP
RAISE EXCEPTION
'SQL/MM Spatial exception - coincident node';
-- Add the new node
--
EXECUTE 'INSERT INTO ' || quote_ident(atopology)
- || '.node(node_id, geom)
- VALUES('||nodeid||','||quote_literal(apoint::text)||
- ')';
+ || '.node(node_id, geom) VALUES($1, $2)'
+ USING nodeid,apoint;
--
-- Compute new edge
|| ',' || -anedge -- next_right_edge
|| ',' || oldedge.left_face -- left_face
|| ',' || oldedge.right_face -- right_face
- || ',' || quote_literal(newedge2::text) -- geom
- ||')';
+ || ',$1)' --geom
+ USING newedge2;
--
-- Update the old edge
--
- EXECUTE 'UPDATE ' || quote_ident(atopology) || '.edge_data '
- || ' SET geom = ' || quote_literal(newedge1::text)
- || ','
- || ' next_left_edge = ' || newedgeid
- || ', abs_next_left_edge = ' || newedgeid
- || ','
- || ' end_node = ' || nodeid
- || ' WHERE edge_id = ' || anedge;
+ EXECUTE 'UPDATE ' || quote_ident(atopology)
+ || '.edge_data SET geom = $1, next_left_edge = $2, '
+ || 'abs_next_left_edge = $2, end_node = $3 WHERE edge_id = $4'
+ USING newedge1, newedgeid, nodeid, anedge;
--
--
FOR rec IN EXECUTE 'SELECT node_id FROM '
|| quote_ident(atopology) || '.node '
- || ' WHERE geom && ' || quote_literal(acurve::text)
- || ' AND ST_Contains(' || quote_literal(acurve::text)
- || ',geom)'
+ || ' WHERE ST_Contains($1, geom)'
+ USING acurve
LOOP
RAISE EXCEPTION
'SQL/MM Spatial exception - geometry crosses a node';
--
FOR rec IN EXECUTE 'SELECT * FROM '
|| quote_ident(atopology) || '.edge_data
- WHERE ST_Intersects(geom, ' || quote_literal(acurve::text) || '::geometry)'
+ WHERE ST_Intersects(geom, $1)'
+ USING acurve
LOOP
RAISE EXCEPTION 'SQL/MM Spatial exception - geometry intersects an edge';
END LOOP;
|| '.edge VALUES(' || edgeid || ',' || anode
|| ',' || anothernode || ',' || (-edgeid)
|| ',' || edgeid || ','
- || aface || ',' || aface || ','
- || quote_literal(acurve::text) || ')';
+ || aface || ',' || aface || ',$1)'
+ USING acurve;
--
-- Update Node containing_face values
-- g) Check if curve crosses any node
--
FOR rec IN EXECUTE
- 'SELECT node_id, ST_Relate(geom, '
- || quote_literal(acurve::text) || '::geometry, 2) as relate FROM '
+ 'SELECT node_id, ST_Relate(geom, $1, 2) as relate FROM '
|| quote_ident(atopology)
- || '.node WHERE geom && '
- || quote_literal(acurve::text)
- || '::geometry AND node_id NOT IN ('
+ || '.node WHERE geom && $1 AND node_id NOT IN ('
|| oldedge.start_node || ',' || oldedge.end_node
|| ')'
+ USING acurve
LOOP
IF ST_RelateMatch(rec.relate, 'T********') THEN
RAISE EXCEPTION 'SQL/MM Spatial exception - geometry crosses a node';
--
-- h) Check if this geometry has any interaction with any existing edge
--
- sql := 'SELECT edge_id, ST_Relate(geom,'
- || quote_literal(acurve::text)
- || '::geometry, 2) as im FROM '
+ sql := 'SELECT edge_id, ST_Relate(geom, $1, 2) as im FROM '
|| quote_ident(atopology)
- || '.edge_data WHERE edge_id != ' || anedge || ' AND geom && '
- || quote_literal(acurve::text) || '::geometry';
- FOR rec IN EXECUTE sql LOOP -- {
+ || '.edge_data WHERE edge_id != $2 AND geom && $1';
+ FOR rec IN EXECUTE sql USING acurve, anedge LOOP -- {
--RAISE DEBUG 'IM=%',rec.im;
sql := 'SELECT ST_Collect(geom) as nodes, '
|| 'null::geometry as r1, null::geometry as r2 FROM '
|| quote_ident(atopology)
- || '.node WHERE geom && '
- || quote_literal(ST_Collect(ST_Envelope(oldedge.geom),
- ST_Envelope(acurve))::text)
- || '::geometry AND node_id NOT IN ( '
+ || '.node WHERE geom && $1 AND node_id NOT IN ( '
|| oldedge.start_node || ',' || oldedge.end_node || ')';
#ifdef POSTGIS_TOPOLOGY_DEBUG
RAISE DEBUG '%', sql;
#endif
- EXECUTE sql INTO rng_info;
+ EXECUTE sql INTO rng_info USING ST_Collect(ST_Envelope(oldedge.geom),
+ ST_Envelope(acurve))
+ ;
-- There's no collision if there's no nodes in the combined
-- bbox of old and new edges.
-- Update edge geometry
--
EXECUTE 'UPDATE ' || quote_ident(atopology) || '.edge_data '
- || ' SET geom = ' || quote_literal(acurve::text)
- || ' WHERE edge_id = ' || anedge;
+ || ' SET geom = $1 WHERE edge_id = $2'
+ USING acurve, anedge;
--
-- Check edge adjacency after
-- would be larger than the old face MBR...
--
IF oldedge.left_face != 0 THEN
- sql := 'UPDATE ' || quote_ident(atopology) || '.face '
- || ' SET mbr = ' || quote_literal(
- ST_Envelope(ST_GetFaceGeometry(atopology, oldedge.left_face))::text
- )
- || '::geometry WHERE face_id = ' || oldedge.left_face;
- EXECUTE sql;
+ sql := 'UPDATE ' || quote_ident(atopology)
+ || '.face SET mbr = $1 WHERE face_id = $2' ;
+ EXECUTE sql USING
+ ST_Envelope(ST_GetFaceGeometry(atopology, oldedge.left_face)),
+ oldedge.left_face
+ ;
END IF;
IF oldedge.right_face != 0 AND oldedge.right_face != oldedge.left_face THEN
- sql := 'UPDATE ' || quote_ident(atopology) || '.face '
- || ' SET mbr = ' || quote_literal(
- ST_Envelope(ST_GetFaceGeometry(atopology, oldedge.right_face))::text
- )
- || '::geometry WHERE face_id = ' || oldedge.right_face;
- EXECUTE sql;
+ sql := 'UPDATE ' || quote_ident(atopology)
+ || '.face SET mbr = $1 WHERE face_id = $2';
+ EXECUTE sql USING
+ ST_Envelope(ST_GetFaceGeometry(atopology, oldedge.right_face)),
+ oldedge.right_face
+ ;
END IF;
RAISE DEBUG 'Edge % splitted face %', anedge, oface;
#endif
- sql := 'WITH ids as ( select row_number() over () as seq, edge from unnest('
- || quote_literal(fan.newring_edges::text)
- || '::int[] ) u(edge) ), edges AS ( select CASE WHEN i.edge < 0 THEN ST_Reverse(e.geom) ELSE e.geom END as g FROM ids i left join '
- || quote_ident(atopology) || '.edge_data e ON(e.edge_id = abs(i.edge)) ORDER BY seq) SELECT ST_MakePolygon(ST_MakeLine(g.g)) FROM edges g;';
+ sql := 'WITH ids as ( select row_number() over () as seq, edge '
+ || 'from unnest($1) u(edge) ), edges AS ( select CASE WHEN i.edge < 0 '
+ || 'THEN ST_Reverse(e.geom) ELSE e.geom END as g FROM ids i left join '
+ || quote_ident(atopology) || '.edge_data e ON(e.edge_id = abs(i.edge)) '
+ || 'ORDER BY seq) SELECT ST_MakePolygon(ST_MakeLine(g.g)) FROM edges g';
#ifdef POSTGIS_TOPOLOGY_DEBUG
RAISE DEBUG '%', sql;
#endif
- EXECUTE sql INTO fan.shell;
+ EXECUTE sql INTO fan.shell USING
+ fan.newring_edges
+ ;
#ifdef POSTGIS_TOPOLOGY_DEBUG
RAISE DEBUG 'got shell';
-- Update old face mbr (nothing to do if we're opening an hole)
IF isccw THEN -- {
sql := 'UPDATE '
- || quote_ident(atopology) || '.face SET mbr = '
- || quote_literal(ST_Envelope(fan.shell)::text)
- || '::geometry WHERE face_id = ' || oface;
+ || quote_ident(atopology)
+ || '.face SET mbr = $1 WHERE face_id = $2';
#ifdef POSTGIS_TOPOLOGY_DEBUG
RAISE DEBUG 'Updating old face mbr';
#endif
- EXECUTE sql;
+ EXECUTE sql USING
+ ST_Envelope(fan.shell),
+ oface
+ ;
END IF; -- }
RETURN NULL;
END IF;
|| ' RETURNING face_id';
ELSE
sql := 'INSERT INTO '
- || quote_ident(atopology) || '.face(mbr) VALUES ('
- || quote_literal(ST_Envelope(fan.shell)::text)
- || '::geometry) RETURNING face_id';
+ || quote_ident(atopology) || '.face(mbr) VALUES ($1) RETURNING face_id';
END IF; -- }
-- Insert new face
#ifdef POSTGIS_TOPOLOGY_DEBUG
RAISE DEBUG 'Inserting new face';
#endif
- EXECUTE sql INTO STRICT newface;
+ EXECUTE sql INTO STRICT newface USING ST_Envelope(fan.shell);
-- Update forward edges
sql := 'UPDATE '
)::text )
|| ') AND ';
IF ishole THEN sql := sql || 'NOT '; END IF;
- sql := sql || '( ' || quote_literal(fan.shell::text)
- || ' && geom AND _ST_Contains(' || quote_literal(fan.shell::text)
+ sql := sql || '($1 && geom AND _ST_Contains($1'
-- We only need to check a single point, but must not be an endpoint
- || '::geometry, ST_LineInterpolatePoint(geom, 0.2)) )';
+ || ', ST_LineInterpolatePoint(geom, 0.2)) )';
#ifdef POSTGIS_TOPOLOGY_DEBUG
RAISE DEBUG 'Updating edges bounding the old face: %', sql;
#endif
- EXECUTE sql;
+ EXECUTE sql USING fan.shell;
-- Update isolated nodes in new new face
sql := 'UPDATE '
|| ' WHERE containing_face = ' || oface
|| ' AND ';
IF ishole THEN sql := sql || 'NOT '; END IF;
- sql := sql || 'ST_Contains(' || quote_literal(fan.shell::text) || '::geometry, geom)';
+ sql := sql || 'ST_Contains($1, geom)';
#ifdef POSTGIS_TOPOLOGY_DEBUG
RAISE DEBUG 'Updating isolated nodes in old face';
#endif
- EXECUTE sql;
+ EXECUTE sql USING fan.shell;
RETURN newface;
-- Check if this geometry crosses any node
--
FOR rec IN EXECUTE
- 'SELECT node_id, ST_Relate(geom, '
- || quote_literal(acurve::text) || '::geometry, 2) as relate FROM '
+ 'SELECT node_id, ST_Relate(geom, $1, 2) as relate FROM '
|| quote_ident(atopology)
- || '.node WHERE geom && '
- || quote_literal(acurve::text)
- || '::geometry'
+ || '.node WHERE geom && $1'
+ USING acurve
LOOP
IF ST_RelateMatch(rec.relate, 'T********') THEN
RAISE EXCEPTION 'SQL/MM Spatial exception - geometry crosses a node';
--
-- Check if this geometry has any interaction with any existing edge
--
- FOR rec IN EXECUTE 'SELECT edge_id, ST_Relate(geom,'
- || quote_literal(acurve::text)
- || '::geometry, 2) as im FROM '
+ FOR rec IN EXECUTE 'SELECT edge_id, ST_Relate(geom, $1, 2) as im FROM '
|| quote_ident(atopology)
- || '.edge_data WHERE geom && '
- || quote_literal(acurve::text) || '::geometry'
+ || '.edge_data WHERE geom && $1'
+ USING acurve
LOOP
--RAISE DEBUG 'IM=%',rec.im;
IF newedge.isclosed THEN
sql := sql || ' UNION SELECT '
|| newedge.edge_id || ',' || newedge.end_node
- || ',-1,0,0,' -- pretend we start elsewhere
- || quote_literal(newedge.cleangeom::text);
+ || ',-1,0,0,$1'; -- pretend we start elsewhere
END IF;
i := 0;
- FOR rec IN EXECUTE sql
+ FOR rec IN EXECUTE sql USING newedge.cleangeom
LOOP -- incident edges {
i := i + 1;
IF newedge.isclosed THEN
sql := sql || ' UNION SELECT '
|| newedge.edge_id || ',' || -1 -- pretend we end elsewhere
- || ',' || newedge.start_node || ',0,0,'
- || quote_literal(newedge.cleangeom::text);
+ || ',' || newedge.start_node || ',0,0,$1';
END IF;
i := 0;
- FOR rec IN EXECUTE sql
+ FOR rec IN EXECUTE sql USING newedge.cleangeom
LOOP -- incident edges {
i := i + 1;
|| ',' || newedge.next_right_edge
|| ',' || newedge.left_face
|| ',' || newedge.right_face
- || ',' || quote_literal(newedge.geom::geometry::text)
- || ')';
+ || ',$1)'
+ USING newedge.geom
+ ;
-- Link prev_left_edge to us
-- (if it's not us already)
-- Check if this geometry crosses any node
--
FOR rec IN EXECUTE
- 'SELECT node_id, ST_Relate(geom, '
- || quote_literal(acurve::text) || '::geometry, 2) as relate FROM '
+ 'SELECT node_id, ST_Relate(geom, $1, 2) as relate FROM '
|| quote_ident(atopology)
- || '.node WHERE geom && '
- || quote_literal(acurve::text)
- || '::geometry'
+ || '.node WHERE geom && $1'
+ USING acurve
LOOP
IF ST_RelateMatch(rec.relate, 'T********') THEN
RAISE EXCEPTION 'SQL/MM Spatial exception - geometry crosses a node';
--
-- Check if this geometry has any interaction with any existing edge
--
- FOR rec IN EXECUTE 'SELECT edge_id, ST_Relate(geom,'
- || quote_literal(acurve::text)
- || '::geometry, 2) as im FROM '
+ FOR rec IN EXECUTE 'SELECT edge_id, ST_Relate(geom, $1, 2) as im FROM '
|| quote_ident(atopology)
- || '.edge_data WHERE geom && '
- || quote_literal(acurve::text) || '::geometry'
+ || '.edge_data WHERE geom && $1'
+ USING acurve
LOOP
--RAISE DEBUG 'IM=%',rec.im;
|| ',' || newedge.next_right_edge
|| ',' || newedge.left_face
|| ',' || newedge.right_face
- || ',' || quote_literal(newedge.geom::geometry::text)
- || ')';
+ || ',$1)'
+ USING newedge.geom
+ ;
-- Link prev_left_edge to us
-- (if it's not us already)