annotate pkg/wfs/global.go @ 2702:d7ef169fd0d3

WFS downloader: More on downloading GML. WIP.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 18 Mar 2019 15:45:42 +0100
parents 49ce3c11ca72
children 3956de9b6b32
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 (
49ce3c11ca72 WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 "io"
49ce3c11ca72 WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 "log"
49ce3c11ca72 WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 "os/exec"
49ce3c11ca72 WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 )
49ce3c11ca72 WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21
2702
d7ef169fd0d3 WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2634
diff changeset
22 var (
d7ef169fd0d3 WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2634
diff changeset
23 FormatGeoJSON = []string{"geojson", "application/json"}
d7ef169fd0d3 WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2634
diff changeset
24 FormatGML = []string{
d7ef169fd0d3 WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2634
diff changeset
25 "gml2", "gml3", "gml32",
d7ef169fd0d3 WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2634
diff changeset
26 "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
27 "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
28 "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
29 }
d7ef169fd0d3 WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2634
diff changeset
30 )
d7ef169fd0d3 WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2634
diff changeset
31
2634
49ce3c11ca72 WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 type (
49ce3c11ca72 WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 Downloader interface {
49ce3c11ca72 WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 Download(handler func(string, io.Reader) error) error
49ce3c11ca72 WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 }
49ce3c11ca72 WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36
49ce3c11ca72 WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 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
38 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
39 )
49ce3c11ca72 WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40
49ce3c11ca72 WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 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
42
49ce3c11ca72 WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 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
44 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
45 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
46 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
47 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
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 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
50 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
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
49ce3c11ca72 WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 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
54 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
55 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
56 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
57 ) (Downloader, error) {
2702
d7ef169fd0d3 WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2634
diff changeset
58 urls, err := GetFeaturesGET(
d7ef169fd0d3 WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2634
diff changeset
59 caps,
d7ef169fd0d3 WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2634
diff changeset
60 featureTypeName,
d7ef169fd0d3 WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2634
diff changeset
61 FormatGeoJSON,
d7ef169fd0d3 WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2634
diff changeset
62 sortBy)
d7ef169fd0d3 WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2634
diff changeset
63 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
64 }
49ce3c11ca72 WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65
49ce3c11ca72 WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66 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
67 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
68 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
69 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
70 ) (Downloader, error) {
2702
d7ef169fd0d3 WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2634
diff changeset
71 urls, err := GetFeaturesGET(
d7ef169fd0d3 WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2634
diff changeset
72 caps,
d7ef169fd0d3 WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2634
diff changeset
73 featureTypeName,
d7ef169fd0d3 WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2634
diff changeset
74 FormatGML,
d7ef169fd0d3 WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2634
diff changeset
75 sortBy)
d7ef169fd0d3 WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2634
diff changeset
76 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
77 }
49ce3c11ca72 WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78
2702
d7ef169fd0d3 WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2634
diff changeset
79 func (gjd GeoJSONDownloader) Download(handler func(string, io.Reader) error) error {
d7ef169fd0d3 WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2634
diff changeset
80 return DownloadURLs([]string(gjd), handler)
d7ef169fd0d3 WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2634
diff changeset
81 }
d7ef169fd0d3 WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2634
diff changeset
82
d7ef169fd0d3 WFS downloader: More on downloading GML. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2634
diff changeset
83 func (gmd GMLDownloader) Download(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
84 // TODO: Implement, me!
49ce3c11ca72 WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85 return nil
49ce3c11ca72 WFS downloads: Started with GML based downloads based on installation of ogr2ogr.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86 }