Mercurial > gemma
comparison pkg/models/sr.go @ 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 | 85f19e924a43 |
children | 235cfce555b5 |
comparison
equal
deleted
inserted
replaced
5406:6d73836bc2fb | 5407:850f5847d18a |
---|---|
37 SoundingResultMeta struct { | 37 SoundingResultMeta struct { |
38 Date Date `json:"date"` | 38 Date Date `json:"date"` |
39 Bottleneck string `json:"bottleneck"` | 39 Bottleneck string `json:"bottleneck"` |
40 EPSG uint `json:"epsg"` | 40 EPSG uint `json:"epsg"` |
41 DepthReference string `json:"depth-reference"` | 41 DepthReference string `json:"depth-reference"` |
42 SurveyType SurveyType `json:"survey-type"` | 42 SingleBeam *bool `json:"single-beam,omitempty"` // kept in for compat! |
43 SurveyType SurveyType `json:"survey-type,omitempty"` | |
43 NegateZ bool `json:"negate-z,omitempty"` | 44 NegateZ bool `json:"negate-z,omitempty"` |
44 } | 45 } |
45 ) | 46 ) |
46 | 47 |
47 func (st *SurveyType) UnmarshalJSON(data []byte) error { | 48 func (st *SurveyType) UnmarshalJSON(data []byte) error { |
78 WHERE bn.objnam = $1 AND sr.date_info = $2` | 79 WHERE bn.objnam = $1 AND sr.date_info = $2` |
79 ) | 80 ) |
80 | 81 |
81 func (m *SoundingResultMeta) Decode(r io.Reader) error { | 82 func (m *SoundingResultMeta) Decode(r io.Reader) error { |
82 err := json.NewDecoder(r).Decode(m) | 83 err := json.NewDecoder(r).Decode(m) |
83 if err == nil && m.EPSG == 0 { | 84 if err != nil { |
85 return err | |
86 } | |
87 | |
88 if m.EPSG == 0 { | |
84 m.EPSG = WGS84 | 89 m.EPSG = WGS84 |
90 } | |
91 | |
92 if m.SingleBeam != nil { | |
93 // Check if single-beam and survey-type match. | |
94 if m.SurveyType != "" { | |
95 if (*m.SingleBeam && m.SurveyType != SurveyTypeSingleBeam) || | |
96 (!*m.SingleBeam && m.SurveyType != SurveyTypeMultiBeam) { | |
97 return errors.New("'single-beam' and 'survey-type' mismatch") | |
98 } | |
99 } else { // Only single-beam given | |
100 if *m.SingleBeam { | |
101 m.SurveyType = SurveyTypeSingleBeam | |
102 } else { | |
103 m.SurveyType = SurveyTypeMultiBeam | |
104 } | |
105 } | |
106 // Kill single-beam | |
107 m.SingleBeam = nil | |
108 } | |
109 | |
110 if m.SurveyType == "" { // default to multi-beam | |
111 m.SurveyType = SurveyTypeMultiBeam | |
85 } | 112 } |
86 return err | 113 return err |
87 } | 114 } |
88 | 115 |
89 func (m *SoundingResultMeta) Validate(ctx context.Context, conn *sql.Conn) []error { | 116 func (m *SoundingResultMeta) Validate(ctx context.Context, conn *sql.Conn) []error { |