Newsletter Volume 1 PyWPS and Embrio

PyWPS and Embrio Using ka-Map & PyWPS to create a GRASS WEB GIS

by Jachym Cepicky and Lorenzo Becchi

Processing geospatial operations via Internet on remote servers -- PyWPS

Jáchym Čepický jachym.cepicky les-ejk cz http://les-ejk.cz Lorzeno Becchi lorenzo ominiverdi org http://ominiverdi.org

''Document OGC 05-007r4 describes the way, how geospatial operations should be offered in networks using Web Services. This paper introduces one of it's implementation -- PyWPS. Even if the original target of PyWPS was to make modules of GRASS GIS accessible from Internet, in general it is possible to use any command-line oriented tool or tool, which has bindings to Python Programming language. With help of PyWPS we can perform time consuming calculations on the server side, as well as build your real WebGIS application, running in web browser. Let us look, how it works and if PyWPS could fit your needs. ''

OGC Web Processing Service
Since OGC Web Processing Service (WPS) standard is still relatively new and not so known as for example it's cousin Web Map Service (WMS) is, we would like to give a brief overview of the standard on this place.

Basic unit in the WPS is the process -- geospatial operation, with inputs and outputs of defined type. Client is communicating with the server with help of three types of requests. The request can be sent to the server via HTTP GET with parameters sorted like KVP (Key-Value Pairs) or via HTTP POST, with parameters sorted in XML file.


 * GetCapabilities -- Server responses with XML, which is describing server provider, fees and general description and giving a list of processes, prepared to be performed.


 * DescribeProcess -- Server responses with XML, which describes concrete inputs and outputs type, so the client is able to formulate the Execute request.


 * Execute -- Client requests the performance of some geospatial operation, with all required input data. Depending on, if the server is supposed to run the process in the background and if it is supposed to store the resulting data on the server, resulting XML or e.g. GML file is returned immediately after the request is obtained or first after the calculation is performed.

Let us introduce some illustrative examples of these requests. Let us assume, we would like to perform line-of-sigh calculation from defined x and y coordinates on some raster file, which can be obtained on remote server. The process name will be visibility.

- First we need to find out, which calculations the server offers:

http://localhost/cgi-bin/wps.py?service=WPS&request=GetCapabilities

- From the resulting XML is is clear, that the process 'visibility' is available on the server and abstract tells us, that it does what we would like. In the second step, we need to find out, what kind of input and outputs does the process need or will send back:

- x of type LiteralValue - y of type LiteralValue - maxdist -- maximum distance from the observer. Type LiteralValue, minimal allowed value is 0, maximal 5000 meters. - observer -- observer height. Type LiteralValue, minimal allowed value is 0, maximal 50        meters. - dem, ComplexValue -- raster map of digital elevation model, on which the visibility should be calculated.

Now we can formulate the input request, sent it to to server and looking forward to calculation results.

http://localhost/cgi-bin/wps.py? service=WPS&version=0.4.0&request=Execute &identifier=visibility&datainputs=x,602829.1875,y,4925326.875,maxdist=2000,observer=1.2, dem,http://somewhere/?some&service

Server will download the input digital elevation model, perform the lines-of-sight calculation and return resulting raster image back the the client.

Introduction to PyWPS
PyWPS is relatively new project (it's development started in April 2006). Original project target was, making the connection between (UMN) MapServer and GRASS GIS easy possible, so that we could build real WebGIS application, which would be able to perform for example interpolation of raster data or various digital elevation model analysis. Time has shown, that even if GRASS GIS is powerful tool, it does not necessary have to be the best or the only one program for all possible tasks. Design of PyWPS has changed, so it can be used without GRASS GIS in the background, with any other tool or just with Python itself.

PyWPS is implementation of OGS's Web Processing Service standard, as it is defined in document OGC 05-007r4. Currently, not complete standard is supported, but we can say, that 95% of the standard is implemented and usable.

It is a simple CGI script, which is trying to make life of WebGIS coder as easy as possible.


 * It parses all inputs and creates all outputs
 * It performs basic control of the input, like type of LiteralValue input, maximum file size for the   ComplexValue input and similar.
 * It creates and removes on-the-fly generated temporary files and directories, like temporary GRASS locations and mapsets and temporary generated files created as part of calculation.
 * And other useful operations

The coder has to do only one thing: She has to define her process with inputs and outputs, which is basically a script in Python programming language. The process is one class Process, with one mandatory method execute, in which the calculation is provided. Input and output data are defined on similar way, it is a complex dictionary structure:

{    'Identifier':'maxdist', 'Title': 'Maximal distance', 'Abstract':'Maximal distance of visibility (meters)', 'LiteralData': { 'values':[ [0.,5000] ], },    'dataType': type(0.0), }, {    'Identifier': 'dem', 'Title': 'Digital elevation mode' 'Abstract': 'Raster map with elevation model', 'ComplexValueReference': { 'Formats':["image/tiff"], } },

The execute method can then use e.g. GRASS modules directly: def execute(self): # importing dem os.system("r.in.gdal in=\%s out=dem" \% (self.datainputs['dem'])    # setting region according to dem file     os.system("g.region rast=dem")     # lines-of-sight module     os.system("r.los input=dem output=output coordinate=\%s,\%s \                max_dist=\%f obs_elev=\%d" \% (self.datainputs['x'],                self.datainputs['y'],self.datainputs['maxdist'],                self.datainputs['observer']))     # exporting raster map     os.system("r.out.gdal in=output out=out.tif")     # setting the output value     self.dataoutputs['output'] = "out.tif"     return

As the source code is the best documentation, around ten example processes are distributed together with PyWPS source, so the user can get general picture about the process definition. There is also on-line and offline documentation available, which is trying to describe the installation process and setup of own processes.

Further development
First "stable" version of PyWPS with number 1.0.0 was released in November 2006. Currently, PyWPS development team would like to release version 2.0.0 soon, with added functionality and few bug fixes. Common effort in the development goes in three directions: - Implementation of OGC WPS standard to maximal degree - Making the application as secure as possible, to avoid server compromitation - Making life of the process-coder as easy as possible.

The PyWPS development team would also like to start discussion across geospatial communities about process metadata definition. The OGC WPS standard defines the input types from the process point of view, however, it does not say anything about input (or output) type from the user (interface) point of view. For example, coordinate x is type of LiteralValue but this does not say anything about, that x is coordinate so it could be useful to setup this input value with mouse click in the map window rather then with keyboard in some input form field.

~

If you want to have closer look at PyWPS, feel free to visit PyWPS project page at http://pywps.wald.intevation.org, where the source code as well as links to projects already using PyWPS are available.