Mercurial > gemma
changeset 2622:02505fcff63c
WFS downloads: Accept 'geojson' as mime type, too.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 13 Mar 2019 15:39:12 +0100 |
parents | 78f75e99f9c5 |
children | 145f2b89287c |
files | cmd/wfs/main.go pkg/imports/dma.go pkg/imports/fd.go pkg/imports/wa.go pkg/imports/wp.go pkg/imports/wx.go pkg/wfs/capabilities.go pkg/wfs/download.go |
diffstat | 8 files changed, 22 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/cmd/wfs/main.go Wed Mar 13 15:21:00 2019 +0100 +++ b/cmd/wfs/main.go Wed Mar 13 15:39:12 2019 +0100 @@ -52,7 +52,7 @@ } urls, err := wfs.GetFeaturesGET( - caps, *featureType, "application/json", *sortBy) + caps, *featureType, wfs.FormatGeoJSON, *sortBy) check(err) log.Printf("urls: %v\n", urls)
--- a/pkg/imports/dma.go Wed Mar 13 15:21:00 2019 +0100 +++ b/pkg/imports/dma.go Wed Mar 13 15:39:12 2019 +0100 @@ -139,7 +139,7 @@ } urls, err := wfs.GetFeaturesGET( - caps, dma.FeatureType, "application/json", dma.SortBy) + caps, dma.FeatureType, wfs.FormatGeoJSON, dma.SortBy) if err != nil { feedback.Error("Cannot create GetFeature URLs. %v", err) return nil, err
--- a/pkg/imports/fd.go Wed Mar 13 15:21:00 2019 +0100 +++ b/pkg/imports/fd.go Wed Mar 13 15:39:12 2019 +0100 @@ -208,7 +208,7 @@ } urls, err := wfs.GetFeaturesGET( - caps, fd.FeatureType, "application/json", fd.SortBy) + caps, fd.FeatureType, wfs.FormatGeoJSON, fd.SortBy) if err != nil { feedback.Error("Cannot create GetFeature URLs. %v", err) return nil, err
--- a/pkg/imports/wa.go Wed Mar 13 15:21:00 2019 +0100 +++ b/pkg/imports/wa.go Wed Mar 13 15:39:12 2019 +0100 @@ -146,7 +146,7 @@ } urls, err := wfs.GetFeaturesGET( - caps, wx.FeatureType, "application/json", wx.SortBy) + caps, wx.FeatureType, wfs.FormatGeoJSON, wx.SortBy) if err != nil { feedback.Error("Cannot create GetFeature URLs. %v", err) return nil, err
--- a/pkg/imports/wp.go Wed Mar 13 15:21:00 2019 +0100 +++ b/pkg/imports/wp.go Wed Mar 13 15:39:12 2019 +0100 @@ -218,7 +218,7 @@ } urls, err := wfs.GetFeaturesGET( - caps, wp.FeatureType, "application/json", wp.SortBy) + caps, wp.FeatureType, wfs.FormatGeoJSON, wp.SortBy) if err != nil { feedback.Error("Cannot create GetFeature URLs. %v", err) return err
--- a/pkg/imports/wx.go Wed Mar 13 15:21:00 2019 +0100 +++ b/pkg/imports/wx.go Wed Mar 13 15:39:12 2019 +0100 @@ -146,7 +146,7 @@ } urls, err := wfs.GetFeaturesGET( - caps, wx.FeatureType, "application/json", wx.SortBy) + caps, wx.FeatureType, wfs.FormatGeoJSON, wx.SortBy) if err != nil { feedback.Error("Cannot create GetFeature URLs. %v", err) return nil, err
--- a/pkg/wfs/capabilities.go Wed Mar 13 15:21:00 2019 +0100 +++ b/pkg/wfs/capabilities.go Wed Mar 13 15:39:12 2019 +0100 @@ -19,6 +19,7 @@ "io" "regexp" "strconv" + "strings" "golang.org/x/net/html/charset" ) @@ -214,19 +215,20 @@ } // SupportsOutputFormat checks if one of the given formats is supported. -func (op *Operation) SupportsOutputFormat(formats ...string) bool { +func (op *Operation) SupportsOutputFormat(formats ...string) string { for _, p := range op.Parameters { if p.Name == "outputFormat" { for _, av := range p.AllowedValues.Values { + v := strings.ToLower(av.Value) for _, f := range formats { - if av.Value == f { - return true + if v == strings.ToLower(f) { + return av.Value } } } } } - return false + return "" } // FeaturesPerPage returns the number of features per page.
--- a/pkg/wfs/download.go Wed Mar 13 15:21:00 2019 +0100 +++ b/pkg/wfs/download.go Wed Mar 13 15:39:12 2019 +0100 @@ -43,6 +43,8 @@ ErrOutputFormatNotSupported = errors.New("Output format not supported") ) +var FormatGeoJSON = []string{"geojson", "application/json"} + // GetCapabilities downloads a capabilities document for a given URL. func GetCapabilities(capURL string) (*Capabilities, error) { @@ -108,8 +110,8 @@ // for a given feature type from a WFS servers. func GetFeaturesGET( caps *Capabilities, - featureTypeName, - outputFormat string, + featureTypeName string, + outputFormats []string, sortBy string, ) ([]string, error) { @@ -140,8 +142,12 @@ getU = getU.ResolveReference(base) } - if !op.SupportsOutputFormat(outputFormat) { - return nil, ErrOutputFormatNotSupported + var outputFormat string + + if len(outputFormats) > 0 { + if outputFormat = op.SupportsOutputFormat(outputFormats...); outputFormat == "" { + return nil, ErrOutputFormatNotSupported + } } wfsVersion := caps.HighestWFSVersion(WFS200)