changeset 2425:4c16f5ad1905

Make area generation more robust Valid geometries can become invalid geometries during transformation e.g. due to very small 'minimum clearance' (see PostGIS docs) and numerical inaccuracy of the transformation. Thus, try to repair polygons of the input area after transformation and calculate the union of the result polygons before transformation to avoid 'TopologyException' in the union operations. The simulated waterway area of the changed axis in the test data is affected here, but real waterway area data with complex shore lines could likely be affected, too.
author Tom Gottfried <tom@intevation.de>
date Thu, 28 Feb 2019 16:36:49 +0100
parents b6deb03ef13f
children 53323f701cf3
files schema/isrs_functions.sql schema/tap_tests_data.sql
diffstat 2 files changed, 5 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/schema/isrs_functions.sql	Thu Feb 28 16:02:56 2019 +0100
+++ b/schema/isrs_functions.sql	Thu Feb 28 16:36:49 2019 +0100
@@ -78,8 +78,9 @@
             -- polygons, which intersect with the axis. The union is to avoid
             -- problems with invalid/self-intersecting multipolygons
             SELECT ST_Union(a_dmp.geom) AS area
-                FROM axis_substring, utm_zone,
-                    ST_Dump(ST_Transform(area, z)) AS a_dmp
+                FROM axis_substring, utm_zone, LATERAL (
+                    SELECT ST_MakeValid(ST_Transform(geom, z)) AS geom
+                        FROM ST_Dump(area)) AS a_dmp
                 WHERE ST_Intersects(a_dmp.geom, axis_substring.line)
             ),
         rotated_ends AS (
@@ -102,7 +103,7 @@
                 FROM area_subset, rotated_ends)
         -- From the polygons returned by the last CTE, select only those
         -- around the clipped axis
-        SELECT ST_Multi(ST_Union(ST_Transform(range_area.geom, ST_SRID(area))))
+        SELECT ST_Multi(ST_Transform(ST_Union(range_area.geom), ST_SRID(area)))
             FROM axis_substring, range_area
             WHERE ST_Intersects(ST_Buffer(range_area.geom, -0.0001),
                 axis_substring.line)
--- a/schema/tap_tests_data.sql	Thu Feb 28 16:02:56 2019 +0100
+++ b/schema/tap_tests_data.sql	Thu Feb 28 16:36:49 2019 +0100
@@ -84,9 +84,7 @@
         4326),
     'testriver'
 ), (
-    ST_SetSRID(ST_CurveToLine(
-        'CIRCULARSTRING(0.6 0.4, 1 0, 2 0)'),
-        4326),
+    ST_SetSRID(ST_CurveToLine('CIRCULARSTRING(0.6 0.4, 1 0, 1.5 0)'), 4326),
     'testriver'
 ), (
     ST_SetSRID('LINESTRING(0.5 0.5, 1 1)'::geometry, 4326),