From: Sandro Santilli Date: Tue, 24 May 2011 14:47:00 +0000 (+0000) Subject: Allow dumping universal face edges with ST_GetFaceEdges. Do it in the correct order... X-Git-Tag: 2.0.0alpha1~1577 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7eecd1dbefc44c7101151a4f9fca78beb9356742;p=postgis Allow dumping universal face edges with ST_GetFaceEdges. Do it in the correct order. Fixes bug #984. [RT-SIGTA] git-svn-id: http://svn.osgeo.org/postgis/trunk@7236 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/topology/sql/sqlmm.sql b/topology/sql/sqlmm.sql index 23f4908a6..d00b31767 100644 --- a/topology/sql/sqlmm.sql +++ b/topology/sql/sqlmm.sql @@ -46,6 +46,7 @@ DECLARE bounds geometry; retrec topology.GetFaceEdges_ReturnType; n int; + sql TEXT; BEGIN -- -- toponame and face_id are required @@ -61,16 +62,18 @@ BEGIN n := 1; -- Construct the face geometry, then for each polygon: - FOR rec IN SELECT (ST_DumpRings((ST_Dump(ST_ForceRHR( - topology.ST_GetFaceGeometry(toponame, face_id)))).geom)).* + sql := 'SELECT (ST_DumpRings((ST_Dump(ST_ForceRHR(' + || 'ST_BuildArea(ST_Collect(geom))))).geom)).* FROM ' + || quote_ident(toponame) || '.edge_data WHERE left_face = ' + || face_id || ' OR right_face = ' || face_id; + FOR rec IN EXECUTE sql LOOP -- { -- Contents of a directed face are the list of edges -- that cover the specific ring bounds = ST_Boundary(rec.geom); - FOR rec IN EXECUTE - 'SELECT e.*, ST_Line_Locate_Point(' + sql := 'SELECT e.*, ST_Line_Locate_Point(' || quote_literal(bounds::text) || ', ST_Line_Interpolate_Point(e.geom, 0.2)) as pos' || ', ST_Line_Locate_Point(' @@ -81,16 +84,31 @@ BEGIN || ' OR e.right_face = ' || face_id || ') AND ST_Covers(' || quote_literal(bounds::text) - || ', e.geom) ORDER BY pos DESC' + || ', e.geom)'; + IF face_id = 0 THEN + sql := sql || ' ORDER BY pos ASC'; + ELSE + sql := sql || ' ORDER BY POS DESC'; + END IF; + + FOR rec IN EXECUTE sql LOOP retrec.sequence = n; retrec.edge = rec.edge_id; - -- if this edge goes in same direction to the - -- ring bounds, make it with negative orientation - IF rec.pos2 > rec.pos THEN -- edge goes in same direction - retrec.edge = -retrec.edge; + IF face_id = 0 THEN + -- if this edge goes in opposite direction to the + -- ring bounds, make it with negative orientation + IF rec.pos2 < rec.pos THEN -- edge goes in opposite direction + retrec.edge = -retrec.edge; + END IF; + ELSE + -- if this edge goes in same direction to the + -- ring bounds, make it with negative orientation + IF rec.pos2 > rec.pos THEN -- edge goes in same direction + retrec.edge = -retrec.edge; + END IF; END IF; RETURN NEXT retrec; @@ -101,6 +119,9 @@ BEGIN END LOOP; -- } RETURN; +EXCEPTION + WHEN INVALID_SCHEMA_NAME THEN + RAISE EXCEPTION 'SQL/MM Spatial exception - invalid topology name'; END $$ LANGUAGE 'plpgsql' VOLATILE; diff --git a/topology/test/regress/st_getfaceedges.sql b/topology/test/regress/st_getfaceedges.sql index 6398bcd12..2927d79c3 100644 --- a/topology/test/regress/st_getfaceedges.sql +++ b/topology/test/regress/st_getfaceedges.sql @@ -26,5 +26,7 @@ SELECT 'F' || SELECT 'F1', (topology.ST_GetFaceEdges('tt', 1)).*; SELECT 'F2', (topology.ST_GetFaceEdges('tt', 2)).*; +SELECT 'F0', (topology.ST_GetFaceEdges('tt', 0)).*; + SELECT topology.DropTopology('tt'); diff --git a/topology/test/regress/st_getfaceedges_expected b/topology/test/regress/st_getfaceedges_expected index f95751d8d..e91b40b4f 100644 --- a/topology/test/regress/st_getfaceedges_expected +++ b/topology/test/regress/st_getfaceedges_expected @@ -23,4 +23,8 @@ F1|7|3 F2|1|-3 F2|2|-2 F2|3|-1 +F0|1|-5 +F0|2|4 +F0|3|6 +F0|4|-7 Topology 'tt' dropped