comparison pkg/imports/sr.go @ 3587:a9d140c7db8d

SR import: Prepare the separate code paths for single and multibeam scans.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 04 Jun 2019 12:06:36 +0200
parents b9adb0ea4c41
children 062dc9b54b86
comparison
equal deleted inserted replaced
3586:b9adb0ea4c41 3587:a9d140c7db8d
186 importID int64, 186 importID int64,
187 conn *sql.Conn, 187 conn *sql.Conn,
188 feedback Feedback, 188 feedback Feedback,
189 ) (interface{}, error) { 189 ) (interface{}, error) {
190 190
191 begin := time.Now() 191 start := time.Now()
192 192
193 z, err := zip.OpenReader(filepath.Join(sr.Dir, "sr.zip")) 193 z, err := zip.OpenReader(filepath.Join(sr.Dir, "sr.zip"))
194 if err != nil { 194 if err != nil {
195 return nil, err 195 return nil, err
196 } 196 }
254 254
255 if len(xyz) == 0 { 255 if len(xyz) == 0 {
256 return nil, errors.New("XYZ does not contain any vertices") 256 return nil, errors.New("XYZ does not contain any vertices")
257 } 257 }
258 258
259 if sr.isSingleBeam() {
260 feedback.Info("Processing as single beam scan.")
261 } else {
262 feedback.Info("Processing as multi beam scan.")
263 }
264
265 // TODO: Implement single beam code path.
266
267 // Is there a boundary shapefile in the ZIP archive? 259 // Is there a boundary shapefile in the ZIP archive?
268 polygon, err := loadBoundary(z) 260 polygon, err := loadBoundary(z)
269 if err != nil { 261 if err != nil {
270 return nil, err 262 return nil, err
271 } 263 }
274 if err != nil { 266 if err != nil {
275 return nil, err 267 return nil, err
276 } 268 }
277 defer tx.Rollback() 269 defer tx.Rollback()
278 270
271 var summary interface{}
272
273 if sr.isSingleBeam() {
274 summary, err = sr.singleBeamScan(
275 ctx,
276 tx,
277 feedback,
278 importID,
279 m,
280 xyz,
281 polygon,
282 )
283 } else {
284 summary, err = sr.multiBeamScan(
285 ctx,
286 tx,
287 feedback,
288 importID,
289 m,
290 xyz,
291 polygon,
292 )
293 }
294 if err != nil {
295 return nil, err
296 }
297
298 if err = tx.Commit(); err != nil {
299 feedback.Error(
300 "Storing sounding result failed after %v.", time.Since(start))
301 return nil, err
302 }
303
304 feedback.Info(
305 "Storing sounding result was successful after %v.", time.Since(start))
306
307 return summary, nil
308 }
309
310 func (sr *SoundingResult) singleBeamScan(
311 ctx context.Context,
312 tx *sql.Tx,
313 feedback Feedback,
314 importID int64,
315 m *models.SoundingResultMeta,
316 xyz octree.MultiPointZ,
317 polygon polygonSlice,
318 ) (interface{}, error) {
319 // TODO: Implement me!
320 return nil, errors.New("Not implemented, yet!")
321 }
322
323 func (sr *SoundingResult) multiBeamScan(
324 ctx context.Context,
325 tx *sql.Tx,
326 feedback Feedback,
327 importID int64,
328 m *models.SoundingResultMeta,
329 xyz octree.MultiPointZ,
330 polygon polygonSlice,
331 ) (interface{}, error) {
332 feedback.Info("Processing as multi beam scan.")
279 var ( 333 var (
280 id int64 334 id int64
281 epsg uint32 335 epsg uint32
282 lat, lon float64 336 lat, lon float64
283 ) 337 )
285 339
286 var hull []byte 340 var hull []byte
287 341
288 xyzWKB := xyz.AsWKB() 342 xyzWKB := xyz.AsWKB()
289 343
290 err = tx.QueryRow(insertHullSQL, 344 err := tx.QueryRow(insertHullSQL,
291 m.Bottleneck, 345 m.Bottleneck,
292 m.Date.Time, 346 m.Date.Time,
293 m.DepthReference, 347 m.DepthReference,
294 xyzWKB, 348 xyzWKB,
295 polygon.asWKB(), 349 polygon.asWKB(),
393 // Store for potential later removal. 447 // Store for potential later removal.
394 if err = track(ctx, tx, importID, "waterway.sounding_results", id); err != nil { 448 if err = track(ctx, tx, importID, "waterway.sounding_results", id); err != nil {
395 return nil, err 449 return nil, err
396 } 450 }
397 451
398 if err = tx.Commit(); err != nil {
399 feedback.Error(
400 "Storing sounding result failed after %v.", time.Since(begin))
401 return nil, err
402 }
403
404 feedback.Info(
405 "Storing sounding result was successful after %v.", time.Since(begin))
406
407 summary := struct { 452 summary := struct {
408 Bottleneck string `json:"bottleneck"` 453 Bottleneck string `json:"bottleneck"`
409 Date models.Date `json:"date"` 454 Date models.Date `json:"date"`
410 Lat float64 `json:"lat"` 455 Lat float64 `json:"lat"`
411 Lon float64 `json:"lon"` 456 Lon float64 `json:"lon"`