Permalink
Browse files

Added basic support for parsing bounds that are polygons instead of m…

…inimum bounding rects to iso.py. This enables parsing of the NOAA ENC Product Catalog. Thanks to Aaron Farnham (https://github.com/tomkralidis/owslib/pull/1)

git-svn-id: https://owslib.svn.sourceforge.net/svnroot/owslib/trunk@1880 b426a367-1105-0410-b9ff-cdf4ab011145
  • Loading branch information...
tomkralidis
tomkralidis committed Jun 9, 2012
1 parent c32bbc2 commit d0cebc86dd031d27c4ab30fabda8b962009cadbd
Showing with 55 additions and 11 deletions.
  1. +55 −11 owslib/iso.py
View
@@ -308,18 +308,16 @@ def __init__(self, md, identtype):
val = md.find(util.nspath_eval('gmd:supplementalInformation/gco:CharacterString', namespaces))
self.supplementalinformation = util.testXMLValue(val)
- # there may be multiple geographicElement, create an extent
- # from the one containing an EX_GeographicBoundingBox
+ # There may be multiple geographicElement, create an extent
+ # from the one containing either an EX_GeographicBoundingBox or EX_BoundingPolygon.
+ # The schema also specifies an EX_GeographicDescription. This is not implemented yet.
val = None
for e in md.findall(util.nspath_eval('gmd:extent/gmd:EX_Extent/gmd:geographicElement', namespaces)):
- if e.find(util.nspath_eval('gmd:EX_GeographicBoundingBox', namespaces)) is not None:
+ if e.find(util.nspath_eval('gmd:EX_GeographicBoundingBox', namespaces)) is not None or e.find(util.nspath_eval('gmd:EX_BoundingPolygon', namespaces)) is not None:
val = e
break
-
- if val is not None:
- self.bbox = EX_Extent(val)
- else:
- self.bbox = None
+ self.extent = EX_Extent(e)
+ self.bbox = self.extent.boundingBox #for backwards compatibility
val = md.find(util.nspath_eval('gmd:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:beginPosition', namespaces))
self.temporalextent_start = util.testXMLValue(val)
@@ -447,8 +445,8 @@ def __init__(self,md):
self.function = _testCodeListValue(md.find(util.nspath_eval('gmd:function/gmd:CI_OnLineFunctionCode', namespaces)))
-class EX_Extent(object):
- """ process EX_Extent """
+
+class EX_GeographicBoundingBox(object):
def __init__(self, md):
val = md.find(util.nspath_eval('gmd:EX_GeographicBoundingBox/gmd:westBoundLongitude/gco:Decimal', namespaces))
self.minx = util.testXMLValue(val)
@@ -458,7 +456,52 @@ def __init__(self, md):
self.miny = util.testXMLValue(val)
val = md.find(util.nspath_eval('gmd:EX_GeographicBoundingBox/gmd:northBoundLatitude/gco:Decimal', namespaces))
self.maxy = util.testXMLValue(val)
-
+
+class EX_Polygon(object):
+ def __init__(self, md):
+ linear_ring = md.find(util.nspath_eval('gml32:Polygon/gml32:exterior/gml32:LinearRing', namespaces))
+ if linear_ring is not None:
+ self.exterior_ring = self._coordinates_for_ring(linear_ring)
+
+ interior_ring_elements = md.findall(util.nspath_eval('gml32:Polygon/gml32:interior', namespaces))
+ self.interior_rings = []
+ for iring_element in interior_ring_elements:
+ linear_ring = iring_element.find(util.nspath_eval('gml32:LinearRing', namespaces))
+ self.interior_rings.append(self._coordinates_for_ring(linear_ring))
+
+ def _coordinates_for_ring(self, linear_ring):
+ coordinates = []
+ positions = linear_ring.findall(util.nspath_eval('gml32:pos', namespaces))
+ for pos in positions:
+ tokens = pos.text.split()
+ coords = tuple([float(t) for t in tokens])
+ coordinates.append(coords)
+ return coordinates
+
+class EX_GeographicBoundingPolygon(object):
+ def __init__(self, md):
+ val = md.find(util.nspath_eval('gmd:extentTypeCode', namespaces))
+ self.is_extent = util.testXMLValue(val)
+
+ md_polygons = md.findall(util.nspath_eval('gmd:polygon', namespaces))
+
+ self.polygons = []
+ for val in md_polygons:
+ self.polygons.append(EX_Polygon(val))
+
+class EX_Extent(object):
+ """ process EX_Extent """
+ def __init__(self, md):
+ self.boundingBox = None
+ self.boundingPolygon = None
+ bboxElement = md.find(util.nspath_eval('gmd:EX_GeographicBoundingBox', namespaces))
+ if bboxElement is not None:
+ self.boundingBox = EX_GeographicBoundingBox(bboxElement)
+
+ polygonElement = md.find(util.nspath_eval('gmd:EX_BoundingPolygon', namespaces))
+ if polygonElement is not None:
+ self.boundingPolygon = EX_GeographicBoundingPolygon(polygonElement)
+
val = md.find(util.nspath_eval('gmd:EX_GeographicDescription/gmd:geographicIdentifier/gmd:MD_Identifier/gmd:code/gco:CharacterString', namespaces))
self.description_code = util.testXMLValue(val)
@@ -527,3 +570,4 @@ def getcodedefinitionidentifiers(self, cdl):
return ids
else:
return None
+

0 comments on commit d0cebc8

Please sign in to comment.