Skip to content

Commit

Permalink
Merge pull request #945 from SearcherSeismicGeodata/wfs_getfeature_srs
Browse files Browse the repository at this point in the history
Add srsname to wfs200.py getfeature GET request
  • Loading branch information
geographika authored Oct 10, 2024
2 parents d4e7080 + d14d447 commit 852fe6d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 59 deletions.
10 changes: 10 additions & 0 deletions owslib/feature/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def getGETGetFeatureRequest(
featureversion=None,
propertyname=None,
maxfeatures=None,
srsname=None,
storedQueryID=None,
storedQueryParams=None,
outputFormat=None,
Expand All @@ -183,6 +184,8 @@ def getGETGetFeatureRequest(
List of feature property names. '*' matches all.
maxfeatures : int
Maximum number of features to be returned.
srsname: string
EPSG code to request the data in
method : string
Qualified name of the HTTP DCP method to use.
outputFormat: string (optional)
Expand Down Expand Up @@ -238,6 +241,13 @@ def getGETGetFeatureRequest(
request["count"] = str(maxfeatures)
else:
request["maxfeatures"] = str(maxfeatures)
if srsname:
request["srsname"] = str(srsname)

# Check if desired SRS is supported by the service for each
# typename. Warning will be thrown if that SRS is not allowed.
for name in typename:
_ = self.getSRS(srsname, name)
if startindex:
request["startindex"] = str(startindex)
if storedQueryID:
Expand Down
4 changes: 4 additions & 0 deletions owslib/feature/wfs200.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ def getfeature(
featureversion=None,
propertyname=None,
maxfeatures=None,
srsname=None,
storedQueryID=None,
storedQueryParams=None,
method="Get",
Expand Down Expand Up @@ -254,6 +255,8 @@ def getfeature(
For Post request, leave blank (None) to get all properties.
maxfeatures : int
Maximum number of features to be returned.
srsname: string
EPSG code to request the data in
storedQueryID : string
A name identifying a prepared set available in WFS-service
storedQueryParams : dict
Expand Down Expand Up @@ -298,6 +301,7 @@ def getfeature(
featureversion,
propertyname,
maxfeatures,
srsname,
storedQueryID,
storedQueryParams,
outputFormat,
Expand Down
109 changes: 50 additions & 59 deletions tests/test_wfs_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import json
import pytest

SERVICE_URL = 'https://www.sciencebase.gov/catalogMaps/mapping/ows/53398e51e4b0db25ad10d288'

SERVICE_URL = 'https://services.ga.gov.au/gis/stratunits/ows'

def test_caps_info():
getcapsin = open(resource_file("wfs_HSRS_GetCapabilities_1_1_0.xml"), "rb").read()
Expand Down Expand Up @@ -59,59 +58,50 @@ def test_verbOptions_wfs_100():
assert len(verbOptions[0]) == 2


@pytest.mark.xfail
@pytest.mark.online
@pytest.mark.skipif(not service_ok(SERVICE_URL),
reason="WFS service is unreachable")
def test_outputformat_wfs_100():
wfs = WebFeatureService('https://www.sciencebase.gov/catalogMaps/mapping/ows/53398e51e4b0db25ad10d288',
version='1.0.0')
wfs = WebFeatureService(SERVICE_URL, version='1.0.0')
feature = wfs.getfeature(
typename=['sb:Project_Area'], maxfeatures=1, propertyname=None, outputFormat='application/json')
typename=['stratunit:StratigraphicUnit'], maxfeatures=1, propertyname=None, outputFormat='application/json')
assert len(json.loads(feature.read())['features']) == 1


@pytest.mark.xfail
@pytest.mark.online
@pytest.mark.skipif(not service_ok(SERVICE_URL),
reason="WFS service is unreachable")
def test_outputformat_wfs_110():
wfs = WebFeatureService('https://www.sciencebase.gov/catalogMaps/mapping/ows/53398e51e4b0db25ad10d288',
version='1.1.0')
wfs = WebFeatureService(SERVICE_URL, version='1.1.0')
feature = wfs.getfeature(
typename=['sb:Project_Area'], maxfeatures=1, propertyname=None, outputFormat='application/json')
typename=['stratunit:StratigraphicUnit'], maxfeatures=1, propertyname=None, outputFormat='application/json')
assert len(json.loads(feature.read())['features']) == 1


@pytest.mark.xfail
@pytest.mark.online
@pytest.mark.skipif(not service_ok(SERVICE_URL),
reason="WFS service is unreachable")
def test_outputformat_wfs_200():
wfs = WebFeatureService('https://www.sciencebase.gov/catalogMaps/mapping/ows/53398e51e4b0db25ad10d288',
version='2.0.0')
wfs = WebFeatureService(SERVICE_URL, version='2.0.0')
feature = wfs.getfeature(
typename=['sb:Project_Area'], maxfeatures=1, propertyname=None, outputFormat='application/json')
typename=['stratunit:StratigraphicUnit'], maxfeatures=1, propertyname=None, outputFormat='application/json')
assert len(json.loads(feature.read())['features']) == 1


@pytest.mark.xfail
@pytest.mark.online
@pytest.mark.skipif(not service_ok(SERVICE_URL),
reason="WFS service is unreachable")
def test_srsname_wfs_100():
wfs = WebFeatureService('https://www.sciencebase.gov/catalogMaps/mapping/ows/53398e51e4b0db25ad10d288',
version='1.0.0')
wfs = WebFeatureService(SERVICE_URL, version='1.0.0')
# ServiceException: Unable to support srsName: EPSG:99999999
with pytest.raises(ServiceException):
feature = wfs.getfeature(
typename=['sb:Project_Area'], maxfeatures=1, propertyname=None, outputFormat='application/json',
typename=['stratunit:StratigraphicUnit'], maxfeatures=1, propertyname=None, outputFormat='application/json',
srsname="EPSG:99999999")

wfs = WebFeatureService('https://www.sciencebase.gov/catalogMaps/mapping/ows/53398e51e4b0db25ad10d288',
version='1.0.0')
wfs = WebFeatureService(SERVICE_URL, version='1.0.0')
feature = wfs.getfeature(
typename=['sb:Project_Area'], maxfeatures=1, propertyname=None, outputFormat='application/json',
typename=['stratunit:StratigraphicUnit'], maxfeatures=1, propertyname=None, outputFormat='application/json',
srsname="urn:x-ogc:def:crs:EPSG:4326")
assert len(json.loads(feature.read())['features']) == 1

Expand All @@ -121,73 +111,76 @@ def test_srsname_wfs_100():
@pytest.mark.skipif(not service_ok(SERVICE_URL),
reason="WFS service is unreachable")
def test_srsname_wfs_110():
wfs = WebFeatureService(
'https://www.sciencebase.gov/catalogMaps/mapping/ows/53398e51e4b0db25ad10d288',
version='1.1.0')
wfs = WebFeatureService(SERVICE_URL, version='1.1.0')
# ServiceException: Unable to support srsName: EPSG:99999999
with pytest.raises(ServiceException):
feature = wfs.getfeature(
typename=['sb:Project_Area'], maxfeatures=1, propertyname=None, outputFormat='application/json',
typename=['stratunit:StratigraphicUnit'], maxfeatures=1, propertyname=None, outputFormat='application/json',
srsname="EPSG:99999999")

wfs = WebFeatureService(
'https://www.sciencebase.gov/catalogMaps/mapping/ows/53398e51e4b0db25ad10d288',
version='1.0.0')
wfs = WebFeatureService(SERVICE_URL, version='1.1.0')
feature = wfs.getfeature(
typename=['sb:Project_Area'], maxfeatures=1, propertyname=None, outputFormat='application/json',
typename=['stratunit:StratigraphicUnit'], maxfeatures=1, propertyname=None, outputFormat='application/json',
srsname="urn:x-ogc:def:crs:EPSG:4326")
assert len(json.loads(feature.read())['features']) == 1


@pytest.mark.online
@pytest.mark.skipif(not service_ok(SERVICE_URL),
reason="WFS service is unreachable")
def test_srsname_wfs_200():
wfs = WebFeatureService(SERVICE_URL, version='2.0.0')
# ServiceException: Unable to support srsName: EPSG:99999999
with pytest.raises(ServiceException):
feature = wfs.getfeature(
typename=['stratunit:StratigraphicUnit'], maxfeatures=1, propertyname=None, outputFormat='application/json',
srsname="EPSG:99999999")

wfs = WebFeatureService(SERVICE_URL, version='2.0.0')
feature = wfs.getfeature(
typename=['stratunit:StratigraphicUnit'], maxfeatures=1, propertyname=None, outputFormat='application/json',
srsname="urn:x-ogc:def:crs:EPSG:4326")
assert len(json.loads(feature.read())['features']) == 1


@pytest.mark.xfail
@pytest.mark.online
@pytest.mark.skipif(not service_ok(SERVICE_URL),
reason="WFS service is unreachable")
def test_schema_wfs_100():
wfs = WebFeatureService(
'https://www.sciencebase.gov/catalogMaps/mapping/ows/53398e51e4b0db25ad10d288',
version='1.0.0')
schema = wfs.get_schema('footprint')
assert len(schema['properties']) == 4
assert schema['properties']['summary'] == 'string'
assert schema['geometry'] == 'Polygon'
wfs = WebFeatureService(SERVICE_URL, version='1.0.0')
schema = wfs.get_schema('stratunit:StratigraphicUnit')
assert len(schema['properties']) == 33
assert schema['properties']['DESCRIPTION'] == 'string'
assert schema['geometry'] is None


@pytest.mark.xfail
@pytest.mark.online
@pytest.mark.skipif(not service_ok(SERVICE_URL),
reason="WFS service is unreachable")
def test_schema_wfs_110():
wfs = WebFeatureService(
'https://www.sciencebase.gov/catalogMaps/mapping/ows/53398e51e4b0db25ad10d288',
version='1.1.0')
schema = wfs.get_schema('footprint')
assert len(schema['properties']) == 4
assert schema['properties']['summary'] == 'string'
assert schema['geometry'] == '3D Polygon'
wfs = WebFeatureService(SERVICE_URL, version='1.1.0')
schema = wfs.get_schema('stratunit:StratigraphicUnit')
assert len(schema['properties']) == 33
assert schema['properties']['DESCRIPTION'] == 'string'
assert schema['geometry'] is None


@pytest.mark.xfail
@pytest.mark.online
@pytest.mark.skipif(not service_ok(SERVICE_URL),
reason="WFS service is unreachable")
def test_schema_wfs_200():
wfs = WebFeatureService(
'https://www.sciencebase.gov/catalogMaps/mapping/ows/53398e51e4b0db25ad10d288',
version='2.0.0')
schema = wfs.get_schema('footprint')
assert len(schema['properties']) == 4
assert schema['properties']['summary'] == 'string'
assert schema['geometry'] == '3D Polygon'
wfs = WebFeatureService(SERVICE_URL, version='2.0.0')
schema = wfs.get_schema('stratunit:StratigraphicUnit')
assert len(schema['properties']) == 33
assert schema['properties']['DESCRIPTION'] == 'string'
assert schema['geometry'] is None


@pytest.mark.online
@pytest.mark.skipif(not service_ok(SERVICE_URL),
reason="WFS service is unreachable")
def test_xmlfilter_wfs_110():
wfs = WebFeatureService(
'https://services.ga.gov.au/gis/stratunits/ows',
version='1.1.0')
wfs = WebFeatureService(SERVICE_URL, version='1.1.0')
filter_prop = PropertyIsLike(propertyname='stratunit:GEOLOGICHISTORY', literal='Cisuralian - Guadalupian',
matchCase=True)

Expand All @@ -203,9 +196,7 @@ def test_xmlfilter_wfs_110():
@pytest.mark.skipif(not service_ok(SERVICE_URL),
reason="WFS service is unreachable")
def test_xmlfilter_wfs_200():
wfs = WebFeatureService(
'https://services.ga.gov.au/gis/stratunits/ows',
version='2.0.0')
wfs = WebFeatureService(SERVICE_URL, version='2.0.0')
filter_prop = PropertyIsLike(propertyname='stratunit:geologichistory', literal='Cisuralian - Guadalupian',
matchCase=True)

Expand Down

0 comments on commit 852fe6d

Please sign in to comment.