Skip to content

Commit

Permalink
Merge pull request #7 from QuLogic/domain-of-validity
Browse files Browse the repository at this point in the history
Fix domain of validity XML searching
  • Loading branch information
rhattersley authored Jun 7, 2017
2 parents 9a90e40 + da1d98a commit a69766a
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions pyepsg.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,10 @@ def domain_of_validity(self):
For example::
>>> print(get(21781).domain_of_validity())
[5.97, 10.49, 45.83, 47.81]
[5.96, 10.49, 45.82, 47.81]
"""
# TODO: Check for gmd:EX_GeographicBoundingBox and blow up otherwise.
# TODO: Generalise interface to return a polygon? (Can we find
# something that uses a polygon instead?)
domain = self.element.find(GML_NS + 'domainOfValidity')
Expand All @@ -204,17 +203,17 @@ def domain_of_validity(self):
xml = requests.get(url).content
gml = ET.fromstring(xml)

def extract_bound(i, tag):
# TODO: Figure out if this is our problem or ET's.
# `find` isn't returning anything :(
# ns = '{http://www.isotc211.org/2005/gmd}'
# bound = gml.find(ns + tag)
bound = gml[1][0][1][0][i]
return float(bound[0].text)
def extract_bound(tag):
ns = '{http://www.isotc211.org/2005/gmd}'
xpath = './/{ns}EX_GeographicBoundingBox/{ns}{tag}/'.format(
ns=ns,
tag=tag)
bound = gml.find(xpath)
return float(bound.text)

tags = ('westBoundLongitude', 'eastBoundLongitude',
'southBoundLatitude', 'northBoundLatitude')
bounds = [extract_bound(i, tag) for i, tag in enumerate(tags)]
bounds = [extract_bound(tag) for tag in tags]
return bounds


Expand Down

0 comments on commit a69766a

Please sign in to comment.