diff pkg/imports/fm_boysaw.go @ 4940:b3b2ba09a450 fairway-marks-import

Add missing fairway mark types
author Tom Gottfried <tom@intevation.de>
date Mon, 17 Feb 2020 18:38:45 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pkg/imports/fm_boysaw.go	Mon Feb 17 18:38:45 2020 +0100
@@ -0,0 +1,159 @@
+// This is Free Software under GNU Affero General Public License v >= 3.0
+// without warranty, see README.md and license for details.
+//
+// SPDX-License-Identifier: AGPL-3.0-or-later
+// License-Filename: LICENSES/AGPL-3.0.txt
+//
+// Copyright (C) 2020 by via donau
+//   – Österreichische Wasserstraßen-Gesellschaft mbH
+// Software engineering by Intevation GmbH
+//
+// Author(s):
+//  * Tom Gottfried <tom.gottfried@intevation.de>
+
+package imports
+
+import (
+	"context"
+	"database/sql"
+
+	"gemma.intevation.de/gemma/pkg/pgxutils"
+)
+
+// Boysaw is an import job to import
+// fairway marks of type BOYSAW in form of point geometries
+// and attribute data from a WFS service.
+type Boysaw struct {
+	FairwayMarks
+}
+
+// Description gives a short info about relevant facts of this import.
+func (boysaw *Boysaw) Description() (string, error) {
+	return boysaw.URL + "|" + boysaw.FeatureType, nil
+}
+
+// BOYSAWJobKind is the import queue type identifier.
+const BOYSAWJobKind JobKind = "fm_boysaw"
+
+type boysawJobCreator struct{}
+
+func init() {
+	RegisterJobCreator(BOYSAWJobKind, boysawJobCreator{})
+}
+
+func (boysawJobCreator) Description() string { return "fairway marks boysaw" }
+
+func (boysawJobCreator) AutoAccept() bool { return true }
+
+func (boysawJobCreator) Create() Job { return new(Boysaw) }
+
+func (boysawJobCreator) Depends() [2][]string {
+	return [2][]string{
+		{"fairway_marks_boysaw"},
+		{},
+	}
+}
+
+// StageDone is a NOP for fairway marks imports.
+func (boysawJobCreator) StageDone(context.Context, *sql.Tx, int64) error {
+	return nil
+}
+
+// CleanUp for fairway marks imports is a NOP.
+func (*Boysaw) CleanUp() error { return nil }
+
+type boysawProperties struct {
+	fairwayMarksProperties
+	Colour *string `json:"hydro_colour"`
+	Colpat *string `json:"hydro_colpat"`
+	Conrad *int    `json:"hydro_conrad"`
+	Marsys *int64  `json:"hydro_marsys"`
+	Boyshp *int    `json:"hydro_boyshp"`
+}
+
+type boysawFeaturetype struct {
+	geom  pointSlice
+	props *boysawProperties
+}
+
+// Do executes the actual import.
+func (fm *Boysaw) Do(
+	ctx context.Context,
+	importID int64,
+	conn *sql.Conn,
+	feedback Feedback,
+) (interface{}, error) {
+
+	err := getFMFeatures(
+		ctx,
+		conn,
+		feedback,
+		fm.FairwayMarks,
+		func() interface{} { return new(boysawProperties) },
+		func(p pointSlice, props interface{}) interface{} {
+			return &boysawFeaturetype{p, props.(*boysawProperties)}
+		},
+		func(
+			tx *sql.Tx, epsg int, fms []interface{},
+		) (outsideOrDup int, features int, err error) {
+
+			feedback.Info("Store fairway marks of type BOYSAW")
+
+			insertStmt, err := tx.PrepareContext(
+				ctx,
+				getFMInsertSQL("boysaw",
+					"colour", "colpat", "conrad", "marsys", "boyshp"),
+			)
+			if err != nil {
+				return
+			}
+			defer insertStmt.Close()
+
+			savepoint := Savepoint(ctx, tx, "feature")
+
+			for _, fm := range fms {
+
+				f := fm.(*boysawFeaturetype)
+
+				var fmid int64
+				err := savepoint(func() error {
+					err := insertStmt.QueryRowContext(
+						ctx,
+						f.geom.asWKB(),
+						epsg,
+						f.props.Datsta,
+						f.props.Datend,
+						f.props.Persta,
+						f.props.Perend,
+						f.props.Objnam,
+						f.props.Nobjnm,
+						f.props.Inform,
+						f.props.Ninfom,
+						f.props.Scamin,
+						f.props.Picrep,
+						f.props.Txtdsc,
+						f.props.Sordat,
+						f.props.Sorind,
+						f.props.Colour,
+						f.props.Colpat,
+						f.props.Conrad,
+						f.props.Marsys,
+						f.props.Boyshp,
+					).Scan(&fmid)
+					return err
+				})
+				switch {
+				case err == sql.ErrNoRows:
+					outsideOrDup++
+					// ignore -> filtered by responsibility_areas
+				case err != nil:
+					feedback.Error(pgxutils.ReadableError{Err: err}.Error())
+				default:
+					features++
+				}
+			}
+			return
+		})
+
+	return nil, err
+}