annotate pkg/imports/fm_boysaw.go @ 4945:97533bbfaa2d fairway-marks-import

Add missing fairway mark types to layer group
author Tom Gottfried <tom@intevation.de>
date Tue, 18 Feb 2020 13:00:25 +0100
parents b3b2ba09a450
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4940
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
1 // This is Free Software under GNU Affero General Public License v >= 3.0
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
2 // without warranty, see README.md and license for details.
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
3 //
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
4 // SPDX-License-Identifier: AGPL-3.0-or-later
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
5 // License-Filename: LICENSES/AGPL-3.0.txt
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
6 //
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
7 // Copyright (C) 2020 by via donau
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
8 // – Österreichische Wasserstraßen-Gesellschaft mbH
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
9 // Software engineering by Intevation GmbH
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
10 //
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
11 // Author(s):
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
12 // * Tom Gottfried <tom.gottfried@intevation.de>
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
13
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
14 package imports
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
15
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
16 import (
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
17 "context"
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
18 "database/sql"
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
19
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
20 "gemma.intevation.de/gemma/pkg/pgxutils"
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
21 )
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
22
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
23 // Boysaw is an import job to import
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
24 // fairway marks of type BOYSAW in form of point geometries
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
25 // and attribute data from a WFS service.
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
26 type Boysaw struct {
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
27 FairwayMarks
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
28 }
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
29
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
30 // Description gives a short info about relevant facts of this import.
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
31 func (boysaw *Boysaw) Description() (string, error) {
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
32 return boysaw.URL + "|" + boysaw.FeatureType, nil
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
33 }
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
34
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
35 // BOYSAWJobKind is the import queue type identifier.
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
36 const BOYSAWJobKind JobKind = "fm_boysaw"
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
37
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
38 type boysawJobCreator struct{}
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
39
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
40 func init() {
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
41 RegisterJobCreator(BOYSAWJobKind, boysawJobCreator{})
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
42 }
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
43
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
44 func (boysawJobCreator) Description() string { return "fairway marks boysaw" }
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
45
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
46 func (boysawJobCreator) AutoAccept() bool { return true }
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
47
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
48 func (boysawJobCreator) Create() Job { return new(Boysaw) }
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
49
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
50 func (boysawJobCreator) Depends() [2][]string {
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
51 return [2][]string{
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
52 {"fairway_marks_boysaw"},
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
53 {},
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
54 }
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
55 }
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
56
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
57 // StageDone is a NOP for fairway marks imports.
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
58 func (boysawJobCreator) StageDone(context.Context, *sql.Tx, int64) error {
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
59 return nil
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
60 }
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
61
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
62 // CleanUp for fairway marks imports is a NOP.
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
63 func (*Boysaw) CleanUp() error { return nil }
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
64
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
65 type boysawProperties struct {
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
66 fairwayMarksProperties
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
67 Colour *string `json:"hydro_colour"`
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
68 Colpat *string `json:"hydro_colpat"`
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
69 Conrad *int `json:"hydro_conrad"`
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
70 Marsys *int64 `json:"hydro_marsys"`
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
71 Boyshp *int `json:"hydro_boyshp"`
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
72 }
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
73
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
74 type boysawFeaturetype struct {
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
75 geom pointSlice
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
76 props *boysawProperties
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
77 }
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
78
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
79 // Do executes the actual import.
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
80 func (fm *Boysaw) Do(
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
81 ctx context.Context,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
82 importID int64,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
83 conn *sql.Conn,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
84 feedback Feedback,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
85 ) (interface{}, error) {
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
86
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
87 err := getFMFeatures(
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
88 ctx,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
89 conn,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
90 feedback,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
91 fm.FairwayMarks,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
92 func() interface{} { return new(boysawProperties) },
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
93 func(p pointSlice, props interface{}) interface{} {
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
94 return &boysawFeaturetype{p, props.(*boysawProperties)}
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
95 },
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
96 func(
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
97 tx *sql.Tx, epsg int, fms []interface{},
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
98 ) (outsideOrDup int, features int, err error) {
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
99
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
100 feedback.Info("Store fairway marks of type BOYSAW")
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
101
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
102 insertStmt, err := tx.PrepareContext(
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
103 ctx,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
104 getFMInsertSQL("boysaw",
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
105 "colour", "colpat", "conrad", "marsys", "boyshp"),
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
106 )
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
107 if err != nil {
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
108 return
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
109 }
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
110 defer insertStmt.Close()
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
111
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
112 savepoint := Savepoint(ctx, tx, "feature")
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
113
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
114 for _, fm := range fms {
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
115
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
116 f := fm.(*boysawFeaturetype)
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
117
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
118 var fmid int64
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
119 err := savepoint(func() error {
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
120 err := insertStmt.QueryRowContext(
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
121 ctx,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
122 f.geom.asWKB(),
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
123 epsg,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
124 f.props.Datsta,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
125 f.props.Datend,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
126 f.props.Persta,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
127 f.props.Perend,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
128 f.props.Objnam,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
129 f.props.Nobjnm,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
130 f.props.Inform,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
131 f.props.Ninfom,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
132 f.props.Scamin,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
133 f.props.Picrep,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
134 f.props.Txtdsc,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
135 f.props.Sordat,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
136 f.props.Sorind,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
137 f.props.Colour,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
138 f.props.Colpat,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
139 f.props.Conrad,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
140 f.props.Marsys,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
141 f.props.Boyshp,
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
142 ).Scan(&fmid)
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
143 return err
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
144 })
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
145 switch {
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
146 case err == sql.ErrNoRows:
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
147 outsideOrDup++
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
148 // ignore -> filtered by responsibility_areas
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
149 case err != nil:
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
150 feedback.Error(pgxutils.ReadableError{Err: err}.Error())
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
151 default:
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
152 features++
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
153 }
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
154 }
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
155 return
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
156 })
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
157
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
158 return nil, err
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
159 }