Changeset 508

Show
Ignore:
Timestamp:
10/17/06 11:48:47
Author:
seang
Message:

initial implementation of service metadata and content metadata. tests are passing.

Files:

Legend:

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

    r507 r508  
    1010    version : string 
    1111        WMS protocol version. 
    12     metadata : object 
    13         Describes the metadata (formerly called capabilities) of the WMS. 
     12    capabilities : object 
     13        Describes the capabilities metadata of the WMS. 
    1414    """ 
    1515 
     
    6565    """ 
    6666     
    67 class IOperationsMetadata: 
     67class IOperationMetadata: 
    6868    """OO-interface to WMS metadata. 
    6969 
     
    8787    """ 
    8888 
    89 class IContentsMetadata: 
     89class IServiceContentsMetadata: 
    9090    """OO-interface to WMS metadata. 
    9191 
     
    115115    """ 
    116116 
     117class IServiceMetadata(IServiceIdentificationMetadata, IServiceProvideMetadata, 
     118                       IServiceOperationsMetadata, IServiceContentsMetadata): 
     119    """OWS Metadata. 
     120    """ 
     121 
  • OWSLib/trunk/owslib/wms.py

    r379 r508  
    2525 
    2626import cgi 
     27import sys 
    2728import urllib 
    28 from etree import etree 
     29 
     30from owslib.etree import etree 
    2931 
    3032class WMSError(Exception): 
     
    5355 
    5456 
    55 class WebMapService: 
    56     """x 
    57     """ 
    58     def capabilities_xml(self): 
    59         """x 
    60         """ 
    61         top = etree.Element('a') 
    62         top.text = self.getName() 
    63         return etree.tostring(top) 
     57class WebMapService(object): 
     58    """Abstraction for OGC Web Map Service (WMS). 
     59 
     60    Implements IWebMapService. 
     61    """ 
     62     
     63    def __init__(self, url, version='1.1.1', xml=None): 
     64        """Initialize.""" 
     65        self.url = url 
     66        self.version = version 
     67        self._capabilities = None 
     68        if xml: 
     69            reader = WMSCapabilitiesReader(self.version) 
     70            self._capabilities = ServiceMetadata(reader.readString(xml)) 
     71         
     72    def _getcapproperty(self): 
     73        if not self._capabilities: 
     74            reader = WMSCapabilitiesReader(self.version) 
     75            self._capabilities = ServiceMetadata(reader.read(self.url)) 
     76        return self._capabilities 
     77    capabilities = property(_getcapproperty, None) 
     78             
     79    def getcapabilities(self): 
     80        """Request and return capabilities document from the WMS.""" 
     81        raise NotImplementedError 
     82         
     83 
     84class ServiceMetadata(object): 
     85    """Abstraction for WMS metadata. 
     86     
     87    Implements IServiceMetadata. 
     88    """ 
     89 
     90    def __init__(self, infoset): 
     91        """Initialize from an element tree.""" 
     92        self._root = infoset.getroot() 
     93        #print >> sys.stderr, self._root 
     94        # properties 
     95        self.service = self._root.find('Service/Name').text 
     96        self.title = self._root.find('Service/Title').text 
     97        # operations [] 
     98        # contents [] 
     99        self.contents = [] 
     100        for elem in self._root.findall('Capability/Layer/Layer'): 
     101            self.contents.append(ContentMetadata(elem)) 
     102          
     103 
     104    #def toXML(self): 
     105    #    """x 
     106    #    """ 
     107    #    top = etree.Element('a') 
     108    #    top.text = self.getName() 
     109    #    return etree.tostring(top) 
     110 
     111 
     112class ContentMetadata: 
     113    """Abstraction for WMS metadata. 
     114     
     115    Implements IMetadata. 
     116    """ 
     117 
     118    def __init__(self, element): 
     119        """.""" 
     120        self.name = element.find('Name').text 
     121        self.title = element.find('Title').text 
     122         
    64123 
    65124class WMSCapabilitiesInfoset: 
  • OWSLib/trunk/tests/WMSCapabilities.txt

    r506 r508  
    2323    >>> from owslib.wms import WebMapService 
    2424     
    25 Connect to a WMS Server 
     25Fake a request to a WMS Server using saved doc from  
     26http://wms.jpl.nasa.gov/wms.cgi. 
    2627 
    27     >>> wms = WebMapService('http://wms.jpl.nasa.gov/wms.cgi', version='1.1.1') 
     28    >>> xml = open('JPLCapabilities.xml', 'r').read()  
     29    >>> wms = WebMapService('url', version='1.1.1', xml=xml) 
    2830     
    29 Get capabilities 
     31Test capabilities 
    3032 
    31     >>> wms.capabilities.nam
     33    >>> wms.capabilities.servic
    3234    'OGC:WMS' 
    3335    >>> wms.capabilities.title 
    34     'JPL World Map Service' 
    35     >>> wms.capabilities.formats 
    36     ['image/jpeg', 'image/png', 'image/geotiff', 'image/tiff'] 
     36    'JPL Global Imagery Service' 
    3737     
    38 Check the layers 
     38Test available layers 
    3939 
    40     >>> [layer.name for layer in wms.capabilities.layers] 
     40    >>> [layer.name for layer in wms.capabilities.contents] 
    4141    ['global_mosaic', 'global_mosaic_base', 'us_landsat_wgs84', 'srtm_mag', 'daily_terra_721', 'daily_aqua_721', 'daily_terra_ndvi', 'daily_aqua_ndvi', 'daily_terra', 'daily_aqua', 'BMNG', 'modis', 'huemapped_srtm', 'srtmplus', 'worldwind_dem', 'us_ned', 'us_elevation', 'us_colordem'] 
    42     >>> [layer.title for layer in wms.capabilities.layers] 
    43     [
     42    >>> [layer.title for layer in wms.capabilities.contents] 
     43    ['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