Mercurial > gemma
annotate pkg/imports/fm.go @ 4933:45ef039cf4a8 fairway-marks-import
grant select rights to sys_admin to new group layers tables.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sat, 15 Feb 2020 19:08:02 +0100 |
parents | e41d42be0e13 |
children | 9f9d72a1d398 |
rev | line source |
---|---|
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
3 // |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
6 // |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2020 by via donau |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
10 // |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
12 // * Tom Gottfried <tom.gottfried@intevation.de> |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
13 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
14 package imports |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
15 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
16 import ( |
4931
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
17 "context" |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
18 "database/sql" |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
19 "encoding/json" |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
20 "fmt" |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
21 "io" |
4931
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
22 "time" |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
23 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
24 "gemma.intevation.de/gemma/pkg/wfs" |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
25 ) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
26 |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
27 // FairwayMarks is a struct |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
28 // to be used as the basis for imports of |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
29 // specific types for fairway marks. |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
30 type FairwayMarks struct { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
31 // URL the GetCapabilities URL of the WFS service. |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
32 URL string `json:"url"` |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
33 // FeatureType selects the feature type of the WFS service. |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
34 FeatureType string `json:"feature-type"` |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
35 // SortBy works around misconfigured services to |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
36 // establish a sort order to get the features. |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
37 SortBy string `json:"sort-by"` |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
38 // User is an optional username for Basic Auth. |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
39 User string `json:"user,omitempty"` |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
40 // Password is an optional password for Basic Auth. |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
41 Password string `json:"password,omitempty"` |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
42 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
43 |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
44 // Properties common to all types of fairway marks |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
45 type fairwayMarksProperties struct { |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
46 Datsta *string `json:"hydro_datsta"` |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
47 Datend *string `json:"hydro_datend"` |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
48 Persta *string `json:"hydro_persta"` |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
49 Perend *string `json:"hydro_perend"` |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
50 Objnam *string `json:"hydro_objnam"` |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
51 Nobjnm *string `json:"hydro_nobjnm"` |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
52 Inform *string `json:"hydro_inform"` |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
53 Ninfom *string `json:"hydro_ninfom"` |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
54 Scamin *int `json:"hydro_scamin"` |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
55 Picrep *string `json:"hydro_picrep"` |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
56 Txtdsc *string `json:"hydro_txtdsc"` |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
57 Sordat *string `json:"hydro_sordat"` |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
58 Sorind *string `json:"hydro_sorind"` |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
59 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
60 |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
61 // Common operation of FM imports to get features from WFS service |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
62 func getFMFeatures( |
4931
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
63 ctx context.Context, |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
64 conn *sql.Conn, |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
65 feedback Feedback, |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
66 fm FairwayMarks, |
4906
21fea90f4002
Avoid unnecessary pointer to pointer
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
67 // Constructor returning pointer to struct |
21fea90f4002
Avoid unnecessary pointer to pointer
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
68 // representing featuretype's properties |
4905
8cb201b551b3
Replace bogus usage of pointer for type intrusion
Tom Gottfried <tom@intevation.de>
parents:
4904
diff
changeset
|
69 newProps func() interface{}, |
4907
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4906
diff
changeset
|
70 // Construct pointer to featuretype from given pointSlice and properties |
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4906
diff
changeset
|
71 newFeat func(pointSlice, interface{}) interface{}, |
4931
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
72 // Store features in type specific database tables |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
73 storeFMs func( |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
74 tx *sql.Tx, |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
75 epsg int, |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
76 // Slice of features to be converted to featuretypes type |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
77 fms []interface{}, |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
78 ) (outsideOrDup int, features int, err error), |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
79 ) (err error) { |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
80 |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
81 start := time.Now() |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
82 |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
83 feedback.Info("Import fairway marks") |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
84 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
85 feedback.Info("Loading capabilities from %s", fm.URL) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
86 caps, err := wfs.GetCapabilities(fm.URL) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
87 if err != nil { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
88 feedback.Error("Loading capabilities failed: %v", err) |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
89 return |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
90 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
91 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
92 ft := caps.FindFeatureType(fm.FeatureType) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
93 if ft == nil { |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
94 err = fmt.Errorf("unknown feature type '%s'", fm.FeatureType) |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
95 return |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
96 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
97 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
98 feedback.Info("Found feature type '%s", fm.FeatureType) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
99 |
4931
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
100 epsg, err := wfs.CRSToEPSG(ft.DefaultCRS) |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
101 if err != nil { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
102 feedback.Error("Unsupported CRS: '%s'", ft.DefaultCRS) |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
103 return |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
104 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
105 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
106 if fm.SortBy != "" { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
107 feedback.Info("Features will be sorted by '%s'", fm.SortBy) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
108 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
109 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
110 dl, err := wfs.GetFeatures(caps, fm.FeatureType, fm.SortBy) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
111 if err != nil { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
112 feedback.Error("Cannot create GetFeature URLs. %v", err) |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
113 return |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
114 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
115 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
116 var ( |
4931
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
117 fms []interface{} |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
118 unsupported = stringCounter{} |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
119 missingProperties int |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
120 badProperties int |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
121 ) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
122 |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
123 err = dl.Download(fm.User, fm.Password, func(url string, r io.Reader) error { |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
124 feedback.Info("Get features from: '%s'", url) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
125 rfc, err := wfs.ParseRawFeatureCollection(r) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
126 if err != nil { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
127 return fmt.Errorf("parsing GetFeature document failed: %v", err) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
128 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
129 if rfc.CRS != nil { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
130 crsName := rfc.CRS.Properties.Name |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
131 if epsg, err = wfs.CRSToEPSG(crsName); err != nil { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
132 feedback.Error("Unsupported CRS: %d", crsName) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
133 return err |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
134 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
135 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
136 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
137 // No features -> ignore. |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
138 if rfc.Features == nil { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
139 return nil |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
140 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
141 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
142 feedback.Info("Using EPSG: %d", epsg) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
143 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
144 for _, feature := range rfc.Features { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
145 if feature.Properties == nil || feature.Geometry.Coordinates == nil { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
146 missingProperties++ |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
147 continue |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
148 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
149 |
4905
8cb201b551b3
Replace bogus usage of pointer for type intrusion
Tom Gottfried <tom@intevation.de>
parents:
4904
diff
changeset
|
150 props := newProps() |
4906
21fea90f4002
Avoid unnecessary pointer to pointer
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
151 if err := json.Unmarshal(*feature.Properties, props); err != nil { |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
152 badProperties++ |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
153 continue |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
154 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
155 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
156 switch feature.Geometry.Type { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
157 case "Point": |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
158 var p pointSlice |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
159 if err := json.Unmarshal(*feature.Geometry.Coordinates, &p); err != nil { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
160 return err |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
161 } |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
162 |
4907
644cb7c175f3
Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents:
4906
diff
changeset
|
163 f := newFeat(p, props) |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
164 fms = append(fms, f) |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
165 default: |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
166 unsupported[feature.Geometry.Type]++ |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
167 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
168 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
169 return nil |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
170 }) |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
171 if err != nil { |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
172 return |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
173 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
174 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
175 if badProperties > 0 { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
176 feedback.Warn("Bad properties: %d", badProperties) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
177 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
178 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
179 if missingProperties > 0 { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
180 feedback.Warn("Missing properties: %d", missingProperties) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
181 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
182 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
183 if len(unsupported) != 0 { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
184 feedback.Warn("Unsupported types found: %s", unsupported) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
185 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
186 |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
187 feedback.Info("Found %d usable features in data source", len(fms)) |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
188 |
4931
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
189 tx, err := conn.BeginTx(ctx, nil) |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
190 if err != nil { |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
191 return |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
192 } |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
193 defer tx.Rollback() |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
194 |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
195 outsideOrDup, features, err := storeFMs(tx, epsg, fms) |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
196 if err != nil { |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
197 return |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
198 } |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
199 |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
200 if outsideOrDup > 0 { |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
201 feedback.Info( |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
202 "Features outside responsibility area and duplicates: %d", |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
203 outsideOrDup) |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
204 } |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
205 |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
206 if features == 0 { |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
207 return UnchangedError("no valid new features found") |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
208 } |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
209 |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
210 if err = tx.Commit(); err == nil { |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
211 feedback.Info("Storing %d features took %s", |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
212 features, time.Since(start)) |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
213 } |
e41d42be0e13
One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents:
4907
diff
changeset
|
214 |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
215 return |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
216 } |