OWSLib
OWSLib copied to clipboard
Inconsistent filter parameter in WFS 2.0.0
Greetings
Not sure if it's a bug or me misunderstanding.
In this small snippet (which works)
wfs20 = WebFeatureService(url='http://services.ga.gov.au/earthresource/wfs', version='2.0.0')
gold= """<fes:Filter xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:erl="http://xmlns.earthresourceml.org/earthresourceml-lite/1.0">
<fes:PropertyIsEqualTo>
<fes:ValueReference>erl:representativeCommodity_uri</fes:ValueReference>
<fes:Literal>http://resource.geosciml.org/classifier/cgi/commodity-code/gold</fes:Literal>
</fes:PropertyIsEqualTo>
</fes:Filter>
"""
# Get some mineral occurrences
response = wfs20.getfeature(typename='erl:MineralOccurrenceView',maxfeatures=10,method="{http://www.opengis.net/wfs}Post",filter=etree.fromstring(gold))
filter
parameter can either be a string on a etree Element, so filter=etree.fromstring(gold)
or filter=gold
should both work. If I pass the etree Element, it works fine, except it outputs a warning
(...) feature\__init__.py:351: FutureWarning: The behavior of this method will change in future versions. Use specific 'len(elem)' or 'elem is not None' test instead.
elif filter:
but If I use a string
# Get some mineral occurrences
response = wfs20.getfeature(typename='erl:MineralOccurrenceView',maxfeatures=10,method="{http://www.opengis.net/wfs}Post",filter=gold)
the WFS returns nothing because there are no filter, because this bit of code in postrequest.py (set_filter
if isinstance(filter, str):
f = etree.fromstring(filter)
sub_elem = f.find(util.nspath("Filter", FES_NAMESPACE))
else:
sub_elem = filter
self._query.append(sub_elem)
sub_elem
returns Nothing
(because it look only in f
child ?)
so to make it work you must surround the filter with some dummy tag (and it then works for both string and Element)
gold= """<a><fes:Filter xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:erl="http://xmlns.earthresourceml.org/earthresourceml-lite/1.0">
<fes:PropertyIsEqualTo>
<fes:ValueReference>erl:representativeCommodity_uri</fes:ValueReference>
<fes:Literal>http://resource.geosciml.org/classifier/cgi/commodity-code/gold</fes:Literal>
</fes:PropertyIsEqualTo>
</fes:Filter></a>
"""
Now, I assume the intent is not to build the filter with a `wfs:Query` around it because the code above specifically look for `Filter` and passing a etree Element just appends it as-is And the parameter is called `filter`. Personnaly, adding a extra tag does not make sense.
So I guess there is a bug when the Filter is passed as a string (sans extra tag) and there is a waning message when an Element is passed.