Mercurial > gemma
annotate pkg/imports/fm.go @ 4906:21fea90f4002 fairway-marks-import
Avoid unnecessary pointer to pointer
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Fri, 07 Feb 2020 12:35:11 +0100 |
parents | 8cb201b551b3 |
children | 644cb7c175f3 |
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 ( |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
17 "encoding/json" |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
18 "fmt" |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
19 "io" |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
20 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
21 "gemma.intevation.de/gemma/pkg/wfs" |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
22 ) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
23 |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
24 // FairwayMarks is a struct |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
25 // 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
|
26 // specific types for fairway marks. |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
27 type FairwayMarks struct { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
28 // URL the GetCapabilities URL of the WFS service. |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
29 URL string `json:"url"` |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
30 // FeatureType selects the feature type of the WFS service. |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
31 FeatureType string `json:"feature-type"` |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
32 // SortBy works around misconfigured services to |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
33 // establish a sort order to get the features. |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
34 SortBy string `json:"sort-by"` |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
35 // User is an optional username for Basic Auth. |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
36 User string `json:"user,omitempty"` |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
37 // Password is an optional password for Basic Auth. |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
38 Password string `json:"password,omitempty"` |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
39 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
40 |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
41 // 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
|
42 type fairwayMarksProperties struct { |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
43 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 Sorind *string `json:"hydro_sorind"` |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
56 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
57 |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
58 // 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
|
59 func getFMFeatures( |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
60 feedback Feedback, |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
61 fm FairwayMarks, |
4906
21fea90f4002
Avoid unnecessary pointer to pointer
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
62 // Constructor returning pointer to struct |
21fea90f4002
Avoid unnecessary pointer to pointer
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
63 // representing featuretype's properties |
4905
8cb201b551b3
Replace bogus usage of pointer for type intrusion
Tom Gottfried <tom@intevation.de>
parents:
4904
diff
changeset
|
64 newProps func() interface{}, |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
65 ) ( |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
66 // Elements can be converted to []interface{}{p, fp} with |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
67 // p being a pointSlice and fp of the type of argument props. |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
68 fms [][]interface{}, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
69 epsg int, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
70 err error, |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
71 ) { |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
72 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
73 feedback.Info("Loading capabilities from %s", fm.URL) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
74 caps, err := wfs.GetCapabilities(fm.URL) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
75 if err != nil { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
76 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
|
77 return |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
78 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
79 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
80 ft := caps.FindFeatureType(fm.FeatureType) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
81 if ft == nil { |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
82 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
|
83 return |
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 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
86 feedback.Info("Found feature type '%s", fm.FeatureType) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
87 |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
88 epsg, err = wfs.CRSToEPSG(ft.DefaultCRS) |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
89 if err != nil { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
90 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
|
91 return |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
92 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
93 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
94 if fm.SortBy != "" { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
95 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
|
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 dl, err := wfs.GetFeatures(caps, fm.FeatureType, fm.SortBy) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
99 if err != nil { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
100 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
|
101 return |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
102 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
103 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
104 var ( |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
105 unsupported = stringCounter{} |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
106 missingProperties int |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
107 badProperties int |
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 |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
110 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
|
111 feedback.Info("Get features from: '%s'", url) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
112 rfc, err := wfs.ParseRawFeatureCollection(r) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
113 if err != nil { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
114 return fmt.Errorf("parsing GetFeature document failed: %v", err) |
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 if rfc.CRS != nil { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
117 crsName := rfc.CRS.Properties.Name |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
118 if epsg, err = wfs.CRSToEPSG(crsName); err != nil { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
119 feedback.Error("Unsupported CRS: %d", crsName) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
120 return err |
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 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
123 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
124 // No features -> ignore. |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
125 if rfc.Features == nil { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
126 return nil |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
127 } |
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 feedback.Info("Using EPSG: %d", epsg) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
130 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
131 for _, feature := range rfc.Features { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
132 if feature.Properties == nil || feature.Geometry.Coordinates == nil { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
133 missingProperties++ |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
134 continue |
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 |
4905
8cb201b551b3
Replace bogus usage of pointer for type intrusion
Tom Gottfried <tom@intevation.de>
parents:
4904
diff
changeset
|
137 props := newProps() |
4906
21fea90f4002
Avoid unnecessary pointer to pointer
Tom Gottfried <tom@intevation.de>
parents:
4905
diff
changeset
|
138 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
|
139 badProperties++ |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
140 continue |
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 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
143 switch feature.Geometry.Type { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
144 case "Point": |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
145 var p pointSlice |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
146 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
|
147 return err |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
148 } |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
149 |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
150 f := []interface{}{p, props} |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
151 fms = append(fms, f) |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
152 default: |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
153 unsupported[feature.Geometry.Type]++ |
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 return nil |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
157 }) |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
158 if err != nil { |
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
159 return |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
160 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
161 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
162 if badProperties > 0 { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
163 feedback.Warn("Bad properties: %d", badProperties) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
164 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
165 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
166 if missingProperties > 0 { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
167 feedback.Warn("Missing properties: %d", missingProperties) |
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 |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
170 if len(unsupported) != 0 { |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
171 feedback.Warn("Unsupported types found: %s", unsupported) |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
172 } |
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
173 |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
174 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
|
175 |
4904
53d929f658f3
Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
4895
diff
changeset
|
176 return |
4894
8eb36d0d5bdf
Draft implementation of fairway marks import
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
177 } |