There are multiple problems with your filter:
- The space before FILTER prevents the server parsing and using it
- You spelled
DWithin
wrong (Within
is a different filter entirely)
- You are using the wrong geometry name (it's
geom
)
- Your unit needs to be meters
- Your point should not have a comma separating the coordinates.
- Probably a bunch of other stuff
So I switched to using CQL
https://emidius.mi.ingv.it/services/italy/wfs/?service=wfs&version=2.0.0&request=GetFeature&typeNames=italy:CPTI_current&outputFormat=application/json&CQL_FILTER=dwithin(geom,%20POINT(14.964%2037.696),%20500,%20meters)
which works but says there are no earthquakes with in 5 km of your point, but does find 46 if I flip the axis order of your point to give a dwithin(geom, POINT(37.696 14.964), 5, kilometers)
and a final URL of:
https://emidius.mi.ingv.it/services/italy/wfs/?service=wfs&version=2.0.0&request=GetFeature&typeNames=italy:CPTI_current&outputFormat=application/json&CQL_FILTER=dwithin(geom,%20POINT(37.696%2014.964),%205,%20kilometers)
Or if you prefer the OGC representation:
<?xml version="1.0" encoding="UTF-8"?>
<ogc:Filter xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc">
<ogc:DWithin>
<ogc:PropertyName>geom</ogc:PropertyName>
<gml:Point>
<gml:coord>
<gml:X>37.696</gml:X>
<gml:Y>14.964</gml:Y>
</gml:coord>
</gml:Point>
<ogc:Distance units="kilometers">5.0</ogc:Distance>
</ogc:DWithin>
</ogc:Filter>
At least the server returns data if the BBOX is given in EPSG:4326 lat-lon coordinates.
https://www.lfu.bayern.de/gdi/wfs/natur/schutzgebiete?service=WFS&version=2.0.0&request=GetFeature&typeName=landschaftsschutzgebiet&srs=epsg:25832&outputFormat=GML3&bbox=47.938331252805355,11.621377748868138,48.04357841307603,11.749294923796597
Your EPSG:25832 bounding box with the urn syntax looks good to me and the syntax is as it is defined in the standard OGC 06-121r3 https://portal.ogc.org/files/?artifact_id=20040 despite you have spaces between the coordinates of the BBOX ,
and they should not be there. Removing the spaces did not make your query to work, though.
Best Answer
You can use the
SQL Query Composer
in theWFS Server Connection Dialog
when adding the data. There you can create a spatial filter.EDIT: For using WFS via GeoServer in python and setting a bounding-box GeoServer requires a
POST
rather than aGET
request as statet here:https://docs.geoserver.org/latest/en/user/services/wfs/reference.html
"While there are limited options available in a GET request for spatial queries (more are available in POST requests using filters), filtering by bounding box (BBOX) is supported."
So one approach would be to query the data in your script beforehand making a post request and from the result create the layer on the fly:
That's how your query would look like in
curl
:In QGIS you could load the data using
urllib
like:Note: I changed your initial bounding box in the sample to a smaller value - your initial bounding box result has around 8MB of data.