<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>
-- 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>
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 = '
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('
|| 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;