OWSLib svn trunk documentation

OWSLib
Author:Tom Kralidis
Contact:tomkralidis at hotmail.com
Release:svn trunk
Date:2012-02-11

Introduction

OWSLib is a Python package for client programming with Open Geospatial Consortium (OGC) web service (hence OWS) interface standards, and their related content models.

OWSLib was buried down inside PCL, but has been brought out as a separate project in r481.

Features

Standards Support

Standard Version(s)
OGC WMS 1.1.1
OGC WFS 1.0.0, 2.0.0
OGC WCS 1.0.0, 1.1.0
OGC WMC 1.1.0
OGC SOS 1.0.0
OGC CSW 2.0.2
OGC Filter 1.1.0
OGC OWS Common 1.0.0, 1.1.0, 2.0
NASA DIF 9.7
FGDC CSDGM 1998
ISO 19139 2007
Dublin Core 1.1

Installation

Requirements

OWSLib requires a Python interpreter, as well as ElementTree or lxml for XML parsing.

Install

PyPI:

$ easy_install OWSLib

Subversion:

$ svn co https://owslib.svn.sourceforge.net/svnroot/owslib/trunk/

Git:

$ git clone git@github.com:tomkralidis/owslib.git

Usage

WMS

Find out what a WMS has to offer. Service metadata:

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

Available layers:

>>> list(wms.contents)
['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']

Details of a layer:

>>> wms['global_mosaic'].title
'WMS Global Mosaic, pan sharpened'
>>> wms['global_mosaic'].boundingBox
>>> wms['global_mosaic'].boundingBoxWGS84
(-180.0, -60.0, 180.0, 84.0)
>>> wms['global_mosaic'].crsOptions
['EPSG:4326', 'AUTO:42003']
>>> wms['global_mosaic'].styles
{'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'}}

Available methods, their URLs, and available formats:

>>> [op.name for op in wms.operations]
['GetCapabilities', 'GetMap']
>>> wms.getOperationByName('GetMap').methods
{'Get': {'url': 'http://wms.jpl.nasa.gov/wms.cgi?'}}
>>> wms.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()

Result:

WMS GetMap generated by OWSLib

WFS

WCS

CSW

Connect to a CSW, and inspect its properties:

>>> from owslib.csw import CatalogueServiceWeb
>>> csw = CatalogueServiceWeb('http://geodiscover.cgdi.ca/wes/serviceManagerCSW/csw')
>>> csw.identification.type
'CSW'
>>> [op.name for op in csw.operations]
['GetCapabilities', 'GetRecords', 'GetRecordById', 'DescribeRecord', 'GetDomain']

Get supported resultType’s:

>>> csw.getdomain('GetRecords.resultType')
>>> csw.results
{'values': ['results', 'validate', 'hits'], 'parameter': 'GetRecords.resultType', 'type': 'csw:DomainValuesType'}
>>>

Search for bird data:

>>> csw.getrecords(keywords=['birds'], maxrecords=20)
>>> csw.results
{'matches': 101, 'nextrecord': 21, 'returned': 20}
>>> for rec in csw.records:
...     print csw.records[rec].title
...
ALLSPECIES
NatureServe Canada References
Bird Studies Canada - BirdMap WMS
Parks Canada Geomatics Metadata Repository
Bird Studies Canada - BirdMap WFS
eBird Canada - Survey Locations
WHC CitizenScience WMS
Project FeederWatch - Survey Locations
North American Bird Banding and Encounter Database
Wildlife Habitat Canada CitizenScience WFS
Parks Canada Geomatics Metadata Repository
Parks Canada Geomatics Metadata Repository
Wildlife Habitat Canada CitizenScience WMS
Canadian IBA Polygon layer
Land
Wildlife Habitat Canada CitizenScience WMS
WATER
Parks Canada Geomatics Metadata Repository
Breeding Bird Survey
SCALE
>>>

Search for bird data in Canada:

>>> csw.getrecords(keywords=['birds'],bbox=[-141,42,-52,84])
>>> csw.results
{'matches': 3, 'nextrecord': 0, 'returned': 3}
>>>

Search for ‘birds’ or ‘fowl’

>>> csw.getrecords(keywords=['birds', 'fowl'])
>>> csw.results
{'matches': 107, 'nextrecord': 11, 'returned': 10}
>>>

Search for a specific record:

>>> csw.getrecordbyid(id=['9250AA67-F3AC-6C12-0CB9-0662231AA181'])
>>> c.records['9250AA67-F3AC-6C12-0CB9-0662231AA181'].title
'ALLSPECIES'

Search with a CQL query

>>> csw.getrecords(cql='csw:AnyText like "%birds%"')

Transaction: insert

>>> csw.transaction(ttype='insert', typename='gmd:MD_Metadata', record=open(file.xml).read())

Transaction: update

>>> # update ALL records
>>> csw.transaction(ttype='update', typename='csw:Record', propertyname='dc:title', propertyvalue='New Title')
>>> # update records satisfying keywords filter
>>> csw.transaction(ttype='update', typename='csw:Record', propertyname='dc:title', propertyvalue='New Title', keywords=['birds','fowl'])
>>> # update records satisfying BBOX filter
>>> csw.transaction(ttype='update', typename='csw:Record', propertyname='dc:title', propertyvalue='New Title', bbox=[-141,42,-52,84])

Transaction: delete

>>> # delete ALL records
>>> csw.transaction(ttype='delete', typename='gmd:MD_Metadata')
>>> # delete records satisfying keywords filter
>>> csw.transaction(ttype='delete', typename='gmd:MD_Metadata', keywords=['birds','fowl'])
>>> # delete records satisfying BBOX filter
>>> csw.transaction(ttype='delete', typename='gmd:MD_Metadata', bbox=[-141,42,-52,84])

Harvest a resource

>>> csw.harvest('http://host/url.xml', 'http://www.isotc211.org/2005/gmd')

WMC

SOS

ISO

>>> from owslib.iso import *
>>> m=MD_Metadata(etree.parse('tests/data/9250AA67-F3AC-6C12-0CB9-0662231AA181_iso.xml')
>>> m.identification.topiccategory
'farming'
>>>

ISO Codelists:

>>> import urllib2
>>> from owslib.etree import etree
>>> from owslib.iso import CodelistCatalogue
>>> e=etree.parse('gmxCodelists.xml')
>>> c=CodelistCatalogue(e)
>>> print c.getcodelistdictionaries()
['MD_RestrictionCode', 'CI_OnLineFunctionCode', 'DQ_EvaluationMethodTypeCode', 'DS_InitiativeTypeCode', 'MD_MaintenanceFrequencyCode', 'MD_SpatialRepresentationTypeCode', 'MD_ImagingConditionCode', 'MD_ObligationCode', 'MD_GeometricObjectTypeCode', 'MD_ScopeCode', 'MD_KeywordTypeCode', 'MD_CharacterSetCode', 'CI_PresentationFormCode', 'MX_ScopeCode', 'CI_DateTypeCode', 'MD_TopicCategoryCode', 'MD_DatatypeCode', 'MD_ProgressCode', 'MD_MediumNameCode', 'MD_ClassificationCode', 'DS_AssociationTypeCode', 'CI_RoleCode', 'MD_TopologyLevelCode', 'MD_DimensionNameTypeCode', 'MD_CoverageContentTypeCode', 'MD_MediumFormatCode', 'MD_PixelOrientationCode', 'MD_CellGeometryCode']
>>> print c.getcodedefinitionidentifiers('CI_RoleCode')
['author', 'processor', 'publisher', 'custodian', 'pointOfContact', 'distributor', 'user', 'resourceProvider', 'originator', 'owner', 'principalInvestigator']

CRS Handling

>>> from owslib import crs
>>> c=crs.Crs('EPSG:4326')
>>> c.code
4326
>>> c=crs.Crs('urn:ogc:def:crs:EPSG::4326')
>>> c.authority
'EPSG'
>>> c.axisorder
'yx'
>>> c=crs.Crs('http://www.opengis.net/gml/epsg.xml#4326')
>>> c.code
4326
>>> c.axisorder
'xy'
>>> c=crs.Crs('urn:x-ogc:def:crs:EPSG:6.11:2192')
>>> c.axisorder
'xy'
>>> c.code
2192
>>> c.version
'6.11'

Dublin Core

NASA DIF

FGDC

Development

The OWSLib wiki is located at https://sourceforge.net/apps/trac/owslib.

The OWSLib source code is available at https://owslib.svn.sourceforge.net/svnroot/owslib/trunk/. You can browse the source code at https://sourceforge.net/apps/trac/owslib/browser.

You can find out about software metrics at the OWSLib ohloh page at http://www.ohloh.net/p/OWSLib.

Testing

Support

Mailing Lists

OWSLib provides users and developers mailing lists. Subscription options and archives are available at https://lists.sourceforge.net/mailman/listinfo/owslib-users and https://lists.sourceforge.net/mailman/listinfo/owslib-devel.

Submitting Questions to Community

To submit questions to a mailing list, first join the list by following the subscription procedure above. Then post questions to the list by sending an email message to either owslib-users@sourceforge.net or owslib-devel@lists.sourceforge.net.

License

Copyright (c) 2006, Ancient World Mapping Center All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of the University of North Carolina nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Credits