Automated WMS Testing with Python


2012-06-23 17:53




mapserver, python, wms


automation, ogc, PIL, python, wms





image0 <>`__This post and associated script details how to automate testing WMS (Web Mapping Service) layers. When you’ve set up several MapServer or GeoServer instances with 100s of layers, its nice to be able to make sure everything continues to run smoothly.

The automation makes maintenance proactive, rather than reacting to client’s emails wondering where their data has gone, and it beats pasting long obfuscated URLS into a browser and repeatedly pressing F5..

This script combines three of my current favourite Python libraries.

  • OWSLib a Python OGC Web Service utility library

  • PIL - The Python Imaging Library (PIL) used for image processing

  • Requests - a Python library to make web requests - “HTTP for Humans”

The PIL site handily contains Windows installers for nearly every version of Python. OWSLib and Requests can be added to your Python installation with easy_install, or PIP. I’m currently sticking with Python 2.6 as many scripts and packages I’m writing need to work with ArcGIS, which requires this version, and also on Windows, which puts me very much in the minority in the Python world outside of ESRI users.

In summary the script does the following:

  1. Connects to the WMS Server to retrieve a list of all the WMS layers.

  2. For each layer it finds the maximum extent of the layer and its projection code.

  3. A GetMap request is made to the WMS server for the layer at the maximum extent.

  4. Any errors getting the image can be reported. If an image is returned it is analysed to check if it is empty or blank.

I then adapted the sample script to work with Python’s unittest module so I could get a nice list of passes and fails for each map layer, and for a variety of issues such as HTTP failures or removed layers. It is then a simple step to set up a Windows Task Schedule to do a daily check that all WMS servers are up and running and returning data.



1. Antonio Santiago **

A write a similar post some time ago:

It is nice to see how “nice” online applications can help us documenting :)


2. geographika **

Anything to make documentation get read!
Your `Balloon

Project <>`__ looks interesting. Its easy to forget NASA Whirlwind when Google Earth gets all the publicity.


3. Sean Gillies **

You wouldn’t believe the work I put into those ASCII class diagrams ;) It’s definitely kitsch from a bygone age.

Add Comment