Mercurial > gemma
annotate pkg/imports/fm_bcnlat.go @ 4907:644cb7c175f3 fairway-marks-import
Use proper type to represent featuretype
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Fri, 07 Feb 2020 19:38:48 +0100 |
parents | 8cb201b551b3 |
children | 52c31d3b5131 |
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 "errors" |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
20 "strconv" |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
21 "time" |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
22 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
23 "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
|
24 ) |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
25 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
26 // 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
|
27 // 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
|
28 // 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
|
29 type Bcnlat struct { |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
30 FairwayMarks |
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 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
33 // 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
|
34 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
|
35 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
|
36 } |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
37 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
38 // FMJobKind is the import queue type identifier. |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
39 const FMJobKind JobKind = "fm" |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
40 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
41 type bcnlatJobCreator struct{} |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
42 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
43 func init() { |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
44 RegisterJobCreator(FMJobKind, bcnlatJobCreator{}) |
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 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
47 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
|
48 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
49 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
|
50 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
51 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
|
52 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
53 func (bcnlatJobCreator) Depends() [2][]string { |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
54 return [2][]string{ |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
55 {"fairway_marks"}, |
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 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
60 // 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
|
61 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
|
62 return nil |
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 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
65 // 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
|
66 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
|
67 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
68 type bcnlatProperties struct { |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
69 fairwayMarksProperties |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
70 Colour *string `json:"hydro_colour"` |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
71 Colpat *string `json:"hydro_colpat"` |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
72 Condtn *int `json:"hydro_condtn"` |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
73 Bcnshp *int `json:"hydro_bcnshp"` |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
74 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
|
75 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
|
76 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
|
77 } |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
78 |
4907
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
79 type bcnlatFeaturetype struct { |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
80 geom pointSlice |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
81 props *bcnlatProperties |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
82 } |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
83 |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
84 const ( |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
85 insertBCNLATSQL = ` |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
86 with a as ( |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
87 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
|
88 ) |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
89 INSERT INTO waterway.fairway_marks ( |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
90 geom, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
91 datsta, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
92 datend, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
93 persta, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
94 perend, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
95 objnam, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
96 nobjnm, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
97 inform, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
98 ninfom, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
99 scamin, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
100 picrep, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
101 txtdsc, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
102 sordat, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
103 sorind, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
104 colour, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
105 colpat, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
106 condtn, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
107 bcnshp, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
108 catlam, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
109 dirimp |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
110 ) |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
111 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
|
112 $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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 ON CONFLICT ( |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
118 CAST((0, geom, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
119 datsta, datend, persta, perend, objnam, nobjnm, inform, ninfom, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
120 scamin, picrep, txtdsc, sordat, sorind, colour, colpat, condtn, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
121 bcnshp, catlam, dirimp) AS waterway.fairway_marks) |
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 { |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
234 err := errors.New("no valid new features found") |
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 } |