File: test_fes2.py

package info (click to toggle)
owslib 0.35.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,772 kB
  • sloc: xml: 143,288; python: 24,542; makefile: 15
file content (46 lines) | stat: -rw-r--r-- 1,654 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import pytest
from owslib.wfs import WebFeatureService
from owslib import fes2
from owslib.gml import Point
from owslib.namespaces import Namespaces
from owslib import util
import json

n = Namespaces()
FES_NAMESPACE = n.get_namespace("fes")
GML32_NAMESPACE = n.get_namespace("gml32")


SERVICE_URL = "http://soggy.zoology.ubc.ca:8080/geoserver/wfs"


def test_raw_filter():
    """Just inspect the filter object (not embedded in a getfeature request)."""
    point = Point(id="qc", srsName="http://www.opengis.net/gml/srs/epsg.xml#4326", pos=[-71, 46])
    f = fes2.Filter(
        fes2.And([fes2.Intersects(propertyname="the_geom", geometry=point),
                  fes2.PropertyIsLike("name", "value")]
                 )
    )

    xml = f.toXML()

    # Fairly basic test
    xml.find(util.nspath("Filter", FES_NAMESPACE))
    xml.find(util.nspath("And", FES_NAMESPACE))
    xml.find(util.nspath("Intersects", FES_NAMESPACE))
    xml.find(util.nspath("Point", GML32_NAMESPACE))

@pytest.mark.xfail
@pytest.mark.online
def test_filter():
    """A request without filtering will yield 600 entries. With filtering we expect only one.

    Note that this type of topological filtering only works (so far) with WFS 2.0.0 and POST requests.
    """
    wfs = WebFeatureService(SERVICE_URL, version="2.0.0")
    layer = "psf:level4"
    point = Point(id="random", srsName="http://www.opengis.net/gml/srs/epsg.xml#4326", pos=[-129.8, 55.44])
    f = fes2.Filter(fes2.Contains(propertyname="geom", geometry=point))
    r = wfs.getfeature(layer, outputFormat="application/json", method="POST", filter=f.toXML())
    assert json.load(r)["totalFeatures"] == 1