[postgis-tickets] [SCM] PostGIS branch main updated. 3.1.0rc1-287-g1674bd6

git at osgeo.org git at osgeo.org
Thu Jul 8 06:16:48 PDT 2021


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".

The branch, main has been updated
       via  1674bd635c2a82c67de074f095fd6241f4cc70fb (commit)
      from  ce90fc77c3b3bd673ef30829bc8205a683e47390 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 1674bd635c2a82c67de074f095fd6241f4cc70fb
Author: Sandro Santilli <strk at kbt.io>
Date:   Thu Jul 8 15:16:32 2021 +0200

    Move edge-linking checking code in its own function

diff --git a/topology/sql/manage/ValidateTopology.sql.in b/topology/sql/manage/ValidateTopology.sql.in
index 81f4572..a6b119c 100644
--- a/topology/sql/manage/ValidateTopology.sql.in
+++ b/topology/sql/manage/ValidateTopology.sql.in
@@ -62,7 +62,155 @@ END;
 $BODY$
 LANGUAGE 'plpgsql' IMMUTABLE STRICT;
 
+--
+-- Check that the edges incident to topology nodes
+-- (as advertised by their start_node/end_node)
+-- correctly link to the next incident node on each
+-- side (CW and CCW)
+--
+-- NOTE: if start_node/end_node values are incorrect the behavior
+--       of this function is undefined
+--
+-- NOTE: assumes search_path was set before calling this function
+--
+CREATE OR REPLACE FUNCTION topology._ValidateTopologyEdgeLinking(bbox geometry DEFAULT NULL)
+RETURNS SETOF topology.ValidateTopology_ReturnType
+AS --{
+$BODY$
+DECLARE
+  retrec topology.ValidateTopology_ReturnType;
+  rec RECORD;
+  last_node_id int;
+  last_node_first_edge RECORD;
+  last_node_prev_edge RECORD;
+BEGIN
+  RAISE DEBUG 'Checking edge linking';
+  -- NOTE: this check relies on correct start_node and end_node
+  --       for edges, if those are not correct the results
+  --       of this check do not make much sense.
+  FOR rec IN --{
+      WITH
+      nodes AS (
+        SELECT node_id
+        FROM node
+        WHERE containing_face IS NULL
+        AND (
+          bbox IS NULL
+          OR geom && bbox
+        )
+      ),
+      incident_edges AS (
+        SELECT
+          n.node_id,
+          e.edge_id,
+          e.start_node,
+          e.end_node,
+          e.next_left_edge,
+          e.next_right_edge,
+          ST_RemoveRepeatedPoints(e.geom) as edge_geom
+        FROM edge_data e, nodes n
+        WHERE e.start_node = n.node_id
+        or e.end_node = n.node_id
+      ),
+      edge_star AS (
+        SELECT
+          node_id,
+          edge_id,
+          next_left_edge,
+          next_right_edge,
+          ST_Azimuth(ST_StartPoint(edge_geom), ST_PointN(edge_geom, 2)) as az
+        FROM incident_edges
+        WHERE start_node = node_id
+          UNION ALL
+        SELECT
+          node_id,
+          -edge_id,
+          next_left_edge,
+          next_right_edge,
+          ST_Azimuth(ST_EndPoint(edge_geom), ST_PointN(edge_geom, ST_NumPoints(edge_geom)-1))
+        FROM incident_edges
+        WHERE end_node = node_id
+      ),
+      sequenced_edge_star AS (
+        SELECT
+          row_number() over (partition by node_id order by az, edge_id) seq,
+          *
+        FROM edge_star
+      )
+      SELECT * FROM sequenced_edge_star
+      ORDER BY node_id, seq
+  LOOP --}{
+    IF last_node_id IS NULL OR last_node_id != rec.node_id
+    THEN --{
+      IF last_node_id IS NOT NULL
+      THEN
+        -- Check that last edge (CW from prev one) is correctly linked
+        retrec := topology._CheckEdgeLinking(
+          last_node_first_edge.edge_id,
+          last_node_prev_edge.edge_id,
+          last_node_prev_edge.next_left_edge,
+          last_node_prev_edge.next_right_edge
+        );
+        IF retrec IS NOT NULL
+        THEN
+          RETURN NEXT retrec;
+        END IF;
+        --RAISE DEBUG 'Finished analisys of edge star around node %', last_node_id;
+      END IF;
+      --RAISE DEBUG 'Analyzing edge star around node %', rec.node_id;
+      last_node_id = rec.node_id;
+      last_node_first_edge = rec;
+    ELSE --}{
+      -- Check that this edge (CW from last one) is correctly linked
+      retrec := topology._CheckEdgeLinking(
+        rec.edge_id,
+        last_node_prev_edge.edge_id,
+        last_node_prev_edge.next_left_edge,
+        last_node_prev_edge.next_right_edge
+      );
+      IF retrec IS NOT NULL
+      THEN
+        RETURN NEXT retrec;
+      END IF;
+    END IF; --}
+    last_node_prev_edge = rec;
+  END LOOP; --}
+  IF last_node_id IS NOT NULL THEN --{
+    --RAISE DEBUG 'Out of loop: last_node_id: %', last_node_id;
+    --RAISE DEBUG 'Out of loop: last_node_first_edge edge_id:% next_left_edge:%', last_node_first_edge.edge_id, last_node_first_edge.next_left_edge;
+    --RAISE DEBUG 'Out of loop: last_node_prev_edge edge_id:% next_left_edge:%', last_node_prev_edge.edge_id, last_node_prev_edge.next_left_edge;
+    --RAISE DEBUG 'Out of loop: last_node_first_edge: %', last_node_first_edge;
+    -- Check that last edge (CW from prev one) is correctly linked
+    retrec := topology._CheckEdgeLinking(
+      last_node_first_edge.edge_id,
+      last_node_prev_edge.edge_id,
+      last_node_prev_edge.next_left_edge,
+      last_node_prev_edge.next_right_edge
+      );
+    IF retrec IS NOT NULL
+    THEN
+      RETURN NEXT retrec;
+    END IF;
+    --RAISE DEBUG 'Finished analisys of edge star around node % (out of loop)', last_node_id;
+  END IF; --}
+
+
+END;
+$BODY$ --}
+LANGUAGE 'plpgsql' VOLATILE;
+
+--
+-- Check that the edges forming all rings
+-- (as advertised by their next_right_edge/next_left_edge)
+-- consistently advertise the same face on the walking side
+-- (CW or CCW)
+--
+-- NOTE: if next_right_edge/next_left_edge values are incorrect
+--       the behavior of this function is undefined, use
+--       _ValidateTopologyEdgeLinking to verify that
+--
 -- NOTE: assumes search_path was set before calling this function
+--
 CREATE OR REPLACE FUNCTION topology._ValidateTopologySideLabeling(bbox geometry DEFAULT NULL)
 RETURNS SETOF topology.ValidateTopology_ReturnType
 AS --{
@@ -243,9 +391,6 @@ DECLARE
   invalid_edges integer[];
   invalid_faces integer[];
   search_path_backup text;
-  last_node_id int;
-  last_node_first_edge RECORD;
-  last_node_prev_edge RECORD;
 BEGIN
 
   IF NOT EXISTS (
@@ -520,122 +665,12 @@ BEGIN
     RETURN NEXT retrec;
   END LOOP; --}
 
-  RAISE DEBUG 'Checking edge linking';
-  -- NOTE: this check relies on correct start_node and end_node
-  --       for edges, if those are not correct the results
-  --       of this check do not make much sense.
-  FOR rec IN --{
-      WITH
-      nodes AS (
-        SELECT node_id
-        FROM node
-        WHERE containing_face IS NULL
-        AND (
-          bbox IS NULL
-          OR geom && bbox
-        )
-      ),
-      incident_edges AS (
-        SELECT
-          n.node_id,
-          e.edge_id,
-          e.start_node,
-          e.end_node,
-          e.next_left_edge,
-          e.next_right_edge,
-          ST_RemoveRepeatedPoints(e.geom) as edge_geom
-        FROM edge_data e, nodes n
-        WHERE e.start_node = n.node_id
-        or e.end_node = n.node_id
-      ),
-      edge_star AS (
-        SELECT
-          node_id,
-          edge_id,
-          next_left_edge,
-          next_right_edge,
-          ST_Azimuth(ST_StartPoint(edge_geom), ST_PointN(edge_geom, 2)) as az
-        FROM incident_edges
-        WHERE start_node = node_id
-          UNION ALL
-        SELECT
-          node_id,
-          -edge_id,
-          next_left_edge,
-          next_right_edge,
-          ST_Azimuth(ST_EndPoint(edge_geom), ST_PointN(edge_geom, ST_NumPoints(edge_geom)-1))
-        FROM incident_edges
-        WHERE end_node = node_id
-      ),
-      sequenced_edge_star AS (
-        SELECT
-          row_number() over (partition by node_id order by az, edge_id) seq,
-          *
-        FROM edge_star
-      )
-      SELECT * FROM sequenced_edge_star
-      ORDER BY node_id, seq
-  LOOP --}{
-    IF last_node_id IS NULL OR last_node_id != rec.node_id
-    THEN --{
-      IF last_node_id IS NOT NULL
-      THEN
-        -- Check that last edge (CW from prev one) is correctly linked
-        retrec := topology._CheckEdgeLinking(
-          last_node_first_edge.edge_id,
-          last_node_prev_edge.edge_id,
-          last_node_prev_edge.next_left_edge,
-          last_node_prev_edge.next_right_edge
-        );
-        IF retrec IS NOT NULL
-        THEN
-          RETURN NEXT retrec;
-        END IF;
-        --RAISE DEBUG 'Finished analisys of edge star around node %', last_node_id;
-      END IF;
-      --RAISE DEBUG 'Analyzing edge star around node %', rec.node_id;
-      last_node_id = rec.node_id;
-      last_node_first_edge = rec;
-    ELSE --}{
-      -- Check that this edge (CW from last one) is correctly linked
-      retrec := topology._CheckEdgeLinking(
-        rec.edge_id,
-        last_node_prev_edge.edge_id,
-        last_node_prev_edge.next_left_edge,
-        last_node_prev_edge.next_right_edge
-      );
-      IF retrec IS NOT NULL
-      THEN
-        RETURN NEXT retrec;
-      END IF;
-    END IF; --}
-    last_node_prev_edge = rec;
-  END LOOP; --}
-  IF last_node_id IS NOT NULL THEN --{
-    --RAISE DEBUG 'Out of loop: last_node_id: %', last_node_id;
-    --RAISE DEBUG 'Out of loop: last_node_first_edge edge_id:% next_left_edge:%', last_node_first_edge.edge_id, last_node_first_edge.next_left_edge;
-    --RAISE DEBUG 'Out of loop: last_node_prev_edge edge_id:% next_left_edge:%', last_node_prev_edge.edge_id, last_node_prev_edge.next_left_edge;
-    --RAISE DEBUG 'Out of loop: last_node_first_edge: %', last_node_first_edge;
-    -- Check that last edge (CW from prev one) is correctly linked
-    retrec := topology._CheckEdgeLinking(
-      last_node_first_edge.edge_id,
-      last_node_prev_edge.edge_id,
-      last_node_prev_edge.next_left_edge,
-      last_node_prev_edge.next_right_edge
-      );
-    IF retrec IS NOT NULL
-    THEN
-      RETURN NEXT retrec;
-    END IF;
-    --RAISE DEBUG 'Finished analisys of edge star around node % (out of loop)', last_node_id;
-  END IF; --}
-
-  --- Edge side-labeling check -------------------------------------------{
+  --- Validate edge linking
+  RETURN QUERY SELECT * FROM topology._ValidateTopologyEdgeLinking(bbox);
 
+  --- Validate side-labeling
   RETURN QUERY SELECT * FROM topology._ValidateTopologySideLabeling(bbox);
 
-  --- Edge side-labeling check -------------------------------------------}
-
 
   -- Now create a temporary table to construct all face geometries
   -- for checking their consistency

-----------------------------------------------------------------------

Summary of changes:
 topology/sql/manage/ValidateTopology.sql.in | 267 ++++++++++++++++------------
 1 file changed, 151 insertions(+), 116 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list