# HG changeset patch # User Sascha L. Teichmann # Date 1625577980 -7200 # Node ID 850f5847d18a9e990da4d9a8dbc5cd37c98f1bd6 # Parent 6d73836bc2fb5be76e35323d4cd0c261b2a4a2fa Re-establish compat with old single-beam interface. diff -r 6d73836bc2fb -r 850f5847d18a pkg/controllers/srimports.go --- 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) { diff -r 6d73836bc2fb -r 850f5847d18a pkg/imports/sr.go --- 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 } diff -r 6d73836bc2fb -r 850f5847d18a pkg/models/sr.go --- 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 }