Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for WMTS BoundingBoxes #687

Merged
merged 1 commit into from May 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 35 additions & 2 deletions owslib/wmts.py
Expand Up @@ -48,6 +48,7 @@
# Version 1.0.0, document 07-057r7

_ABSTRACT_TAG = _OWS_NS + 'Abstract'
_BOUNDING_BOX_TAG = _OWS_NS + 'BoundingBox'
_IDENTIFIER_TAG = _OWS_NS + 'Identifier'
_LOWER_CORNER_TAG = _OWS_NS + 'LowerCorner'
_OPERATIONS_METADATA_TAG = _OWS_NS + 'OperationsMetadata'
Expand Down Expand Up @@ -659,6 +660,31 @@ def __repr__(self):
return fmt.format(self=self)


class BoundingBox(object):
"""
Represents a BoundingBox element
"""

def __init__(self, elem) -> None:
if elem.tag != _BOUNDING_BOX_TAG:
raise ValueError('%s should be a BoundingBox' % elem)

lc = elem.find(_LOWER_CORNER_TAG)
uc = elem.find(_UPPER_CORNER_TAG)

self.ll = [float(s) for s in lc.text.split()]
self.ur = [float(s) for s in uc.text.split()]

self.crs = elem.attrib.get('crs')
self.extent = (self.ll[0], self.ll[1], self.ur[0], self.ur[1])

def __repr__(self):
fmt = ('<BoundingBox'
', crs={self.crs}'
', extent={self.extent}>')
return fmt.format(self=self)


class ContentMetadata:
"""
Abstraction for WMTS layer metadata.
Expand All @@ -684,9 +710,16 @@ def __init__(self, elem, parent=None, index=0, parse_remote_metadata=False):

self.abstract = testXMLValue(elem.find(_ABSTRACT_TAG))

# bboxes
# Bounding boxes
# There may be multiple, using different CRSes
self.boundingBox = []

bbs = elem.findall(_BOUNDING_BOX_TAG)
for b in bbs:
self.boundingBox.append(BoundingBox(b))

# WGS84 Bounding box
b = elem.find(_WGS84_BOUNDING_BOX_TAG)
self.boundingBox = None
if b is not None:
lc = b.find(_LOWER_CORNER_TAG)
uc = b.find(_UPPER_CORNER_TAG)
Expand Down