Changeset 508
- Timestamp:
- 10/17/06 11:48:47
- Files:
-
- OWSLib/trunk/owslib/interfaces.py (modified) (4 diffs)
- OWSLib/trunk/owslib/wms.py (modified) (2 diffs)
- OWSLib/trunk/tests/JPLCapabilities.xml (added)
- OWSLib/trunk/tests/WMSCapabilities.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
OWSLib/trunk/owslib/interfaces.py
r507 r508 10 10 version : string 11 11 WMS protocol version. 12 metadata: object13 Describes the metadata (formerly called capabilities)of the WMS.12 capabilities : object 13 Describes the capabilities metadata of the WMS. 14 14 """ 15 15 … … 65 65 """ 66 66 67 class IOperation sMetadata:67 class IOperationMetadata: 68 68 """OO-interface to WMS metadata. 69 69 … … 87 87 """ 88 88 89 class I ContentsMetadata:89 class IServiceContentsMetadata: 90 90 """OO-interface to WMS metadata. 91 91 … … 115 115 """ 116 116 117 class IServiceMetadata(IServiceIdentificationMetadata, IServiceProvideMetadata, 118 IServiceOperationsMetadata, IServiceContentsMetadata): 119 """OWS Metadata. 120 """ 121 OWSLib/trunk/owslib/wms.py
r379 r508 25 25 26 26 import cgi 27 import sys 27 28 import urllib 28 from etree import etree 29 30 from owslib.etree import etree 29 31 30 32 class WMSError(Exception): … … 53 55 54 56 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) 57 class 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 84 class 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 112 class 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 64 123 65 124 class WMSCapabilitiesInfoset: OWSLib/trunk/tests/WMSCapabilities.txt
r506 r508 23 23 >>> from owslib.wms import WebMapService 24 24 25 Connect to a WMS Server 25 Fake a request to a WMS Server using saved doc from 26 http://wms.jpl.nasa.gov/wms.cgi. 26 27 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) 28 30 29 Get capabilities31 Test capabilities 30 32 31 >>> wms.capabilities. name33 >>> wms.capabilities.service 32 34 'OGC:WMS' 33 35 >>> 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' 37 37 38 Check the layers38 Test available layers 39 39 40 >>> [layer.name for layer in wms.capabilities. layers]40 >>> [layer.name for layer in wms.capabilities.contents] 41 41 ['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'] 44 44 45
