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:
- Connects to the WMS Server to retrieve a list of all the WMS layers.
- For each layer it finds the maximum extent of the layer and its projection code.
- A GetMap request is made to the WMS server for the layer at the maximum extent.
- 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.