Using PyWPS as a WPS server instance allows you to easily transform about any Python into a WPS process. In this example we show you which code has to be added to your script so that it is recognized by PyWPS.
The Process
To demonstrate the set up of a PyWPS process we show you how to convert a (very) simple piece of Python code into a PyWPS process. The process in the code box below uses two input values which are added together.
# Input val_1 = 2 val_2 = 6 # Process result = val_1 + val_2 # Output print result
Add PyWPS Metadata
PyWPS requires some metadata about different components of the process. In the script a process identifier, title and abstract can be added as well as a definition of the different in- and output parameters.
Defining PyWPS in- and outputs
The complete script
from pywps.Process import WPSProcess from types import FloatType class Process(WPSProcess): def __init__(self): WPSProcess.__init__(self, identifier = "inputs_added", title = "This process adds the inputvalues", version = "1", storeSupported = "true", statusSupported = "true", abstract = "test process") self.val_1 = self.addLiteralInput(identifier = "val_1", title = "Input Value 1", type = FloatType) self.val_2 = self.addLiteralInput(identifier = "val_2", title = "Input Value 2", type = FloatType) self.result = self.addLiteralOutput(identifier = "result", title = "Value of the process result", type = FloatType) def execute(self): # Input val_1 = self.val_1.getValue() val_2 = self.val_2.getValue() # Process result = val_1 + val_2 # Output self.result.setValue(result) return