changeset 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 cffa99aa523c
files pkg/imports/sr.go
diffstat 1 files changed, 64 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/imports/sr.go	Tue Jun 04 11:26:05 2019 +0200
+++ b/pkg/imports/sr.go	Tue Jun 04 12:06:36 2019 +0200
@@ -188,7 +188,7 @@
 	feedback Feedback,
 ) (interface{}, error) {
 
-	begin := time.Now()
+	start := time.Now()
 
 	z, err := zip.OpenReader(filepath.Join(sr.Dir, "sr.zip"))
 	if err != nil {
@@ -256,14 +256,6 @@
 		return nil, errors.New("XYZ does not contain any vertices")
 	}
 
-	if sr.isSingleBeam() {
-		feedback.Info("Processing as single beam scan.")
-	} else {
-		feedback.Info("Processing as multi beam scan.")
-	}
-
-	// TODO: Implement single beam code path.
-
 	// Is there a boundary shapefile in the ZIP archive?
 	polygon, err := loadBoundary(z)
 	if err != nil {
@@ -276,6 +268,68 @@
 	}
 	defer tx.Rollback()
 
+	var summary interface{}
+
+	if sr.isSingleBeam() {
+		summary, err = sr.singleBeamScan(
+			ctx,
+			tx,
+			feedback,
+			importID,
+			m,
+			xyz,
+			polygon,
+		)
+	} else {
+		summary, err = sr.multiBeamScan(
+			ctx,
+			tx,
+			feedback,
+			importID,
+			m,
+			xyz,
+			polygon,
+		)
+	}
+	if err != nil {
+		return nil, err
+	}
+
+	if err = tx.Commit(); err != nil {
+		feedback.Error(
+			"Storing sounding result failed after %v.", time.Since(start))
+		return nil, err
+	}
+
+	feedback.Info(
+		"Storing sounding result was successful after %v.", time.Since(start))
+
+	return summary, nil
+}
+
+func (sr *SoundingResult) singleBeamScan(
+	ctx context.Context,
+	tx *sql.Tx,
+	feedback Feedback,
+	importID int64,
+	m *models.SoundingResultMeta,
+	xyz octree.MultiPointZ,
+	polygon polygonSlice,
+) (interface{}, error) {
+	// TODO: Implement me!
+	return nil, errors.New("Not implemented, yet!")
+}
+
+func (sr *SoundingResult) multiBeamScan(
+	ctx context.Context,
+	tx *sql.Tx,
+	feedback Feedback,
+	importID int64,
+	m *models.SoundingResultMeta,
+	xyz octree.MultiPointZ,
+	polygon polygonSlice,
+) (interface{}, error) {
+	feedback.Info("Processing as multi beam scan.")
 	var (
 		id       int64
 		epsg     uint32
@@ -287,7 +341,7 @@
 
 	xyzWKB := xyz.AsWKB()
 
-	err = tx.QueryRow(insertHullSQL,
+	err := tx.QueryRow(insertHullSQL,
 		m.Bottleneck,
 		m.Date.Time,
 		m.DepthReference,
@@ -395,15 +449,6 @@
 		return nil, err
 	}
 
-	if err = tx.Commit(); err != nil {
-		feedback.Error(
-			"Storing sounding result failed after %v.", time.Since(begin))
-		return nil, err
-	}
-
-	feedback.Info(
-		"Storing sounding result was successful after %v.", time.Since(begin))
-
 	summary := struct {
 		Bottleneck string      `json:"bottleneck"`
 		Date       models.Date `json:"date"`