2

I need help with WFS filtering for GML. I want to filter only by one property (name of administrative unit) - that is all.

Lets say I would like to get the second member of this GML: http://services.cuzk.cz/wfs/inspire-au-wfs.asp?service=WFS&version=2.0.0&request=GetFeature&typeNames=au:AdministrativeUnit&count=2

The name of administrative unit is in this tag: <gn:text>Hlavní město Praha</gn:text> (path: au:name > gn:GeographicalName > gn:spelling > gn:SpellingOfName > gn:text)

Here are some of my tests which do not work:

http://services.cuzk.cz/wfs/inspire-au-wfs.asp?service=WFS&version=2.0.0&request=GetFeature&typeNames=au:AdministrativeUnit&FILTER=<Filter><PropertyIsEqualTo><ValueReference>gn:text</ValueReference><Literal>Hlavní město Praha</Literal></PropertyIsEqualTo></Filter> 

When I use ogr2ogr to transform the GML to GeoJSON (the WFS returns only GML) then the name of the administrative unit is in "text" attribute.

http://services.cuzk.cz/wfs/inspire-au-wfs.asp?service=WFS&version=2.0.0&request=GetFeature&typeNames=au:AdministrativeUnit&FILTER=<Filter><PropertyIsEqualTo><PropertyName>text</PropertyName><Literal>Hlavní město Praha</Literal></PropertyIsEqualTo></Filter> 

This one returns whole layer instead of the 1 feature/member:

http://services.cuzk.cz/wfs/inspire-au-wfs.asp?service=WFS&version=2.0.0&request=GetFeature&typeNames=au:AdministrativeUnit&CQL_FILTER=text='Hlavní město Praha' 

Here is meta for the layer & service:

http://services.cuzk.cz/wfs/inspire-au-wfs.asp?service=WFS&version=2.0.0&request=DescribeFeatureType&typeNames=au:AdministrativeUnit

http://services.cuzk.cz/wfs/inspire-au-wfs.asp?service=WFS&version=2.0.0&request=GetCapabilities

Any idea how to filter the nested tags in GML?

2 Answers 2

1

In WFS 2.0 you can use a limited set of XPath to specify your property in the feature so in your case a query like this should work:

<?xml version="1.0"?> <wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:sf="http://www.openplans.org/spearfish" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" service="WFS" version="2.0.0" xsi:schemaLocation="http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/gml.xsd"> <wfs:Query typeNames="au:AdministrativeUnit"> <fes:Filter> <PropertyIsEqualTo> <ValueReference>name/GeographicalName/spelling/SpellingOfName/text</ValueReference> <Literal>Hlavní město Praha</Literal> </PropertyIsEqualTo> </fes:Filter> </wfs:Query> </wfs:GetFeature> 

But this server (despite claiming to support POST in the getCapabilities) doesn't seem to like POSTed queries so you need to URL encode the Filter which should give you a URL like:

"http://services.cuzk.cz/wfs/inspire-au-wfs.asp?service=wfs&version=2.0.0&request=GetFeature&typeNames=au:AdministrativeUnit&FILTER=%3Cfes%3AFilter%3E%0D%0A%20%20%20%20%20%20%3CPropertyIsEqualTo%3E%0D%0A%20%20%20%20%20%20%20%20%3CValueReference%3Ename%2FGeographicalName%2Fspelling%2FSpellingOfName%2Ftext%3C%2FValueReference%3E%0D%0A%20%20%20%20%20%20%20%20%3CLiteral%3EHlavn%C3%AD%20m%C4%9Bsto%20Praha%3C%2FLiteral%3E%0D%0A%20%20%20%20%20%20%3C%2FPropertyIsEqualTo%3E%0D%0A%20%20%20%20%3C%2Ffes%3AFilter%3E%0D%0A" 

But all I can get from that is an OperationProcessingFailed error, so something seems to be up with either my request or the server.

Since it seems to not be a GeoServer you almost certainly can't use CQL_FILTERs anyway.

1
  • 1
    I found out that the WFS server has stored queries so I used it: services.cuzk.cz/wfs/… Commented Jul 5, 2018 at 16:59
0

I had the same problem in

https://inspire-wfs.maanmittauslaitos.fi/inspire-wfs/au/wfs. 

I tried to proposed solution, but the server returned an error. I modified the query a bit and got a correct result with this query:

<?xml version="1.0"?> <GetFeature service="WFS" version="2.0.0" xmlns="http://www.opengis.net/wfs/2.0" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/2.0/wfs.xsd" xmlns:au="http://inspire.ec.europa.eu/schemas/au/4.0" xmlns:gn="http://inspire.ec.europa.eu/schemas/gn/4.0" > <Query typeNames="au:AdministrativeUnit" srsName="EPSG:4326"> <fes:Filter> <fes:PropertyIsEqualTo> <fes:ValueReference>au:name/gn:GeographicalName/gn:spelling/gn:SpellingOfName/gn:text</fes:ValueReference> <fes:Literal>Helsinki</fes:Literal> </fes:PropertyIsEqualTo> </fes:Filter> </Query> 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.