OWSLib 0.1.0

2006-10-19T18:15:50Z | Comments: 1

Landsat mosaic, Colorado Plateau

Uploaded: http://cheeseshop.python.org/pypi/OWSLib/0.1.0.

OWSLib is a Python package for working with OGC web map and feature services. It provides a common API for accessing service metadata and wrappers for GetCapabilities, GetMap, and GetFeature requests.

It's the work on this software that made me so grumpy about WFS yesterday. OWSLib is designed to forward imagery and feature responses to the user, and raise an exception in the case of a W*S service exception. It would be nice to be able to do this just by inspecting response headers, without looking in the data, but that's not possible in the WFS case. My solution is to waive large data through, assuming success, and only check smaller responses. I think this will generally work, though it could be spoiled by enormous tracebacks that make their way into service exception messages.

There is no GML parsing in OWSLib. WebMapService.getmap and WebFeatureService.getfeature return imagery and XML. OWSLib does parse service metadata, and can be used to find out what a WMS or WFS has to offer. For example:

>>> from owslib.wms import WebMapService
>>> wms = WebMapService('http://wms.jpl.nasa.gov/wms.cgi', version='1.1.1')
>>> wms.capabilities.service
'OGC:WMS'
>>> wms.capabilities.title
'JPL Global Imagery Service'

Available layers:

>>> [layer.name for layer in wms.capabilities.contents]
['global_mosaic', 'global_mosaic_base', ... ]

Details of a layer:

>>> wms.capabilities.getContentByName('global_mosaic').title
'WMS Global Mosaic, pan sharpened'
>>> wms.capabilities.getContentByName('global_mosaic').boundingBox
>>> wms.capabilities.getContentByName('global_mosaic').boundingBoxWGS84
(-180.0, -60.0, 180.0, 84.0)
>>> wms.capabilities.getContentByName('global_mosaic').crsOptions
['EPSG:4326', 'AUTO:42003']
>>> wms.capabilities.getContentByName('global_mosaic').styles
{ ...,
  'visual_bright': {
      'title': 'Real-color image (Uses the visual bands, 321 mapping), gamma 1.5'
      }
  }

Available methods, their URLs, and available formats:

>>> [op.name for op in wms.capabilities.operations]
['GetCapabilities', 'GetMap']
>>> wms.capabilities.getOperationByName('GetMap').methods
{'Get': {'url': 'http://wms.jpl.nasa.gov/wms.cgi?'}}
>>> wms.capabilities.getOperationByName('GetMap').formatOptions
['image/jpeg', 'image/png', 'image/geotiff', 'image/tiff']

That's everything needed to make a request for imagery:

>>> img = wms.getmap(   layers=['global_mosaic'],
...                     styles=['visual_bright'],
...                     srs='EPSG:4326',
...                     bbox=(-112, 36, -106, 41),
...                     size=(300, 250),
...                     format='image/jpeg',
...                     transparent=True
...                     )
>>> out = open('jpl_mosaic_visb.jpg', 'wb')
>>> out.write(img.read())
>>> out.close()

Categories: The Lab

del.icio.us

Comments

Re: OWSLib 0.1.0

Excellent!

Thanks,
Joel
By: Joel, 2006-10-19T19:16:12Z

Comments are closed after 13 days.