# HG changeset patch # User Sascha L. Teichmann # Date 1545134197 -3600 # Node ID f5955031014344f0c6da6c710d860b6f82538123 # Parent efc409e330a6ceb5447ff0f1e7e8cdf30405cf1a WFS downloader: Support different feature output formats. diff -r efc409e330a6 -r f59550310143 cmd/wfs/main.go --- 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) } } diff -r efc409e330a6 -r f59550310143 pkg/wfs/download.go --- 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()}