Changeset 509

Show
Ignore:
Timestamp:
10/17/06 12:49:59
Author:
seang
Message:

test for, and implement accessors for content bounding boxes and crs options

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • OWSLib/trunk/owslib/interfaces.py

    r508 r509  
    109109    boundingBoxWGS84 : 4-tuple 
    110110        Four bounding values in WGS coordinates. 
    111     formatOptions : list 
    112         List of available formats, each a string. 
    113111    crsOptions : list 
    114112        List of available coordinate/spatial reference systems. 
  • OWSLib/trunk/owslib/wms.py

    r508 r509  
    9595        self.service = self._root.find('Service/Name').text 
    9696        self.title = self._root.find('Service/Title').text 
     97         
    9798        # operations [] 
    98         # contents [] 
     99         
     100        # contents: our assumption is that services use a top-level layer 
     101        # as a metadata organizer, nothing more. 
    99102        self.contents = [] 
     103        top = self._root.find('Capability/Layer') 
    100104        for elem in self._root.findall('Capability/Layer/Layer'): 
    101             self.contents.append(ContentMetadata(elem)) 
     105            self.contents.append(ContentMetadata(elem, top)) 
    102106          
     107    def getContentByName(self, name): 
     108        """Return a named content item.""" 
     109        for item in self.contents: 
     110            if item.name == name: 
     111                return item 
     112        raise KeyError, "No content named %s" % name 
     113 
     114    def getOperationByName(self, name): 
     115        """Return a named content item.""" 
     116        for item in self.operations: 
     117            if item.name == name: 
     118                return item 
     119        raise KeyError, "No operation named %s" % name 
    103120 
    104121    #def toXML(self): 
     
    116133    """ 
    117134 
    118     def __init__(self, element): 
     135    def __init__(self, elem, parent): 
    119136        """.""" 
    120         self.name = element.find('Name').text 
    121         self.title = element.find('Title').text 
    122          
    123  
     137        self.name = elem.find('Name').text 
     138        self.title = elem.find('Title').text 
     139        # bboxes 
     140        self.boundingBox = None 
     141        b = elem.find('BoundingBox') 
     142        if b is not None: 
     143            self.boundingBox = (float(b.attrib['minx']),float(b.attrib['miny']), 
     144                    float(b.attrib['maxx']), float(b.attrib['maxy']), 
     145                    b.attrib['SRS']) 
     146        else: 
     147            b = parent.find('BoundingBox') 
     148            if b is not None: 
     149                self.boundingBox = ( 
     150                        float(b.attrib['minx']), float(b.attrib['miny']), 
     151                        float(b.attrib['maxx']), float(b.attrib['maxy']), 
     152                        b.attrib['SRS']) 
     153        self.boundingBoxWGS84 = None 
     154        b = elem.find('LatLonBoundingBox') 
     155        if b is not None: 
     156            self.boundingBoxWGS84 = ( 
     157                    float(b.attrib['minx']),float(b.attrib['miny']), 
     158                    float(b.attrib['maxx']), float(b.attrib['maxy']), 
     159                    ) 
     160        else: 
     161            b = parent.find('LatLonBoundingBox') 
     162            if b is not None: 
     163                self.boundingBoxWGS84 = ( 
     164                        float(b.attrib['minx']), float(b.attrib['miny']), 
     165                        float(b.attrib['maxx']), float(b.attrib['maxy']), 
     166                        ) 
     167        # crs options 
     168        self.crsOptions = [srs.text for srs in parent.findall('SRS')] 
     169         
     170         
    124171class WMSCapabilitiesInfoset: 
    125172    """High-level container for WMS Capabilities based on lxml.etree 
  • OWSLib/trunk/tests/WMSCapabilities.txt

    r508 r509  
    3636    'JPL Global Imagery Service' 
    3737     
    38 Test available layers 
     38Test available content layers 
    3939 
    4040    >>> [layer.name for layer in wms.capabilities.contents] 
     
    4343    ['WMS Global Mosaic, pan sharpened', 'WMS Global Mosaic, not pan sharpened', 'CONUS mosaic of 1990 MRLC dataset', 'SRTM reflectance magnitude, 30m', 'Daily composite of MODIS-TERRA 721 pseudocolor', 'Daily composite of MODIS-AQUA 721 pseudocolor', 'Daily composite of MODIS-TERRA images, NDVI processing', 'Daily composite of MODIS-AQUA images, NDVI processing', 'Daily composite of MODIS-TERRA images', 'Daily composite of MODIS-AQUA images', 'Blue Marble Next Generation, Global MODIS derived image', 'Blue Marble, Global MODIS derived image', 'SRTM derived global elevation, 3 arc-second, hue mapped', 'Global 1km elevation, seamless SRTM land elevation and ocean depth', 'SRTM derived global elevation, 3 arc-second', 'United States elevation, 30m', 'Digital Elevation Map of the United States, DTED dataset, 3 second resolution, grayscale', 'Digital Elevation Map of the United States, DTED dataset, 3 second resolution, hue mapped'] 
    4444     
    45      
     45Test single item accessor 
     46 
     47    >>> wms.capabilities.getContentByName('global_mosaic').title 
     48    'WMS Global Mosaic, pan sharpened' 
     49    >>> wms.capabilities.getContentByName('global_mosaic').boundingBox 
     50    >>> wms.capabilities.getContentByName('global_mosaic').boundingBoxWGS84 
     51    (-180.0, -60.0, 180.0, 84.0) 
     52    >>> wms.capabilities.getContentByName('global_mosaic').crsOptions 
     53    ['EPSG:4326', 'AUTO:42003'] 
     54 
     55Expect a KeyError for invalid names 
     56 
     57    >>> wms.capabilities.getContentByName('utterly bogus').title 
     58    Traceback (most recent call last): 
     59    ... 
     60    KeyError: 'No content named utterly bogus' 
     61