| 1 |
OWSLib |
|---|
| 2 |
====== |
|---|
| 3 |
|
|---|
| 4 |
Package for working with OGC map, feature, and coverage services. |
|---|
| 5 |
|
|---|
| 6 |
OWSLib provides a common API for accessing service metadata and wrappers for |
|---|
| 7 |
GetCapabilities, GetMap, and GetFeature requests. |
|---|
| 8 |
|
|---|
| 9 |
The OWSLib version 0.3 API is incompatible with version 0.2.1. |
|---|
| 10 |
|
|---|
| 11 |
Dependencies |
|---|
| 12 |
------------ |
|---|
| 13 |
|
|---|
| 14 |
OWSLib requires elementtree (standard in 2.5 as xml.etree) or lxml. |
|---|
| 15 |
|
|---|
| 16 |
Usage |
|---|
| 17 |
----- |
|---|
| 18 |
|
|---|
| 19 |
Find out what a WMS has to offer. Service metadata:: |
|---|
| 20 |
|
|---|
| 21 |
>>> from owslib.wms import WebMapService |
|---|
| 22 |
>>> wms = WebMapService('http://wms.jpl.nasa.gov/wms.cgi', version='1.1.1') |
|---|
| 23 |
>>> wms.identification.type |
|---|
| 24 |
'OGC:WMS' |
|---|
| 25 |
>>> wms.identification.version |
|---|
| 26 |
'1.1.1' |
|---|
| 27 |
>>> wms.identification.title |
|---|
| 28 |
'JPL Global Imagery Service' |
|---|
| 29 |
>>> wms.identification.abstract |
|---|
| 30 |
'WMS Server maintained by JPL, worldwide satellite imagery.' |
|---|
| 31 |
|
|---|
| 32 |
Available layers:: |
|---|
| 33 |
|
|---|
| 34 |
>>> list(wms.contents) |
|---|
| 35 |
['us_landsat_wgs84', 'modis', 'global_mosaic_base', 'huemapped_srtm', |
|---|
| 36 |
'srtm_mag', 'daily_terra', 'us_ned', 'us_elevation', 'global_mosaic', |
|---|
| 37 |
'daily_terra_ndvi', 'daily_aqua_ndvi', 'daily_aqua_721', 'daily_planet', |
|---|
| 38 |
'BMNG', 'srtmplus', 'us_colordem', None, 'daily_aqua', 'worldwind_dem', |
|---|
| 39 |
'daily_terra_721'] |
|---|
| 40 |
|
|---|
| 41 |
Details of a layer:: |
|---|
| 42 |
|
|---|
| 43 |
>>> wms['global_mosaic'].title |
|---|
| 44 |
'WMS Global Mosaic, pan sharpened' |
|---|
| 45 |
>>> wms['global_mosaic'].boundingBoxWGS84 |
|---|
| 46 |
(-180.0, -60.0, 180.0, 84.0) |
|---|
| 47 |
>>> wms['global_mosaic'].crsOptions |
|---|
| 48 |
['EPSG:4326', 'AUTO:42003'] |
|---|
| 49 |
>>> wms['global_mosaic'].styles |
|---|
| 50 |
{'pseudo_bright': {'title': 'Pseudo-color image (Uses IR and Visual bands, |
|---|
| 51 |
542 mapping), gamma 1.5'}, 'pseudo': {'title': '(default) Pseudo-color |
|---|
| 52 |
image, pan sharpened (Uses IR and Visual bands, 542 mapping), gamma 1.5'}, |
|---|
| 53 |
'visual': {'title': 'Real-color image, pan sharpened (Uses the visual |
|---|
| 54 |
bands, 321 mapping), gamma 1.5'}, 'pseudo_low': {'title': 'Pseudo-color |
|---|
| 55 |
image, pan sharpened (Uses IR and Visual bands, 542 mapping)'}, |
|---|
| 56 |
'visual_low': {'title': 'Real-color image, pan sharpened (Uses the visual |
|---|
| 57 |
bands, 321 mapping)'}, 'visual_bright': {'title': 'Real-color image (Uses |
|---|
| 58 |
the visual bands, 321 mapping), gamma 1.5'}} |
|---|
| 59 |
|
|---|
| 60 |
Available methods, their URLs, and available formats:: |
|---|
| 61 |
|
|---|
| 62 |
>>> [op.name for op in wms.operations] |
|---|
| 63 |
['GetTileService', 'GetCapabilities', 'GetMap'] |
|---|
| 64 |
>>> wms.getOperationByName('GetMap').methods |
|---|
| 65 |
{'Get': {'url': 'http://wms.jpl.nasa.gov/wms.cgi?'}} |
|---|
| 66 |
>>> wms.getOperationByName('GetMap').formatOptions |
|---|
| 67 |
['image/jpeg', 'image/png', 'image/geotiff', 'image/tiff'] |
|---|
| 68 |
|
|---|
| 69 |
That's everything needed to make a request for imagery:: |
|---|
| 70 |
|
|---|
| 71 |
>>> img = wms.getmap( layers=['global_mosaic'], |
|---|
| 72 |
... styles=['visual_bright'], |
|---|
| 73 |
... srs='EPSG:4326', |
|---|
| 74 |
... bbox=(-112, 36, -106, 41), |
|---|
| 75 |
... size=(300, 250), |
|---|
| 76 |
... format='image/jpeg', |
|---|
| 77 |
... transparent=True |
|---|
| 78 |
... ) |
|---|
| 79 |
>>> out = open('jpl_mosaic_visb.jpg', 'wb') |
|---|
| 80 |
>>> out.write(img.read()) |
|---|
| 81 |
>>> out.close() |
|---|
| 82 |
|
|---|
| 83 |
A very similar API exists for WebFeatureService. See |
|---|
| 84 |
tests/MapServerWFSCapabilities.txt for details. |
|---|
| 85 |
|
|---|
| 86 |
Known Issues |
|---|
| 87 |
------------ |
|---|
| 88 |
|
|---|
| 89 |
OWSLib works with WMS version 1.1.1 and WFS 1.0.0 Other versions are not |
|---|
| 90 |
supported at this time. |
|---|
| 91 |
|
|---|
| 92 |
Support |
|---|
| 93 |
------- |
|---|
| 94 |
|
|---|
| 95 |
OWSLib shares a wiki and email list with the Python Cartographic Library: |
|---|
| 96 |
|
|---|
| 97 |
http://lists.gispython.org/mailman/listinfo/community |
|---|
| 98 |
|
|---|
| 99 |
http://trac.gispython.org/projects/PCL/wiki |
|---|
| 100 |
|
|---|
| 101 |
Updated project information can be found at |
|---|
| 102 |
|
|---|
| 103 |
http://trac.gispython.org/projects/PCL/wiki/OwsLib |
|---|