diff pkg/imports/sr.go @ 5305:1a565f8a935a zpg-exception

Adjusted Go code to establish ZPG exception during SR import.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 19 May 2021 17:26:02 +0200
parents 56c589f7435d
children 0e8fd0e5bf36
line wrap: on
line diff
--- a/pkg/imports/sr.go	Wed May 19 16:48:04 2021 +0200
+++ b/pkg/imports/sr.go	Wed May 19 17:26:02 2021 +0200
@@ -134,7 +134,8 @@
   date_info,
   depth_reference,
   area,
-  surtyp
+  surtyp,
+  zpg_exception
 ) SELECT
   bottleneck_id,
   $2::date,
@@ -145,7 +146,8 @@
     ELSE
       ST_MakeValid(ST_Transform(ST_GeomFromWKB($5, $6::integer), 4326))::geography
     END),
-  $7
+  $7,
+  $8
 FROM waterway.bottlenecks
 WHERE objnam = $1 AND validity @> CAST($2 AS timestamptz)
 RETURNING
@@ -207,6 +209,9 @@
   AND grwl.depth_reference like 'LDC%'
 `
 
+	selectZPGExceptionAllowedSQL = `
+SELECT country IN ('BG', 'RO') FROM users.list_users WHERE username = current_user`
+
 	reprojectPointsSingleBeamSQL = `
 SELECT
   ST_AsBinary(
@@ -294,6 +299,8 @@
 		xform = identityTransform
 	}
 
+	var zpgException bool
+
 	if m.DepthReference == "ZPG" {
 		feedback.Info("Found ZPG as reference system -> translating Z values to LDC")
 		var ldc float64
@@ -308,18 +315,28 @@
 		)
 		switch {
 		case err == sql.ErrNoRows:
-			return nil, errors.New("cannot load LDC value")
+			if err := conn.QueryRowContext(
+				ctx, selectZPGExceptionAllowedSQL).Scan(&zpgException); err != nil {
+				return nil, err
+			}
+			if !zpgException {
+				return nil, errors.New("cannot load LDC value")
+			}
+			feedback.Warn("Not LCD found, but ZPG exception granted")
+
 		case err != nil:
 			return nil, err
 		}
 
-		// LDC is cm. The data is in m.
-		ldc /= 100
-		xform = chainTransforms(
-			xform,
-			func(v mesh.Vertex) mesh.Vertex {
-				return mesh.Vertex{X: v.X, Y: v.Y, Z: v.Z + ldc}
-			})
+		if !zpgException {
+			// LDC is cm. The data is in m.
+			ldc /= 100
+			xform = chainTransforms(
+				xform,
+				func(v mesh.Vertex) mesh.Vertex {
+					return mesh.Vertex{X: v.X, Y: v.Y, Z: v.Z + ldc}
+				})
+		}
 		m.DepthReference = depthReference
 	}
 
@@ -372,6 +389,7 @@
 		m,
 		xyz,
 		boundary,
+		zpgException,
 	)
 	if err != nil {
 		return nil, err
@@ -397,6 +415,7 @@
 	m *models.SoundingResultMeta,
 	xyz mesh.MultiPointZ,
 	boundary polygonSlice,
+	zpgException bool,
 ) (interface{}, error) {
 
 	if sr.singleBeam() {
@@ -626,6 +645,7 @@
 		clippingPolygonWKB,
 		epsg,
 		sr.surtype(),
+		zpgException,
 	).Scan(
 		&id,
 		&lat,