Mercurial > gemma
annotate pkg/imports/fm_bcnlat.go @ 4911:bcb8b69e4358 fairway-marks-import
Type specific names for fairway marks import
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Mon, 10 Feb 2020 18:02:22 +0100 |
parents | 6f244b5eb716 |
children | bfd8ef836998 |
rev | line source |
---|---|
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
3 // |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
6 // |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2020 by via donau |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
10 // |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
12 // * Tom Gottfried <tom.gottfried@intevation.de> |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
13 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
14 package imports |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
15 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
16 import ( |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
17 "context" |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
18 "database/sql" |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
19 "strconv" |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
20 "time" |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
21 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
22 "gemma.intevation.de/gemma/pkg/pgxutils" |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
23 ) |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
24 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
25 // Bcnlat is an import job to import |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
26 // fairway marks of type BCNLAT in form of point geometries |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
27 // and attribute data from a WFS service. |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
28 type Bcnlat struct { |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
29 FairwayMarks |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
30 } |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
31 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
32 // Description gives a short info about relevant facts of this import. |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
33 func (bcnlat *Bcnlat) Description() (string, error) { |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
34 return bcnlat.URL + "|" + bcnlat.FeatureType, nil |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
35 } |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
36 |
4911
bcb8b69e4358
Type specific names for fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
4909
diff
changeset
|
37 // BCNLATJobKind is the import queue type identifier. |
bcb8b69e4358
Type specific names for fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
4909
diff
changeset
|
38 const BCNLATJobKind JobKind = "fm_bcnlat" |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
39 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
40 type bcnlatJobCreator struct{} |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
41 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
42 func init() { |
4911
bcb8b69e4358
Type specific names for fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
4909
diff
changeset
|
43 RegisterJobCreator(BCNLATJobKind, bcnlatJobCreator{}) |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
44 } |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
45 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
46 func (bcnlatJobCreator) Description() string { return "fairway marks bcnlat" } |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
47 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
48 func (bcnlatJobCreator) AutoAccept() bool { return true } |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
49 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
50 func (bcnlatJobCreator) Create() Job { return new(Bcnlat) } |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
51 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
52 func (bcnlatJobCreator) Depends() [2][]string { |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
53 return [2][]string{ |
4909
6f244b5eb716
Use table inheritance to define common fairway marks attributes
Tom Gottfried <tom@intevation.de>
parents:
4908
diff
changeset
|
54 {"fairway_marks_bcnlat"}, |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
55 {}, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
56 } |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
57 } |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
58 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
59 // StageDone is a NOP for fairway marks imports. |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
60 func (bcnlatJobCreator) StageDone(context.Context, *sql.Tx, int64) error { |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
61 return nil |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
62 } |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
63 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
64 // CleanUp for fairway marks imports is a NOP. |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
65 func (*Bcnlat) CleanUp() error { return nil } |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
66 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
67 type bcnlatProperties struct { |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
68 fairwayMarksProperties |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
69 Colour *string `json:"hydro_colour"` |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
70 Colpat *string `json:"hydro_colpat"` |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
71 Condtn *int `json:"hydro_condtn"` |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
72 Bcnshp *int `json:"hydro_bcnshp"` |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
73 HydroCatlam *int64 `json:"hydro_catlam,omitempty"` |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
74 IENCCatlam *int64 `json:"ienc_catlam,omitempty"` |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
75 Dirimp *string `json:"ienc_dirimp,omitempty"` |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
76 } |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
77 |
4907
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
78 type bcnlatFeaturetype struct { |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
79 geom pointSlice |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
80 props *bcnlatProperties |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
81 } |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
82 |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
83 const ( |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
84 insertBCNLATSQL = ` |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
85 with a as ( |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
86 select users.current_user_area_utm() AS a |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
87 ) |
4909
6f244b5eb716
Use table inheritance to define common fairway marks attributes
Tom Gottfried <tom@intevation.de>
parents:
4908
diff
changeset
|
88 INSERT INTO waterway.fairway_marks_bcnlat ( |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
89 geom, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
90 datsta, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
91 datend, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
92 persta, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
93 perend, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
94 objnam, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
95 nobjnm, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
96 inform, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
97 ninfom, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
98 scamin, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
99 picrep, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
100 txtdsc, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
101 sordat, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
102 sorind, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
103 colour, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
104 colpat, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
105 condtn, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
106 bcnshp, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
107 catlam, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
108 dirimp |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
109 ) |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
110 SELECT newfm, $3, $4, $5, $6, $7, $8, $9, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
111 $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
112 FROM ST_Transform(ST_GeomFromWKB($1, $2::integer), 4326) AS newfm (newfm) |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
113 WHERE pg_has_role('sys_admin', 'MEMBER') |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
114 OR ST_Intersects((select a from a), |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
115 ST_Transform(newfm, (select ST_SRID(a) from a))) |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
116 ON CONFLICT ( |
4909
6f244b5eb716
Use table inheritance to define common fairway marks attributes
Tom Gottfried <tom@intevation.de>
parents:
4908
diff
changeset
|
117 CAST((geom, |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
118 datsta, datend, persta, perend, objnam, nobjnm, inform, ninfom, |
4909
6f244b5eb716
Use table inheritance to define common fairway marks attributes
Tom Gottfried <tom@intevation.de>
parents:
4908
diff
changeset
|
119 scamin, picrep, txtdsc, sordat, sorind, |
6f244b5eb716
Use table inheritance to define common fairway marks attributes
Tom Gottfried <tom@intevation.de>
parents:
4908
diff
changeset
|
120 0, colour, colpat, condtn, bcnshp, catlam, dirimp |
6f244b5eb716
Use table inheritance to define common fairway marks attributes
Tom Gottfried <tom@intevation.de>
parents:
4908
diff
changeset
|
121 ) AS waterway.fairway_marks_bcnlat) |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
122 ) |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
123 DO NOTHING |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
124 RETURNING id |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
125 ` |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
126 ) |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
127 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
128 // Do executes the actual import. |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
129 func (fm *Bcnlat) Do( |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
130 ctx context.Context, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
131 importID int64, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
132 conn *sql.Conn, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
133 feedback Feedback, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
134 ) (interface{}, error) { |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
135 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
136 start := time.Now() |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
137 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
138 feedback.Info("Import fairway marks of type BCNLAT/bcnlat") |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
139 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
140 fms, epsg, err := getFMFeatures( |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
141 feedback, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
142 fm.FairwayMarks, |
4905
8cb201b551b3
Replace bogus usage of pointer for type intrusion
Tom Gottfried <tom@intevation.de>
parents:
4904
diff
changeset
|
143 func() interface{} { return new(bcnlatProperties) }, |
4907
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
144 func(p pointSlice, props interface{}) interface{} { |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
145 return &bcnlatFeaturetype{p, props.(*bcnlatProperties)} |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
146 }, |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
147 ) |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
148 if err != nil { |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
149 return nil, err |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
150 } |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
151 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
152 tx, err := conn.BeginTx(ctx, nil) |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
153 if err != nil { |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
154 return nil, err |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
155 } |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
156 defer tx.Rollback() |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
157 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
158 insertStmt, err := tx.PrepareContext(ctx, insertBCNLATSQL) |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
159 if err != nil { |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
160 return nil, err |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
161 } |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
162 defer insertStmt.Close() |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
163 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
164 savepoint := Savepoint(ctx, tx, "feature") |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
165 |
4907
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
166 var ( |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
167 outsideOrDup int |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
168 features int |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
169 ) |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
170 for _, fm := range fms { |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
171 |
4907
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
172 f := fm.(*bcnlatFeaturetype) |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
173 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
174 var catlam sql.NullInt64 |
4907
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
175 if f.props.HydroCatlam != nil { |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
176 catlam = sql.NullInt64{Int64: *f.props.HydroCatlam, Valid: true} |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
177 } else if f.props.IENCCatlam != nil { |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
178 catlam = sql.NullInt64{Int64: *f.props.IENCCatlam, Valid: true} |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
179 } |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
180 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
181 var dirimp sql.NullInt64 |
4907
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
182 if f.props.Dirimp != nil { |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
183 if value, err := strconv.ParseInt(*f.props.Dirimp, 10, 64); err == nil { |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
184 dirimp = sql.NullInt64{Int64: value, Valid: true} |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
185 } |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
186 } |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
187 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
188 var fmid int64 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
189 err := savepoint(func() error { |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
190 err := insertStmt.QueryRowContext( |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
191 ctx, |
4907
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
192 f.geom.asWKB(), |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
193 epsg, |
4907
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
194 f.props.Datsta, |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
195 f.props.Datend, |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
196 f.props.Persta, |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
197 f.props.Perend, |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
198 f.props.Objnam, |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
199 f.props.Nobjnm, |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
200 f.props.Inform, |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
201 f.props.Ninfom, |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
202 f.props.Scamin, |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
203 f.props.Picrep, |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
204 f.props.Txtdsc, |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
205 f.props.Sordat, |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
206 f.props.Sorind, |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
207 f.props.Colour, |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
208 f.props.Colpat, |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
209 f.props.Condtn, |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
210 f.props.Bcnshp, |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
211 catlam, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
212 dirimp, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
213 ).Scan(&fmid) |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
214 return err |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
215 }) |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
216 switch { |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
217 case err == sql.ErrNoRows: |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
218 outsideOrDup++ |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
219 // ignore -> filtered by responsibility_areas |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
220 case err != nil: |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
221 feedback.Error(pgxutils.ReadableError{Err: err}.Error()) |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
222 default: |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
223 features++ |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
224 } |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
225 } |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
226 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
227 if outsideOrDup > 0 { |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
228 feedback.Info( |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
229 "Features outside responsibility area and duplicates: %d", |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
230 outsideOrDup) |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
231 } |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
232 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
233 if features == 0 { |
4908
52c31d3b5131
Report properly if nothing changed
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
234 err := UnchangedError("no valid new features found") |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
235 return nil, err |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
236 } |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
237 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
238 if err = tx.Commit(); err == nil { |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
239 feedback.Info("Storing %d features took %s", |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
240 features, time.Since(start)) |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
241 } |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
242 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
243 return nil, err |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
244 } |