diff pkg/imports/wx.go @ 5009:e8b2dc771f9e

Store axis as MultiLinestring MultiLinestrings could already be imported but we stored them as multiple Linestrings with identical attributes and even stored Linestrings with self-intersections as multiple single Linestrings with identical attributes. Avoid both by storing as MultiLinestring. In passing, removed unnecessary processing steps in the INSERT statemet for the sys_admin case and ensured that attempts to convert to valid simple features are made after transformation, which might lead to invalid features. Since isrsrange_axis() relies on single Linestrings for linear referencing, add an extra ST_Dump().
author Tom Gottfried <tom@intevation.de>
date Wed, 11 Mar 2020 17:11:23 +0100
parents 783d0bec86d3
children 7dff1015283d
line wrap: on
line diff
--- a/pkg/imports/wx.go	Wed Mar 11 15:54:37 2020 +0100
+++ b/pkg/imports/wx.go	Wed Mar 11 17:11:23 2020 +0100
@@ -100,16 +100,18 @@
   SELECT users.current_user_area_utm() AS a
 )
 INSERT INTO waterway.waterway_axis (wtwaxs, objnam, nobjnam)
-SELECT dmp.geom, $3, $4
+SELECT
+    ST_Multi(ST_Node(ST_CollectionExtract(ST_Transform(new_ax, 4326), 2))),
+    $3, $4
   FROM ST_GeomFromWKB($1, $2::integer) AS new_line (new_line),
-    ST_Dump(ST_Transform(ST_CollectionExtract(
+    LATERAL (SELECT
       CASE WHEN pg_has_role('sys_admin', 'MEMBER')
-        THEN ST_Node(ST_Transform(new_line,
-          best_utm(ST_Transform(new_line, 4326))))
+        THEN new_line
         ELSE ST_Intersection((SELECT a FROM resp),
           ST_Node(ST_Transform(new_line, (SELECT ST_SRID(a) FROM resp))))
-        END,
-      2), 4326)) AS dmp
+        END) AS new_ax (new_ax)
+  -- Do nothing if intersection is empty:
+  WHERE NOT ST_IsEmpty(new_ax)
 RETURNING id
 `
 )
@@ -222,47 +224,34 @@
 				nobjnam = sql.NullString{String: *props.NObjNnm, Valid: true}
 			}
 
+			var ls multiLineSlice
 			switch feature.Geometry.Type {
 			case "LineString":
 				var l lineSlice
 				if err := json.Unmarshal(*feature.Geometry.Coordinates, &l); err != nil {
 					return err
 				}
-				if err := storeLinestring(
-					ctx,
-					savepoint,
-					feedback,
-					l,
-					epsg,
-					props,
-					nobjnam,
-					&outside,
-					&features,
-					insertStmt); err != nil {
-					return err
-				}
+				ls = append(ls, l)
 			case "MultiLineString":
-				var ls []lineSlice
 				if err := json.Unmarshal(*feature.Geometry.Coordinates, &ls); err != nil {
 					return err
 				}
-				for _, l := range ls {
-					if err := storeLinestring(
-						ctx,
-						savepoint,
-						feedback,
-						l,
-						epsg,
-						props,
-						nobjnam,
-						&outside,
-						&features,
-						insertStmt); err != nil {
-						return err
-					}
-				}
 			default:
 				unsupported[feature.Geometry.Type]++
+				continue
+			}
+			if err := storeLinestring(
+				ctx,
+				savepoint,
+				feedback,
+				ls,
+				epsg,
+				props,
+				nobjnam,
+				&outside,
+				&features,
+				insertStmt); err != nil {
+				return err
 			}
 		}
 		return nil
@@ -302,7 +291,7 @@
 	ctx context.Context,
 	savepoint func(func() error) error,
 	feedback Feedback,
-	l lineSlice,
+	l multiLineSlice,
 	epsg int,
 	props waterwayAxisProperties,
 	nobjnam sql.NullString,