Mercurial > gemma
annotate pkg/wfs/global.go @ 3334:8c96b7379aea
client: fairway availability: made store action work with both types of feature objects
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Mon, 20 May 2019 17:14:47 +0200 |
parents | 2b6f73c30016 |
children | 04876d865528 |
rev | line source |
---|---|
2634
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 // |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 // |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2019 by via donau |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 // |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 package wfs |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
2711
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
17 "bufio" |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
18 "errors" |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
19 "fmt" |
2634
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 "io" |
2711
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
21 "io/ioutil" |
2634
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 "log" |
2711
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
23 "os" |
2634
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 "os/exec" |
2711
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
25 "path/filepath" |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
26 |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
27 "gemma.intevation.de/gemma/pkg/config" |
2634
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 ) |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 |
2702
d7ef169fd0d3
WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2634
diff
changeset
|
30 var ( |
d7ef169fd0d3
WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2634
diff
changeset
|
31 FormatGeoJSON = []string{"geojson", "application/json"} |
d7ef169fd0d3
WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2634
diff
changeset
|
32 FormatGML = []string{ |
2711
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
33 "application/gml+xml; version=3.2", |
2702
d7ef169fd0d3
WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2634
diff
changeset
|
34 "gml2", "gml3", "gml32", |
d7ef169fd0d3
WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2634
diff
changeset
|
35 "text/xml; subtype=gml/2.1.2", |
d7ef169fd0d3
WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2634
diff
changeset
|
36 "text/xml; subtype=gml/3.1.1", |
d7ef169fd0d3
WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2634
diff
changeset
|
37 "text/xml; subtype=gml/3.2", |
d7ef169fd0d3
WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2634
diff
changeset
|
38 } |
d7ef169fd0d3
WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2634
diff
changeset
|
39 ) |
d7ef169fd0d3
WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2634
diff
changeset
|
40 |
2634
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 type ( |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 Downloader interface { |
2719
2b6f73c30016
WFS downloader: Add BasicAuth support for downloading. TODO: Use it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2711
diff
changeset
|
43 Download(user, password string, handler func(string, io.Reader) error) error |
2634
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 } |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 GeoJSONDownloader []string |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 GMLDownloader []string |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 ) |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 var GetFeatures = setup() |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 func setup() func(*Capabilities, string, string) (Downloader, error) { |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 path, err := exec.LookPath("ogr2ogr") |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 if err != nil { |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 log.Println("info: ogr2ogr not installed. Using direct GeoJSON WFS download.") |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 return GetFeaturesGeoJSON |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 } |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 log.Printf("info: ogr2ogr found at %s. Using GML WFS download.\n", path) |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 return GetFeaturesGML |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 } |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 func GetFeaturesGeoJSON( |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 caps *Capabilities, |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 featureTypeName string, |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 sortBy string, |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 ) (Downloader, error) { |
2702
d7ef169fd0d3
WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2634
diff
changeset
|
67 urls, err := GetFeaturesGET( |
d7ef169fd0d3
WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2634
diff
changeset
|
68 caps, |
d7ef169fd0d3
WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2634
diff
changeset
|
69 featureTypeName, |
d7ef169fd0d3
WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2634
diff
changeset
|
70 FormatGeoJSON, |
d7ef169fd0d3
WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2634
diff
changeset
|
71 sortBy) |
d7ef169fd0d3
WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2634
diff
changeset
|
72 return GeoJSONDownloader(urls), err |
2634
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 } |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 func GetFeaturesGML( |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 caps *Capabilities, |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 featureTypeName string, |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 sortBy string, |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 ) (Downloader, error) { |
2702
d7ef169fd0d3
WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2634
diff
changeset
|
80 urls, err := GetFeaturesGET( |
d7ef169fd0d3
WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2634
diff
changeset
|
81 caps, |
d7ef169fd0d3
WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2634
diff
changeset
|
82 featureTypeName, |
d7ef169fd0d3
WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2634
diff
changeset
|
83 FormatGML, |
d7ef169fd0d3
WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2634
diff
changeset
|
84 sortBy) |
d7ef169fd0d3
WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2634
diff
changeset
|
85 return GMLDownloader(urls), err |
2634
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 } |
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 |
2719
2b6f73c30016
WFS downloader: Add BasicAuth support for downloading. TODO: Use it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2711
diff
changeset
|
88 func (gjd GeoJSONDownloader) Download(user, password string, handler func(string, io.Reader) error) error { |
2b6f73c30016
WFS downloader: Add BasicAuth support for downloading. TODO: Use it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2711
diff
changeset
|
89 return DownloadURLs(user, password, []string(gjd), handler) |
2702
d7ef169fd0d3
WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2634
diff
changeset
|
90 } |
d7ef169fd0d3
WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2634
diff
changeset
|
91 |
2711
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
92 func places(n int) int { |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
93 places := 1 |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
94 if n < 0 { |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
95 places++ |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
96 n = -n |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
97 } |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
98 for value := 10; n >= value; value *= 10 { |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
99 places++ |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
100 } |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
101 return places |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
102 } |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
103 |
2719
2b6f73c30016
WFS downloader: Add BasicAuth support for downloading. TODO: Use it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2711
diff
changeset
|
104 func (gmd GMLDownloader) Download(user, password string, handler func(string, io.Reader) error) error { |
2711
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
105 |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
106 if len(gmd) == 0 { |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
107 return errors.New("Nothing to download") |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
108 } |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
109 |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
110 tmpDir := config.TmpDir() |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
111 dlDir, err := ioutil.TempDir(tmpDir, "wfs-downloads") |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
112 if err != nil { |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
113 return err |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
114 } |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
115 defer os.RemoveAll(dlDir) |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
116 digits := places(len(gmd)) |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
117 |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
118 var files []string |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
119 |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
120 for i, url := range gmd { |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
121 fname := filepath.Join(dlDir, fmt.Sprintf("%0*d.gml", digits, i)) |
2719
2b6f73c30016
WFS downloader: Add BasicAuth support for downloading. TODO: Use it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2711
diff
changeset
|
122 if err := downloadURL(user, password, url, func(_ string, r io.Reader) error { |
2711
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
123 f, err := os.Create(fname) |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
124 if err != nil { |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
125 return err |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
126 } |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
127 if _, err = io.Copy(f, r); err != nil { |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
128 f.Close() |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
129 return err |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
130 } |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
131 return f.Close() |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
132 }); err != nil { |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
133 return err |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
134 } |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
135 files = append(files, fname) |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
136 } |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
137 |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
138 out := filepath.Join(dlDir, "out.geojson") |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
139 |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
140 cmd := exec.Command("ogr2ogr", append([]string{"-f", "GeoJSON", out}, files...)...) |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
141 |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
142 msg, err := cmd.CombinedOutput() |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
143 if err != nil { |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
144 return fmt.Errorf("ogr2ogr failed: %s", msg) |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
145 } |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
146 |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
147 in, err := os.Open(out) |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
148 if err != nil { |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
149 return err |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
150 } |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
151 defer in.Close() |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
152 |
3956de9b6b32
WFS downloader: Implemented GML download to file, ogr2ogr to GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2702
diff
changeset
|
153 return handler(gmd[0], bufio.NewReader(in)) |
2634
49ce3c11ca72
WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 } |