Execution of the processΒΆ
Each process has to define a pywps.Process.WPSProcess.execute()
method,
which makes the calculation and sets the output values. This method is
called via a WPS Execute request.
In principle, you can do what ever you need within this method. It is advised, to use python bindings to popular GIS packages, like GRASS GIS, GDAL/OGR, PROJ4, or any other Python-GIS package.
In the special chapter, we give you a quick intro to some of these packages. Some examples are also distributed along with the PyWPS source.
If you need to run some shell programs, you should use the
pywps.Process.WPSProcess.cmd()
method.
Below is an example of a simple execute method which transforms a raster file from one coordinate system to another, using Python bindings to GDAL.:
from osgeo import gdal
from osgeo.gdalconst import *
...
def execute(self):
"""Convert input raster file to PNG using GDAL"""
# create gdal input dataset
indataset = gdal.Open( self.inputRaster.getValue())
# get output driver for PNG format
pngDriver = gdal.GetDriverByName("png")
# define output gdal dataset
outfile = "output.png"
outdataset = pngDriver.CreateCopy(outfile, indataset)
self.outputRaster.setValue(outfile)
self.outputRaster.format = {'mimeType':"image/png"}
return