Process Inputs and Outputs ========================== Process inputs and outputs are of three types: ComplexValue Usually used for raster or vector data LiteralValue Used for simple text strings BoundingBoxValue Two coordinate pairs of lower-left and upper-right corners in defined coordinate sytem. Inputs and outputs should usually be defined in the `__init__` method of the process. ComplexValue input and Output ----------------------------- ComplexValue inputs and outputs are used in WPS, to send larger sets of data (usually raster or vector data) into the process or from the process back to the user. The method :meth:`pywps.Process.WPSProcess.addComplexInput` returns instance of :class:`pywps.Process.InAndOutputs.ComplexInput` for inputs. For outputs, they are called :meth:`pywps.Process.WPSProcess.addComplexOutput`, which gives :class:`pywps.Process.InAndOutputs.ComplexOutput` back. The :attr:`pywps.Process.InAndOutputs.ComplexInput.value` and :attr:`pywps.Process.InAndOutputs.ComplexOutput.value` attributes, do contain *file name* of the raster or vector file. For inputs, consider using :meth:`pywps.Process.InAndOutputs.ComplexInput.getValue` method, for getting the value of the input, which can be returned as file object to you, or as file name. For outputs, you should definitely use :meth:`pywps.Process.InAndOutputs.ComplexOutput.setValue` for setting the results file name. The method accepts file objects as well as file name. Sometimes, users are sending the data *as reference* to some URL (e.g. OGC WFS or WCS service). PyWPS downloads the data for you and stores them to local file. If the client requires reference to the output data, PyWPS will create this for you. PyWPS is able to setup `MapServer `_ instance for you, and return OGC WFS or WCS URLs back to the client. For more on this topic, see :ref:`using-mapserver`. Even you can (and should) define support data mimetypes (:attr:`pywps.Process.InAndOutputs.ComplexInput.formats`), mimetype only is checked. PyWPS does not care about valid schemas or anything else. Your Process should do this. Vector data values .................. Vectors are usually handled as `GML `_ files. You can send any other file format as well, such as `GeoJSON `_, `KML `_ or any other. Only condition is: the file should be in text form (so it can fit into XML correctly), if you want to append it as part of the input XML request and everything should be stored in *one* file. Vectors are the default :attr:`pywps.Process.InAndOutputs.ComplexInput.format` of ComplexValue in- or output -- `text/xml` (GML) is expected. .. note:: Some users do want to send `ESRI Shapfiles `_. This is in general not to be adviced: The file is binary format, which is hard to be used with XML, and it consists out of at least three files shp, shx and dbf. If you still want to handle shapefiles, you have either to zip everything in one file or define three separate complex inputs. Example of simple input vector data:: self.inputVector = self.addComplexOutput(identifier="in",title="Input file") Example of more complex input vector data:: self.gmlOrSimilarIn = self.addComplexInput(identifier="input", title="Input file", abstract="Input vector file, usually in GML format", formats = [ # gml {mimeType: 'text/xml', encoding:'utf-8', schema:'http://schemas.opengis.net/gml/3.2.1/gml.xsd'}, # json {mimeType: 'text/plain', encoding: 'iso-8859-2', schema: None }, # kml {mimeType: 'text/xml', encoding: 'windows-1250', schema: 'http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd'} ], # we need at least TWO input files, maximal 5 minOccurs: 2, maxOccurs: 5, metadata: {'foo':'bar','spam':'eggs'} ) Raster data values .................. Sometimes, you need to work with raster data. You have to set proper :attr:`pywps.Process.InAndOutputs.ComplexInput.formats` attribute of supported raster file format. Since they are usually in *binary* form, you would have to send the data always *as reference*. Fortunately, this is not the case. PyWPS can handle the input data, encoded in `Base64 format `_ and once, PyWPS needs to send raster data out as part of Execute response XML, they are encoded with Base64 as well. Example of simple output raster data:: self.dataIn = self.addComplexOutput(identifier="raster", title="Raster out", formats=[{"mimeType":"image/tiff"}]) LiteralValue input and Output ----------------------------- With literal input, you can obtain or send any type of character string. You will obtain instance of :class:`pywps.Process.InAndOutputs.LiteralInput` or :class:`pywps.Process.InAndOutputs.LiteralOutput` class. Literal value Inputs can be more complex. You can define list of allowed values, type of the literal input, spacing and so on. .. note:: Spacing is not supported, so you can not currently define the step in allowed values row. Type .... For type settings, you can either use :mod:`types` module, or the :func:`type()` function of python. Default type is `type(0)` -- Integer. PyWPS will check for you, if the input value type matches allowed type. .. note:: If you need the String type of literal input, PyWPS will always remove everything behind "#", ";", "!", "&" and similar characters. Try to avoid usage of LiteralValue input directly as input for e.g. SQL database or command line programs. You could cause serious system compromise. Allowed Values .............. PyWPS let's you define list of allowed input values. That can be string or integer or float types. Default values are defined in the list. Ranges are defined as two-items filed in form of `(minimum,maximum)`. For example, we would like to allow values 1,2,3, 5 to 7, and 'spam', the :attr:`pywps.Process.InAndOutputs.LiteralInput.values` would look like:: [1,2,3,[5,7],'spam'] Default is "*", which means *all values*. Simple example of LiteralValue output:: self.widthOut = self.addLiteralOutput(identifier = "width", title = "Width") Complex example of LiteralValue input:: self.litIn = self.addLiteralInput(identifier = "eggs", title = "Eggs", abstract = "Eggs with spam and sausages", minOccurs = 0, maxOccurs = 1, uoms = "m", dataType=type(0.0), default=1.1, values=[(0.0,10.1)]) BoundingBoxValue input and Output --------------------------------- BoundingBox are two pairs of coordinates, defined in some coordinate system, of two or three dimensions. In PyWPS, they are defined in :class:`pywps.Process.InAndOutputs.BoundingBoxInput`, :class:`pywps.Process.InAndOutputs.BoundingBoxOutput`. For getting them, use :meth:`pywps.Process.WPSProcess.addBBoxInput` and :meth:`pywps.Process.WPSProcess.addBBoxOutput` respectively. The value is list of four coordinates in `(minx, miny, maxx, maxy)` format. Example of BoundingBoxValue input:: self.bbox = self.addBBoxOutput(identifier = "bbox", title = "BBox")