changeset 5407:850f5847d18a marking-single-beam

Re-establish compat with old single-beam interface.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 06 Jul 2021 15:26:20 +0200
parents 6d73836bc2fb
children 901b70f9c6bd
files pkg/controllers/srimports.go pkg/imports/sr.go pkg/models/sr.go
diffstat 3 files changed, 58 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/controllers/srimports.go	Tue Jul 06 14:26:02 2021 +0200
+++ b/pkg/controllers/srimports.go	Tue Jul 06 15:26:20 2021 +0200
@@ -112,6 +112,20 @@
 		sr.NegateZ = &negateZ
 	}
 
+	// Kept this in for compat.
+	if v := req.FormValue("single-beam"); v != "" {
+		var surveyType models.SurveyType
+		switch strings.ToLower(v) {
+		case "true", "1", "singlebeam", "single-beam":
+			surveyType = models.SurveyTypeSingleBeam
+		case "false", "0", "multibeam", "multi-beam":
+			surveyType = models.SurveyTypeMultiBeam
+		default:
+			return fmt.Errorf("unknown single-beam '%s'", v)
+		}
+		sr.SurveyType = &surveyType
+	}
+
 	if v := req.FormValue("survey-type"); v != "" {
 		var surveyType models.SurveyType
 		switch strings.ToLower(v) {
--- a/pkg/imports/sr.go	Tue Jul 06 14:26:02 2021 +0200
+++ b/pkg/imports/sr.go	Tue Jul 06 15:26:20 2021 +0200
@@ -58,6 +58,8 @@
 	// DepthReference if given overides the DepthReference value
 	// from the meta.json.
 	DepthReference *string `json:"depth-reference,omitempty"`
+	// SingleBeam is kept in for compat.
+	SingleBeam *bool `json:"single-beam,omitempty"`
 	// SurveyType indicates that the sounding is a single beam scan.
 	SurveyType *models.SurveyType `json:"survey-type,omitempty"`
 	// NegateZ indicated that the Z values of thy XYZ input should be
@@ -237,6 +239,9 @@
 	if sr.NegateZ != nil && *sr.NegateZ {
 		descs = append(descs, "negateZ")
 	}
+	if sr.surveyType != nil {
+		descs = append(descs, string(*sr.SurveyType))
+	}
 	return strings.Join(descs, "|"), nil
 }
 
@@ -757,6 +762,16 @@
 	if sr.DepthReference != nil {
 		m.DepthReference = *sr.DepthReference
 	}
+
+	// Kept in for compat
+	if sr.SingleBeam != nil {
+		if *sr.SingleBeam {
+			m.SurveyType = models.SurveyTypeSingleBeam
+		} else {
+			m.SurveyType = models.SurveyTypeSingleBeam
+		}
+	}
+
 	if sr.SurveyType != nil {
 		m.SurveyType = *sr.SurveyType
 	}
--- a/pkg/models/sr.go	Tue Jul 06 14:26:02 2021 +0200
+++ b/pkg/models/sr.go	Tue Jul 06 15:26:20 2021 +0200
@@ -39,7 +39,8 @@
 		Bottleneck     string     `json:"bottleneck"`
 		EPSG           uint       `json:"epsg"`
 		DepthReference string     `json:"depth-reference"`
-		SurveyType     SurveyType `json:"survey-type"`
+		SingleBeam     *bool      `json:"single-beam,omitempty"` // kept in for compat!
+		SurveyType     SurveyType `json:"survey-type,omitempty"`
 		NegateZ        bool       `json:"negate-z,omitempty"`
 	}
 )
@@ -80,9 +81,35 @@
 
 func (m *SoundingResultMeta) Decode(r io.Reader) error {
 	err := json.NewDecoder(r).Decode(m)
-	if err == nil && m.EPSG == 0 {
+	if err != nil {
+		return err
+	}
+
+	if m.EPSG == 0 {
 		m.EPSG = WGS84
 	}
+
+	if m.SingleBeam != nil {
+		// Check if single-beam and survey-type match.
+		if m.SurveyType != "" {
+			if (*m.SingleBeam && m.SurveyType != SurveyTypeSingleBeam) ||
+				(!*m.SingleBeam && m.SurveyType != SurveyTypeMultiBeam) {
+				return errors.New("'single-beam' and 'survey-type' mismatch")
+			}
+		} else { // Only single-beam given
+			if *m.SingleBeam {
+				m.SurveyType = SurveyTypeSingleBeam
+			} else {
+				m.SurveyType = SurveyTypeMultiBeam
+			}
+		}
+		// Kill single-beam
+		m.SingleBeam = nil
+	}
+
+	if m.SurveyType == "" { // default to multi-beam
+		m.SurveyType = SurveyTypeMultiBeam
+	}
 	return err
 }