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