Skip to content

Commit

Permalink
Adding more robust parser for WGS84 bbox for WFS 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jachym committed Jul 4, 2015
1 parent c2fc988 commit 640ed63
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
32 changes: 23 additions & 9 deletions owslib/feature/wfs100.py
Expand Up @@ -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")
Expand Down Expand Up @@ -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'))]

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
@@ -1,3 +1,4 @@
python-dateutil>=1.5
pytz
requests>=2.7
pyproj
2 changes: 1 addition & 1 deletion tests/doctests/csw_pycsw.txt
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/doctests/wfs_MapServerWFSCapabilities.txt
Expand Up @@ -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']
Expand Down

0 comments on commit 640ed63

Please sign in to comment.