diff --git a/owslib/feature/wfs100.py b/owslib/feature/wfs100.py index 03b6ae0c4..e2ac8e115 100644 --- a/owslib/feature/wfs100.py +++ b/owslib/feature/wfs100.py @@ -23,6 +23,8 @@ from owslib.namespaces import Namespaces from owslib.util import log +import pyproj + n = Namespaces() WFS_NAMESPACE = n.get_namespace("wfs") OGC_NAMESPACE = n.get_namespace("ogc") @@ -295,18 +297,30 @@ def __init__(self, elem, parent, parse_remote_metadata=False, timeout=30): # bboxes self.boundingBox = None - b = elem.find(nspath('BoundingBox')) + b = elem.find(nspath('LatLongBoundingBox')) + srs = elem.find(nspath('SRS')) + if b is not None: self.boundingBox = (float(b.attrib['minx']),float(b.attrib['miny']), - float(b.attrib['maxx']), float(b.attrib['maxy']), - b.attrib['SRS']) + float(b.attrib['maxx']), float(b.attrib['maxy']), Crs(srs.text)) + + # transform wgs84 bbox from given default bboxt self.boundingBoxWGS84 = None - b = elem.find(nspath('LatLongBoundingBox')) - if b is not None: - self.boundingBoxWGS84 = ( - float(b.attrib['minx']),float(b.attrib['miny']), - float(b.attrib['maxx']), float(b.attrib['maxy']), - ) + + if b is not None and srs is not None: + wgs84 = pyproj.Proj(init="epsg:4326") + try: + src_srs = pyproj.Proj(init=srs.text) + mincorner = pyproj.transform(src_srs, wgs84, b.attrib['minx'], + b.attrib['miny']) + maxcorner = pyproj.transform(src_srs, wgs84, b.attrib['maxx'], + b.attrib['maxy']) + + self.boundingBoxWGS84 = (mincorner[0], mincorner[1], + maxcorner[0], maxcorner[1]) + except RuntimeError, e: + pass + # crs options self.crsOptions = [Crs(srs.text) for srs in elem.findall(nspath('SRS'))] diff --git a/requirements.txt b/requirements.txt index 508d3032a..e2e066882 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ python-dateutil>=1.5 pytz requests>=2.7 +pyproj diff --git a/tests/doctests/csw_pycsw.txt b/tests/doctests/csw_pycsw.txt index 239602da7..1e5ea1c91 100644 --- a/tests/doctests/csw_pycsw.txt +++ b/tests/doctests/csw_pycsw.txt @@ -11,7 +11,7 @@ Properties '2.0.2' >>> c.identification.title - 'pycsw Geospatial Catalogue OGC CITE demo and Reference Implementation' + 'pycsw OGC CITE demo and Reference Implementation' GetRecords diff --git a/tests/doctests/wfs_MapServerWFSCapabilities.txt b/tests/doctests/wfs_MapServerWFSCapabilities.txt index 3651caa1f..6e3d65609 100644 --- a/tests/doctests/wfs_MapServerWFSCapabilities.txt +++ b/tests/doctests/wfs_MapServerWFSCapabilities.txt @@ -62,9 +62,10 @@ Test single item accessor 'glaciers' >>> wfs['glaciers'].boundingBox + (-11887400000.0, -850889000.0, 557154000.0, 262891000.0, urn:ogc:def:crs:EPSG::3031) >>> cast_tuple_int_list(wfs['glaciers'].boundingBoxWGS84) - [-11887400000, -850889000, 557154000, 262891000] + [-94, 89, 64, 87] >>> [x.getcode() for x in wfs['glaciers'].crsOptions] ['EPSG:3031']