Skip to content

Conversation

huard
Copy link
Contributor

@huard huard commented Jun 14, 2021

This PR allows users to filter WFS requests using spatial filters: Intercepts, Contains, Within, Touches, Disjoint, Overlaps, Equals.

  • Add spatial filters in fes2.py;
  • Create gml:Point object;

Notes

  • Only works with WFS 2.0 and POST.
  • The set_filter method in GetFeature is weird. It expects a GetFeature xml request, instead of just the Filter node. I've added a shortcut to allow passing a filter XML object directly. Suggestions welcome. I suggest that when passing filter to getfeature, we only pass the filter node, not the getfeature node.
  • I've tested it on our own geoserver instance, but unclear how to test this actually works without a live instance somewhere.
  • The implementation bypasses the FilterRequest class, which seemed to target CSW.
  • I used dataclasses, but that's only available from 3.7 onward so added it to dependencies if python < 3.7.

Related

#128

@huard huard requested a review from tomkralidis June 14, 2021 20:36
@huard
Copy link
Contributor Author

huard commented Jun 14, 2021

Example usage:

from owslib.wfs import WebFeatureService
from owslib.fes2 import Intersects
from owslib.gml import Point
import geojson


def test_intersects():
    p = Point(id="qc", srsName="http://www.opengis.net/gml/srs/epsg.xml#4326", pos=[-71, 46])
    f = Intersects(propertyname="the_geom", geometry=p)
    intersects = f.toXML()
    wfs = WebFeatureService("https://pavics.ouranos.ca/geoserver/wfs", version="2.0.0")
    resp = wfs.getfeature(typename="public:canada_admin_boundaries", outputFormat="application/json",
                   propertyname="PRENAME", method="POST", filter=intersects)
    out = geojson.load(resp)
    assert out["totalFeatures"] == 1
    assert out["features"][0]["properties"]["PRENAME"] == "Quebec"

@tomkralidis
Copy link
Member

Thanks @huard. There are no plans to drop 3.6 anytime soon given it is the default Python version on major OSs (i.e. bionic).

@huard
Copy link
Contributor Author

huard commented Jun 17, 2021

Ok, will modify the PR.

@huard
Copy link
Contributor Author

huard commented Jun 17, 2021

As mentioned, at the moment the <Filter> tag is built into each topological filter. I think ideally, users should be able to compose filters with AND, OR operations. This would require a smarter composition mechanism.

@coveralls
Copy link

coveralls commented Jun 30, 2021

Coverage Status

Coverage increased (+0.4%) to 59.155% when pulling 943f40f on huard:topological_filters into 38c88e5 on geopython:master.

@huard
Copy link
Contributor Author

huard commented Jun 30, 2021

@kwilcox @lpinner @jorisvandenbossche Is this what you were looking for in issue #128 ?

@huard
Copy link
Contributor Author

huard commented Jul 5, 2021

@tomkralidis Ready for review.

@tomkralidis tomkralidis merged commit 953a1b5 into geopython:master Jul 5, 2021
@tomkralidis
Copy link
Member

Thanks @huard !

@huard huard deleted the topological_filters branch July 5, 2021 20:08
@GabrielFerrariR
Copy link

is there any provision for stable implementation of geometry types other than Point?

@huard
Copy link
Contributor Author

huard commented Mar 15, 2023

Not from my part. This PR was meant to solve a problem I had.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants