diff pkg/imports/sr.go @ 983:f4f5bd73bd27

Default to WGS84 if EPSG is not given in meta.json. Also fixed SQL checks.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 19 Oct 2018 15:45:55 +0200
parents 7934b5c1a910
children 3c9ea8ab856a
line wrap: on
line diff
--- a/pkg/imports/sr.go	Fri Oct 19 14:17:16 2018 +0200
+++ b/pkg/imports/sr.go	Fri Oct 19 15:45:55 2018 +0200
@@ -42,12 +42,20 @@
 	}
 )
 
+const wgs84 = 4326
+
 const (
 	contourStepWidth = 0.5
 	contourTolerance = 0.1
 )
 
 const (
+	checkDepthReferenceSQL = `
+SELECT true FROM depth_references WHERE depth_reference = $1`
+
+	checkBottleneckSQL = `
+SELECT true FROM waterway.bottlenecks WHERE objnam = $1`
+
 	insertPointsSQL = `
 INSERT INTO waterway.sounding_results (
   bottleneck_id,
@@ -154,6 +162,11 @@
 	defer r.Close()
 	var m SoundingResultMeta
 	err = json.NewDecoder(r).Decode(&m)
+	if err == nil {
+		if m.EPSG == 0 {
+			m.EPSG = wgs84
+		}
+	}
 	return &m, err
 }
 
@@ -161,7 +174,7 @@
 
 	var b bool
 	err := conn.QueryRowContext(context.Background(),
-		`SELECT true FROM internal.depth_references WHERE depth_reference = $1`,
+		checkDepthReferenceSQL,
 		m.DepthReference).Scan(&b)
 	switch {
 	case err == sql.ErrNoRows:
@@ -173,7 +186,7 @@
 	}
 
 	err = conn.QueryRowContext(context.Background(),
-		`SELECT true FROM waterway.bottlenecks WHERE objnam = $1`,
+		checkBottleneckSQL,
 		m.Bottleneck).Scan(&b)
 	switch {
 	case err == sql.ErrNoRows: