Mercurial > gemma
changeset 1616:f59550310143
WFS downloader: Support different feature output formats.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 18 Dec 2018 12:56:37 +0100 |
parents | efc409e330a6 |
children | f4b31cf5b656 |
files | cmd/wfs/main.go pkg/wfs/download.go |
diffstat | 2 files changed, 19 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/cmd/wfs/main.go Tue Dec 18 12:42:43 2018 +0100 +++ b/cmd/wfs/main.go Tue Dec 18 12:56:37 2018 +0100 @@ -36,7 +36,7 @@ dump(caps) } - if err := wfs.GetFeaturesGET(caps, *featureType); err != nil { + if err := wfs.GetFeaturesGET(caps, *featureType, "application/json"); err != nil { log.Fatalf("error: %v\n", err) } }
--- a/pkg/wfs/download.go Tue Dec 18 12:42:43 2018 +0100 +++ b/pkg/wfs/download.go Tue Dec 18 12:56:37 2018 +0100 @@ -27,10 +27,11 @@ ) var ( - ErrNoSuchFeatureType = errors.New("No such feature type") - ErrGetFeatureNotSupported = errors.New("GetFeature not supported") - ErrMethodGetNotSupported = errors.New("GET not supported") - ErrNoNumberMatchedFound = errors.New("No numberMatched attribute found") + ErrNoSuchFeatureType = errors.New("No such feature type") + ErrGetFeatureNotSupported = errors.New("GetFeature not supported") + ErrMethodGetNotSupported = errors.New("GET not supported") + ErrNoNumberMatchedFound = errors.New("No numberMatched attribute found") + ErrOutputFormatNotSupported = errors.New("Output format not supported") ) func GetCapabilities(capURL string) (*Capabilities, error) { @@ -93,7 +94,7 @@ return *result.NumberMatched, nil } -func GetFeaturesGET(caps *Capabilities, featureTypeName string) error { +func GetFeaturesGET(caps *Capabilities, featureTypeName, outputFormat string) error { feature := caps.FindFeatureType(featureTypeName) if feature == nil { @@ -122,6 +123,10 @@ getU = getU.ResolveReference(base) } + if !op.SupportsOutputFormat(outputFormat) { + return ErrOutputFormatNotSupported + } + wfsVersion := caps.HighestWFSVersion(WFS2_0_0) featuresPerPage, supportsPaging := op.FeaturesPerPage() @@ -161,6 +166,12 @@ } } + addOutputFormat := func(v url.Values) { + if outputFormat != "" { + v.Set("outputFormat", outputFormat) + } + } + if supportsPaging { pagedURL := func(ofs, count int) string { v := url.Values{} @@ -175,6 +186,7 @@ } v.Set("TYPENAMES", featureTypeName) addNS(v) + addOutputFormat(v) q := *getU q.RawQuery = v.Encode() return q.String() @@ -202,6 +214,7 @@ v.Set("VERSION", wfsVersion) v.Set("TYPENAMES", featureTypeName) addNS(v) + addOutputFormat(v) q := *getU q.RawQuery = v.Encode() downloadURLs = []string{q.String()}