[OWSLib-users] How to add a filter to a joined getfeature request.

Tom Kralidis tomkralidis at gmail.com
Fri Aug 23 00:44:53 PDT 2019


Hi Tyler: I was able to reproduce, are you able to provide an example
WFS request that works so we can see what you are trying to achieve?

On Tue, Aug 20, 2019 at 1:55 AM Tyler McCamley <tyler at eaglehire.com> wrote:
>
> Hi Tom,
>
>
>
> Here is the test code below, I’ve provided both ways of attempting to filter.
>
>
>
> Test code:
>
>
>
> def start_wfs():
>     import owslib.fes as fes
>     from owslib.wfs import WebFeatureService
>     from owslib.etree import etree
>     import csv
>
>     wfs = WebFeatureService(
>         'http://services.land.vic.gov.au/catalogue/publicproxy/guest/dv_geoserver/wfs?request=getCapabilities',
>         version='2.0.0')
>
>     filter_table_1 = fes.PropertyIsEqualTo(propertyname='PROPERTY_PFI', literal='151697865')
>     filter_table_2 = fes.PropertyIsEqualTo(propertyname='PROPERTY_PFI', literal='151697865')
>
>     # fes Filters
>     join_filter = fes.And([filter_table_1, filter_table_2])
>     filterxml = etree.tostring(join_filter.toXML()).decode("utf-8")
>
>     # XML Filter
>     xml_test = '<Filter>' \
>                '<And>' \
>                '<PropertyIsEqualTo>' \
>                '<ValueReference>datavic:VMADD_ADDRESS/PROPERTY_PFI</ValueReference>' \
>                '<ValueReference>datavic:VMPROP_PARCEL_PROPERTY/PROPERTY_PFI</ValueReference>' \
>                '</PropertyIsEqualTo>' \
>                '</And>' \
>                '</Filter>'
>
>     response = wfs.getfeature(typename=['datavic:VMADD_ADDRESS', 'datavic:VMPROP_PARCEL_PROPERTY'],  # Table to query
>                               filter=xml_test,  # Which filter to use
>                               maxfeatures=200,  # Max of rows returned
>                               outputFormat='csv')
>
>     reader = csv.reader(response)
>     print([r for r in reader])
>     print(response.getvalue())
>
> start_wfs()
>
>
>
>
>
> Error:
>
> Traceback (most recent call last):
>
>   File "C:/Users/Tyler/PycharmProjects/MAINGUIV2/MainGui.py", line 39, in <module>
>
>     start_wfs()
>
>   File "C:/Users/Tyler/PycharmProjects/MAINGUIV2/MainGui.py", line 33, in start_wfs
>
>     outputFormat='csv')
>
>   File "C:\Users\Tyler\PycharmProjects\MAINGUIV2\venv\lib\site-packages\owslib\feature\wfs200.py", line 238, in getfeature
>
>     u = openURL(url, data, method, timeout=self.timeout, auth=self.auth)
>
>   File "C:\Users\Tyler\PycharmProjects\MAINGUIV2\venv\lib\site-packages\owslib\util.py", line 224, in openURL
>
>     raise ServiceException('\n'.join([encode_string(t).strip() for t in serviceException.itertext() if encode_string(t).strip()]))
>
> owslib.util.ServiceException: Join query must specify a filter
>
>
>
> Process finished with exit code 1
>
>
>
> Kind Regards,
>
> Tyler McCamley
>
> From: Tom Kralidis <tom.kralidis at gmail.com> On Behalf Of Tom Kralidis
> Sent: Tuesday, 20 August 2019 3:43 PM
> To: Tyler McCamley <tyler at eaglehire.com>
> Cc: owslib-users at lists.osgeo.org
> Subject: Re: [OWSLib-users] How to add a filter to a joined getfeature request.
>
>
>
> Hi Tyler: can you provide a test case that can be reproduced?
>
>
>
> ..Tom
>
>
>
> Sent from my iPhone
>
>
> On Aug 19, 2019, at 09:21, Tyler McCamley <tyler at eaglehire.com> wrote:
>
> Hi,
>
>
>
> I keep getting the ”owslib.util.ServiceException: Join query must specify a filter” exception despite using the filter= parameter in the getfeature function. Any help in the correct syntax to use or where to place this additional filter is much appreciated.
>
>
>
> Example:
>
>
>
> response = wfs.getfeature(typename=['datavic:VMADD_ADDRESS', 'datavic:VMPROP_PARCEL_PROPERTY'],
>                           filter=xml_test,
>                           maxfeatures=200,
>                           outputFormat='csv')
>
>
>
> Kind Regards,
> Tyler M
>
> _______________________________________________
> OWSLib-users mailing list
> OWSLib-users at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/owslib-users


More information about the OWSLib-users mailing list