# HG changeset patch # User Sascha L. Teichmann # Date 1625527244 -7200 # Node ID 85f19e924a43a78f130924898707f9becf81c88d # Parent f5063fa7f666478d577744ea30b8a0103163125d Adjusted the import model to be able to handle marking single beam scans. diff -r f5063fa7f666 -r 85f19e924a43 pkg/controllers/srimports.go --- a/pkg/controllers/srimports.go Tue Jul 06 00:30:39 2021 +0200 +++ b/pkg/controllers/srimports.go Tue Jul 06 01:20:44 2021 +0200 @@ -112,17 +112,19 @@ sr.NegateZ = &negateZ } - if v := req.FormValue("single-beam"); v != "" { - var singleBeam bool + if v := req.FormValue("survey-type"); v != "" { + var surveyType models.SurveyType switch strings.ToLower(v) { - case "true", "1", "singlebeam", "single-beam": - singleBeam = true - case "false", "0", "multibeam", "multi-beam": - singleBeam = false + case "2", "marking": + surveyType = models.SurveyTypeMarking + case "true", "1", "singlebeam", "single-beam", "single": + surveyType = models.SurveyTypeSingleBeam + case "false", "0", "multibeam", "multi-beam", "multi": + surveyType = models.SurveyTypeMultiBeam default: - return fmt.Errorf("unknown single-beam '%s'", v) + return fmt.Errorf("unknown survey-type '%s'", v) } - sr.SingleBeam = &singleBeam + sr.SurveyType = &surveyType } return nil diff -r f5063fa7f666 -r 85f19e924a43 pkg/imports/sr.go --- a/pkg/imports/sr.go Tue Jul 06 00:30:39 2021 +0200 +++ b/pkg/imports/sr.go Tue Jul 06 01:20:44 2021 +0200 @@ -58,8 +58,8 @@ // DepthReference if given overides the DepthReference value // from the meta.json. DepthReference *string `json:"depth-reference,omitempty"` - // SingleBeam indicates that the sounding is a single beam scan. - 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 // multiplied by -1. NegateZ *bool `json:"negate-z,omitempty"` @@ -240,15 +240,15 @@ return strings.Join(descs, "|"), nil } -func (sr *SoundingResult) singleBeam() bool { - return sr.SingleBeam != nil && *sr.SingleBeam +func (sr *SoundingResult) surveyType() models.SurveyType { + if sr.SurveyType != nil { + return *sr.SurveyType + } + return models.SurveyTypeMultiBeam } func (sr *SoundingResult) surtype() string { - if sr.singleBeam() { - return "single" - } - return "multi" + return string(sr.surveyType()) } func (sr *SoundingResult) negateZ() bool { @@ -419,11 +419,7 @@ zpgException bool, ) (interface{}, error) { - if sr.singleBeam() { - feedback.Info("Processing as single beam scan.") - } else { - feedback.Info("Processing as multi beam scan.") - } + feedback.Info("Processing as %s beam scan.", sr.surtype()) feedback.Info("Reproject XYZ data.") @@ -532,7 +528,12 @@ removed = str.Clip(&clippingPolygon) } - if sr.singleBeam() { + switch sr.surveyType() { + case models.SurveyTypeMarking: + // TODO: Implement me! + return nil, errors.New("Not implemented, yet!") + + case models.SurveyTypeSingleBeam: origDensity := float64(len(xyz)) / polygonArea @@ -712,7 +713,7 @@ return sr.Bottleneck != nil && sr.Date != nil && sr.DepthReference != nil && - sr.SingleBeam != nil && + sr.SurveyType != nil && sr.NegateZ != nil } @@ -729,7 +730,7 @@ Bottleneck: *sr.Bottleneck, EPSG: epsg, DepthReference: *sr.DepthReference, - SingleBeam: sr.singleBeam(), + SurveyType: sr.surveyType(), NegateZ: sr.negateZ(), }, nil } @@ -756,8 +757,8 @@ if sr.DepthReference != nil { m.DepthReference = *sr.DepthReference } - if sr.SingleBeam != nil { - m.SingleBeam = *sr.SingleBeam + if sr.SurveyType != nil { + m.SurveyType = *sr.SurveyType } if sr.NegateZ != nil { m.NegateZ = *sr.NegateZ diff -r f5063fa7f666 -r 85f19e924a43 pkg/models/sr.go --- a/pkg/models/sr.go Tue Jul 06 00:30:39 2021 +0200 +++ b/pkg/models/sr.go Tue Jul 06 01:20:44 2021 +0200 @@ -25,17 +25,39 @@ "gemma.intevation.de/gemma/pkg/common" ) +type SurveyType string + +const ( + SurveyTypeMultiBeam = SurveyType("multi") + SurveyTypeSingleBeam = SurveyType("single") + SurveyTypeMarking = SurveyType("marking") +) + type ( SoundingResultMeta struct { - Date Date `json:"date"` - Bottleneck string `json:"bottleneck"` - EPSG uint `json:"epsg"` - DepthReference string `json:"depth-reference"` - SingleBeam bool `json:"single-beam"` - NegateZ bool `json:"negate-z,omitempty"` + Date Date `json:"date"` + Bottleneck string `json:"bottleneck"` + EPSG uint `json:"epsg"` + DepthReference string `json:"depth-reference"` + SurveyType SurveyType `json:"survey-type"` + NegateZ bool `json:"negate-z,omitempty"` } ) +func (st *SurveyType) UnmarshalJSON(data []byte) error { + var s string + if err := json.Unmarshal(data, &s); err != nil { + return err + } + switch x := SurveyType(s); x { + case SurveyTypeMultiBeam, SurveyTypeSingleBeam, SurveyTypeMarking: + *st = x + return nil + default: + return fmt.Errorf("unkown survey type '%s'", s) + } +} + const ( checkDepthReferenceSQL = ` SELECT EXISTS(SELECT 1