I have a web client that filters WFS layers from various servers such as MapServer and GeoServer.
The following URL (encoding and removing whitespace does not make a difference):
https://ows-demo.terrestris.de/geoserver/osm/ows?version=2.0.0&request=GetFeature&service=WFS&typeNames=osm-fuel&count=10&exceptions=xml&filter=<fes:Filter xsi:schemaLocation="http://www.opengis.net/fes/2.0 http://schemas.opengis.net/filter/2.0/filterAll.xsd http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/gml.xsd" xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><ogc:BBOX> <ogc:PropertyName>the_geom</ogc:PropertyName><gml:Envelope xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:3857"><gml:lowerCorner>-1400194.9520285155 6560917.375753866</gml:lowerCorner> <gml:upperCorner>270219.8351193511 7459453.681587799</gml:upperCorner></gml:Envelope> </ogc:BBOX></fes:Filter>
Returns an exception:
<?xml version="1.0" encoding="UTF-8"?><ows:ExceptionReport xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0.0" xsi:schemaLocation="http://www.opengis.net/ows/1.1 http://ows-demo.terrestris.de/geoserver/schemas/ows/1.1.0/owsAll.xsd">
<ows:Exception exceptionCode="XML getFeature request SAX parsing error" locator="org.geoserver.ows.XmlRequestReader">
<ows:ExceptionText>org.xml.sax.SAXException: Attempted to construct illegal filter - I dont understand the tag: ogc:BBOX. HINT: tags are case-sensitive!
Attempted to construct illegal filter - I dont understand the tag: ogc:BBOX. HINT: tags are case-sensitive!</ows:ExceptionText>
</ows:Exception>
</ows:ExceptionReport>
If I remove the outer <filter></filter>
tags I get results:
https://ows-demo.terrestris.de/geoserver/osm/ows?version=2.0.0&request=GetFeature&service=WFS&typeNames=osm-fuel&count=10&exceptions=xml&filter=<ogc:BBOX> <ogc:PropertyName>the_geom</ogc:PropertyName><gml:Envelope xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:3857"><gml:lowerCorner>-1400194.9520285155 6560917.375753866</gml:lowerCorner> <gml:upperCorner>270219.8351193511 7459453.681587799</gml:upperCorner></gml:Envelope></ogc:BBOX>
However these results don't appear to be spatially filtered - the same number of results are returned with or without the filter.
The bbox
approach (suggested in the GeoServer docs works fine. The following returns the expected results:
However I was hoping for an approach that works with both MapServer and GeoServer. Note this approach was working (in 2020) so I'm wondering if something has changed, or a config setting has changed in a more recent version of GeoServer.
With some basic testing it seems as though MapServer does also support the bbox
option so it could be possible to switch to this for all servers.
Update
The following request brings back the expected results:
https://ows-demo.terrestris.de/geoserver/osm/ows?version=2.0.0&request=GetFeature&service=WFS&typeNames=osm-fuel&count=10&exceptions=xml&filter=<fes:Filter xmlns:fes="http://www.opengis.net/fes/2.0"><fes:BBOX><fes:ValueReference>the_geom</fes:ValueReference><gml:Envelope xmlns:gml="http://www.opengis.net/gml/3.2" srsName="EPSG:3857"><gml:lowerCorner>-1400194.9520285155 6560917.375753866</gml:lowerCorner><gml:upperCorner>270219.8351193511 7459453.681587799</gml:upperCorner></gml:Envelope></fes:BBOX></fes:Filter>
Note:
- BBOX is in the
fes
namespace (thanks @ian-turton) <fes:ValueReference>the_geom</fes:ValueReference>
instead of<ogc:PropertyName>
- namespaces have to be included - without them there is no error but there is no spatial filtering