3

I am trying to apply spatial filter on a WFS layer, but owslib.fes has only BBox spatial filter. Other spatial filters such as Intersects, Disjoint, Contains etc. are missing and unable to find. I want to apply intersect filter. I am able to do it in GeoServer.

Curl Request.

 curl -X POST -H "Content-Type:text/xml" --data @intersect.xml "https://demo.geo-solutions.it:443/geoserver/wfs"
         

@intersect.xml file.

       <wfs:GetFeature service="WFS" version="1.0.0"
             outputFormat="JSON"
          xmlns:topp="http://www.openplans.org/topp"
          xmlns:wfs="http://www.opengis.net/wfs"
          xmlns="http://www.opengis.net/ogc"
          xmlns:gml="http://www.opengis.net/gml"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://www.opengis.net/wfs
                              http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd">
         <wfs:Query typeName="geosolutions:Linee_in_america">
            <Filter>
              <Intersects>
                <PropertyName>the_geom</PropertyName>
                  <gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
                    <gml:coordinates>-74.817265,40.5296504</gml:coordinates>
                  </gml:Point>
                </Intersects>
              </Filter>
          </wfs:Query>
        <wfs:Query typeName="topp:states">
            <Filter>
              <Intersects>
                <PropertyName>the_geom</PropertyName>
                  <gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
                    <gml:coordinates>-74.817265,40.5296504</gml:coordinates>
                  </gml:Point>
                </Intersects>
              </Filter>
          </wfs:Query>
        </wfs:GetFeature>

Is it possible to implement this using OWSLib??

1 Answer 1

2

From the documentation https://geopython.github.io/OWSLib/#standards-support: OWSLib currently only support filter building for WFS 1.1 (FE.1.1). So OWSLib does support FE 1.1 filters and there is also an example about how to use PropertyIsLike filter. The challenge is to find the right syntax for the Intersects filter but once you get it right it should work. Maybe you can simple save the xml as you have it and use it like wfs11.getfeature(typename='bvv:gmd_ex', filter=filterxml).

>>> from owslib.fes import *
>>> from owslib.etree import etree
>>> from owslib.wfs import WebFeatureService
>>> wfs11 = WebFeatureService(url='http://geoserv.weichand.de:8080/geoserver/wfs', version='1.1.0')

>>> filter = PropertyIsLike(propertyname='bez_gem', literal='Ingolstadt', wildCard='*')
>>> filterxml = etree.tostring(filter.toXML()).decode("utf-8")
>>> response = wfs11.getfeature(typename='bvv:gmd_ex', filter=filterxml)
10
  • I have seen it and following the same example but there isn't any spatial filter.
    – Ayaz49
    Oct 29, 2020 at 9:56
  • Filter is a generic term. Spatial filters are filters as well as property filters. They are used in the same way in WFS. Just use what you have as <filter> in @intersect.xml file.
    – user30184
    Oct 29, 2020 at 10:59
  • By spatial filter I mean there is no spatial operator. For example PropertyIsGreaterThanOrEqualTo, PropertyIsLike are the operators. There is'nt any operator for spatial filtering, i.e intersects.
    – Ayaz49
    Oct 29, 2020 at 11:12
  • 1
    I think to create the filterxml for intersect, the respective operator is required. Can we create filterxml for intersect from whatever is available?
    – Ayaz49
    Oct 29, 2020 at 11:15
  • I do not quite get what you mean, sorry. Spatial filters compare reference geometry with the geometry field of the feature type. Why do you think that the filter that works directly against GeoServer is not usable in OWSLib? You can also look at the MapServer examples mapserver.org/ogc/filter_encoding.html?. There is an intersects example as well, the filter used in it should work as filterxml.
    – user30184
    Oct 29, 2020 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.