| 25 | | See tests/*.txt, which are doctests. |
|---|
| | 25 | Find out what a WMS has to offer. Service metadata: |
|---|
| | 26 | |
|---|
| | 27 | >>> from owslib.wms import WebMapService |
|---|
| | 28 | >>> wms = WebMapService('http://wms.jpl.nasa.gov/wms.cgi', version='1.1.1') |
|---|
| | 29 | >>> wms.capabilities.service |
|---|
| | 30 | 'OGC:WMS' |
|---|
| | 31 | >>> wms.capabilities.title |
|---|
| | 32 | 'JPL Global Imagery Service' |
|---|
| | 33 | |
|---|
| | 34 | Available layers: |
|---|
| | 35 | |
|---|
| | 36 | >>> [layer.name for layer in wms.capabilities.contents] |
|---|
| | 37 | ['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'] |
|---|
| | 38 | |
|---|
| | 39 | Details of a layer: |
|---|
| | 40 | |
|---|
| | 41 | >>> wms.capabilities.getContentByName('global_mosaic').title |
|---|
| | 42 | 'WMS Global Mosaic, pan sharpened' |
|---|
| | 43 | >>> wms.capabilities.getContentByName('global_mosaic').boundingBox |
|---|
| | 44 | >>> wms.capabilities.getContentByName('global_mosaic').boundingBoxWGS84 |
|---|
| | 45 | (-180.0, -60.0, 180.0, 84.0) |
|---|
| | 46 | >>> wms.capabilities.getContentByName('global_mosaic').crsOptions |
|---|
| | 47 | ['EPSG:4326', 'AUTO:42003'] |
|---|
| | 48 | >>> wms.capabilities.getContentByName('global_mosaic').styles |
|---|
| | 49 | {'pseudo_bright': {'title': 'Pseudo-color image (Uses IR and Visual bands, 542 mapping), gamma 1.5'}, 'pseudo': {'title': '(default) Pseudo-color image, pan sharpened (Uses IR and Visual bands, 542 mapping), gamma 1.5'}, 'visual': {'title': 'Real-color image, pan sharpened (Uses the visual bands, 321 mapping), gamma 1.5'}, 'pseudo_low': {'title': 'Pseudo-color image, pan sharpened (Uses IR and Visual bands, 542 mapping)'}, 'visual_low': {'title': 'Real-color image, pan sharpened (Uses the visual bands, 321 mapping)'}, 'visual_bright': {'title': 'Real-color image (Uses the visual bands, 321 mapping), gamma 1.5'}} |
|---|
| | 50 | |
|---|
| | 51 | Available methods, their URLs, and available formats: |
|---|
| | 52 | |
|---|
| | 53 | >>> [op.name for op in wms.capabilities.operations] |
|---|
| | 54 | ['GetCapabilities', 'GetMap'] |
|---|
| | 55 | >>> wms.capabilities.getOperationByName('GetMap').methods |
|---|
| | 56 | {'Get': {'url': 'http://wms.jpl.nasa.gov/wms.cgi?'}} |
|---|
| | 57 | >>> wms.capabilities.getOperationByName('GetMap').formatOptions |
|---|
| | 58 | ['image/jpeg', 'image/png', 'image/geotiff', 'image/tiff'] |
|---|
| | 59 | |
|---|
| | 60 | That's everything needed to make a request for imagery: |
|---|
| | 61 | |
|---|
| | 62 | >>> img = wms.getmap( layers=['global_mosaic'], |
|---|
| | 63 | ... styles=['visual_bright'], |
|---|
| | 64 | ... srs='EPSG:4326', |
|---|
| | 65 | ... bbox=(-112, 36, -106, 41), |
|---|
| | 66 | ... size=(300, 250), |
|---|
| | 67 | ... format='image/jpeg', |
|---|
| | 68 | ... transparent=True |
|---|
| | 69 | ... ) |
|---|
| | 70 | >>> out = open('jpl_mosaic_visb.jpg', 'wb') |
|---|
| | 71 | >>> out.write(img.read()) |
|---|
| | 72 | >>> out.close() |
|---|
| | 73 | |
|---|
| | 74 | A very similar API exists for WebFeatureService. See |
|---|
| | 75 | tests/MapServerWFSCapabilities.txt for details. |
|---|