]> granicus.if.org Git - postgis/commitdiff
Stricter ISO output from ST_GetEdgeFaces: start enumerating ring edges from the edge...
authorSandro Santilli <strk@keybit.net>
Mon, 11 Jul 2011 12:17:33 +0000 (12:17 +0000)
committerSandro Santilli <strk@keybit.net>
Mon, 11 Jul 2011 12:17:33 +0000 (12:17 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@7628 b70326c6-7e19-0410-871a-916f4a2858ee

doc/extras_topology.xml
topology/sql/sqlmm.sql
topology/test/regress/st_getfaceedges_expected

index bfc7d07afb197ad21b31fe2ec3096fc4b44b9b38..ce719768668cc96958d2622839c36621825e58c3 100644 (file)
@@ -1490,7 +1490,12 @@ ERROR:  Two or more faces found</programlisting>
                        <refsection>
                 <title>Description</title>
             
-                <para>Returns a set of ordered edges that bound <varname>aface</varname> includes the sequence order.  Each output consists of a sequence and edgeid</para>
+                <para>Returns a set of ordered edges that bound <varname>aface</varname> includes the sequence order.  Each output consists of a sequence and edgeid. Sequence numbers start with value 1.</para>
+
+               <para>
+Enumeration of each ring edges start from the edge with smallest identifier.
+               </para>
+
                 <!-- use this format if new function -->
                 <para>Availability: 2.0 </para>
                        <para>&sqlmm_compliant; SQL-MM 3 Topo-Geo and Topo-Net 3: Routine Details: X.3.5</para>
@@ -1505,13 +1510,13 @@ SELECT (topology.ST_GetFaceEdges('tt', 1)).*;
 -- result --
  sequence | edge
 ----------+------
-        1 |    5
-        2 |   -4
-        3 |   -6
-        4 |    7
-        5 |    3
+        1 |   -4
+        2 |    5
+        3 |    7
+        4 |   -6
+        5 |    1
         6 |    2
-        7 |    1
+        7 |    3
 (7 rows)
  
 </programlisting>
index 80585749e6f6ff2137e3ea97c036954627c1454d..66f2430c734abd4fca49e90b5f43c9314fd9e319 100644 (file)
@@ -61,7 +61,7 @@ BEGIN
 
   n := 1;
 
-  -- Construct the face geometry, then for each polygon:
+  -- Construct the face geometry, then for each ring of each polygon:
   sql := 'SELECT (ST_DumpRings((ST_Dump(ST_ForceRHR('
     || 'ST_BuildArea(ST_Collect(geom))))).geom)).* FROM '
     || quote_ident(toponame) || '.edge_data WHERE left_face = '
@@ -69,11 +69,14 @@ BEGIN
   FOR rec IN EXECUTE sql 
   LOOP -- {
 
-    -- Contents of a directed face are the list of edges
-    -- that cover the specific ring
+    -- Find the edges constituting its boundary
     bounds = ST_Boundary(rec.geom);
 
-    sql := 'SELECT e.*, ST_Line_Locate_Point('
+
+    sql := 'WITH er2 AS ( ' 
+      || 'WITH er AS ( SELECT ' 
+      || 'min(e.edge_id) over (), count(*) over () as cnt, e.edge_id, '
+      || 'ST_Line_Locate_Point('
       || quote_literal(bounds::text)
       || ', ST_Line_Interpolate_Point(e.geom, 0.2)) as pos'
       || ', ST_Line_Locate_Point('
@@ -86,14 +89,24 @@ BEGIN
       || quote_literal(bounds::text)
       || ', e.geom)';
     IF face_id = 0 THEN
-      sql := sql || ' ORDER BY pos ASC';
+      sql := sql || ' ORDER BY POS ASC) ';
     ELSE
-      sql := sql || ' ORDER BY POS DESC';
+      sql := sql || ' ORDER BY POS DESC';
     END IF;
 
+    -- Reorder rows so to start with the one with smaller edge_id
+    sql := sql || 'SELECT row_number() over () - 1 as rn, * FROM er ) '
+               || 'SELECT *, ( rn + cnt - ( select rn FROM er2 WHERE edge_id = min ) ) % cnt AS reord FROM er2 ORDER BY reord';
+
+
+    --RAISE DEBUG 'SQL: %', sql;
+
     FOR rec IN EXECUTE sql
     LOOP
 
+      RAISE DEBUG 'rn:%, n:%, edg:%, cnt:%, min:%, reord:%',
+         rec.rn, n, rec.edge_id, rec.cnt, rec.min, rec.reord;
+
       retrec.sequence = n;
       retrec.edge = rec.edge_id;
 
index e91b40b4f7e64a3a2f5c1a0a5a4207d340dc4ce4..556a240e441f573f02a24a11fca2b0c9ec779150 100644 (file)
@@ -13,18 +13,18 @@ E6
 E7
 F1
 F2
-F1|1|7
-F1|2|-6
-F1|3|-4
-F1|4|5
+F1|1|-4
+F1|2|5
+F1|3|7
+F1|4|-6
 F1|5|1
 F1|6|2
 F1|7|3
-F2|1|-3
-F2|2|-2
-F2|3|-1
-F0|1|-5
-F0|2|4
-F0|3|6
-F0|4|-7
+F2|1|-1
+F2|2|-3
+F2|3|-2
+F0|1|4
+F0|2|6
+F0|3|-7
+F0|4|-5
 Topology 'tt' dropped