Make topology.AddEdge consistent with AddNode and AddFace in that it will return an existing identical Edge, if found.

git-svn-id: http://svn.osgeo.org/postgis/trunk@6724 b70326c6-7e19-0410-871a-916f4a2858ee
This commit is contained in:
Sandro Santilli 2011-01-25 09:39:50 +00:00
parent c9c88b971e
commit 6f385996bb
4 changed files with 16 additions and 9 deletions

View file

@ -533,7 +533,7 @@ face without edges | 0 |
<refnamediv>
<refname>AddEdge</refname>
<refpurpose>Adds a linestring edge to the edge table and associated start and end points to the point nodes table of the specified topology schema using the specified linestring geometry and returns the edgeid of the new edge.</refpurpose>
<refpurpose>Adds a linestring edge to the edge table and associated start and end points to the point nodes table of the specified topology schema using the specified linestring geometry and returns the edgeid of the new (or existing) edge.</refpurpose>
</refnamediv>
<refsynopsisdiv>
@ -549,9 +549,9 @@ face without edges | 0 |
<refsection>
<title>Description</title>
<para>Adds an edge to the edge table and associated nodes to the nodes table of the specified <varname>toponame</varname> schema using the specified linestring geometry and returns the edgeid of the new record.
<para>Adds an edge to the edge table and associated nodes to the nodes table of the specified <varname>toponame</varname> schema using the specified linestring geometry and returns the edgeid of the new or existing record.
The newly added edge has "universe" face on both sides and links to itself.</para>
<note><para>If the <varname>aline</varname> geometry crosses an existing linestring edge, or intersects an existing not at the endpoints, then an error is thrown and the edge is not added.</para></note>
<note><para>If the <varname>aline</varname> geometry crosses, overlaps, contains or is contained by an existing linestring edge, then an error is thrown and the edge is not added.</para></note>
<note><para>The geometry of <varname>aline</varname> must have the same <varname>srid</varname> as defined for the topology otherwise an invalid spatial reference sys error will be thrown.</para></note>

View file

@ -123,11 +123,10 @@ LANGUAGE 'plpgsql';
--
-- Add an edge primitive to a topology and get it's identifier.
-- Edge endpoints will be added as nodes if missing.
-- Returns an existing edge at the same location, if any.
--
-- An exception is raised if the given line crosses an existing
-- node or interects with an existing edge on anything but endnodes.
-- TODO: for symmetry with AddNode, it might be useful to return the
-- id of an equal existing edge (currently raising an exception)
--
-- The newly added edge has "universe" face on both sides
-- and links to itself.
@ -289,7 +288,11 @@ BEGIN
END IF;
END IF;
-- TODO: reuse an EQUAL edge ?
-- Reuse an EQUAL edge (be it closed or not)
IF ST_RelateMatch(rec.im, '1FFF*FFF2') THEN
RAISE DEBUG 'Edge already known as %', rec.edge_id;
RETURN rec.edge_id;
END IF;
RAISE EXCEPTION 'Edge intersects (not on endpoints) with existing edge % ', rec.edge_id;

View file

@ -3,11 +3,11 @@ set client_min_messages to WARNING;
SELECT topology.CreateTopology('tt') > 0;
SELECT 'e1', topology.addEdge('tt', 'LINESTRING(0 0, 8 0)');
-- Equal edge
SELECT 'e*1', topology.addEdge('tt', 'LINESTRING(0 0, 8 0)');
-- Failing cases (should all raise exceptions) -------
-- Equals [ TODO: turn this into a success ]
SELECT 'e*1', topology.addEdge('tt', 'LINESTRING(0 0, 8 0)');
-- Contained with endpoint contact
SELECT 'e*2', topology.addEdge('tt', 'LINESTRING(1 0, 8 0)');
-- Contained with no endpoint contact
@ -56,6 +56,9 @@ SELECT '#770-*', topology.addEdge('tt', 'LINESTRING(8 10, 7 13, 10 12, 8 12, 10
-- (not the existing edge endpoint)
SELECT '#770-*', topology.addEdge('tt', 'LINESTRING(10 12, 11 12, 10 13, 10 12)');
-- Another equals case, this time a closed edge
SELECT '#770-1*', topology.addEdge('tt', 'LINESTRING(8 10, 10 10, 10 12, 8 10)');
SELECT edge_id, left_face, right_face,
next_left_edge, next_right_edge,
st_astext(geom) from tt.edge ORDER by edge_id;

View file

@ -1,6 +1,6 @@
t
e1|1
ERROR: Edge intersects (not on endpoints) with existing edge 1
e*1|1
ERROR: Edge intersects (not on endpoints) with existing edge 1
ERROR: Edge intersects (not on endpoints) with existing edge 1
ERROR: Edge intersects (not on endpoints) with existing edge 1
@ -20,6 +20,7 @@ e6|6
ERROR: Edge intersects (not on endpoints) with existing edge 7
ERROR: Edge intersects (not on endpoints) with existing edge 7
ERROR: Edge intersects (not on endpoints) with existing edge 7
#770-1*|7
1|0|0|1|1|LINESTRING(0 0,8 0)
2|0|0|2|2|LINESTRING(8 0,8 10)
3|0|0|3|3|LINESTRING(0 0,0 10)