changeset 1614:efc409e330a6

WFS downloader: Propagate namespaces of feature type into GetFeature request.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 18 Dec 2018 12:42:43 +0100
parents f2d24dceecc7
children 95641748383f f59550310143
files pkg/wfs/capabilities.go pkg/wfs/download.go
diffstat 2 files changed, 34 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/wfs/capabilities.go	Tue Dec 18 12:38:58 2018 +0100
+++ b/pkg/wfs/capabilities.go	Tue Dec 18 12:42:43 2018 +0100
@@ -188,6 +188,21 @@
 	return false
 }
 
+func (o *Operation) SupportsOutputFormat(formats ...string) bool {
+	for _, p := range o.Parameters {
+		if p.Name == "outputFormat" {
+			for _, av := range p.AllowedValues.Values {
+				for _, f := range formats {
+					if av.Value == f {
+						return true
+					}
+				}
+			}
+		}
+	}
+	return false
+}
+
 func (o *Operation) FeaturesPerPage() (int, bool) {
 	for _, c := range o.Constraints {
 		if c.Name == "CountDefault" {
--- a/pkg/wfs/download.go	Tue Dec 18 12:38:58 2018 +0100
+++ b/pkg/wfs/download.go	Tue Dec 18 12:42:43 2018 +0100
@@ -17,6 +17,7 @@
 	"bufio"
 	"encoding/xml"
 	"errors"
+	"fmt"
 	"log"
 	"net/http"
 	"net/url"
@@ -94,7 +95,8 @@
 
 func GetFeaturesGET(caps *Capabilities, featureTypeName string) error {
 
-	if caps.FindFeatureType(featureTypeName) == nil {
+	feature := caps.FindFeatureType(featureTypeName)
+	if feature == nil {
 		return ErrNoSuchFeatureType
 	}
 	op := caps.FindOperation("GetFeature")
@@ -144,9 +146,22 @@
 	}
 
 	var downloadURLs []string
+	wfs2 := !versionIsLess(wfsVersion, WFS2_0_0)
+
+	addNS := func(v url.Values) {
+		if len(feature.Namespaces) == 0 {
+			return
+		}
+		// Only use first namespace
+		ns := feature.Namespaces[0]
+		if wfs2 {
+			v.Set("NAMESPACES", fmt.Sprintf("(%s,%s)", ns.Space, ns.Local))
+		} else {
+			v.Set("NAMESPACE", fmt.Sprintf("(%s:%s)", ns.Space, ns.Local))
+		}
+	}
 
 	if supportsPaging {
-		wfs2 := !versionIsLess(wfsVersion, WFS2_0_0)
 		pagedURL := func(ofs, count int) string {
 			v := url.Values{}
 			v.Set("SERVICE", "WFS")
@@ -159,6 +174,7 @@
 				v.Set("maxFeatures", strconv.Itoa(count))
 			}
 			v.Set("TYPENAMES", featureTypeName)
+			addNS(v)
 			q := *getU
 			q.RawQuery = v.Encode()
 			return q.String()
@@ -185,6 +201,7 @@
 		v.Set("REQUEST", "GetFeature")
 		v.Set("VERSION", wfsVersion)
 		v.Set("TYPENAMES", featureTypeName)
+		addNS(v)
 		q := *getU
 		q.RawQuery = v.Encode()
 		downloadURLs = []string{q.String()}