Ticket #2 (new enhancement)
Opened 14 years ago
GIS GRASS integration
Reported by: | soeren | Owned by: | soeren |
---|---|---|---|
Priority: | major | Milestone: | |
Component: | zoo-kernel | Version: | 1.0 |
Keywords: | Cc: | soeren |
Description
I have implemented a proof of concept to attach GIS GRASS as processing back-end to ZOO WPS. The approach is quite generic. There is (hopefully) no need to implement a single line of code to attach a grass module as WPS service. Everything is automatically generated and works with grass7.
The principle:
Based on the grass module WPS XML description [0], which must be generated for the module in gis grass7, a zcfg file and a python service file are generated. The generator is available here [1]. There is also a grass XML WPS to YAML generator available for future use [2].
The zcfg file should work out of the box, but it can of course be modified to your needs.
Automatically generated python service file example for v.voronoi:
import ZOO_Project.ZOOGrassModuleStarter as zoo def v_voronoi(m, inputs, outputs): service = zoo.ZOOGrassModuleStarter() service.fromMaps("v.voronoi", inputs, outputs) return 1
How it works?
The generated python service file instantiates an object of the class ZOOGrassModuleStarter [3], passing the input and output maps. This class is derived from GrassModuleStarter? [4], which is a framework to start gis grass modules based on external data.
The ZOOGrassModuleStarter will write the input data located in the input map to a temporary directory, so grass can import/link it. Then a gis grass location based on the first input is generated. Then the grass module will be executed and the result will be exported and written into the output map, so the zoo kernel can handle it.
What to modify?
To get the ZOOGrassModuleStarter to work properly, some paths must be set in the header section. This is an "works for me" example:
# !!!!! EDIT THIS SECTION !!!!! # Some default variables. Override them to your needs. WORKDIR="/tmp" OUTPUTDIR="/tmp" LOGFILE="logfile.txt" LOGFILE_MODULE_STDOUT="logfile_module_stdout.txt" LOGFILE_MODULE_STDERR="logfile_module_sterr.txt" GRASS_GIS_BASE="/home/soeren/src/grass7.0/grass_trunk/dist.i686-pc-linux-gnu" GRASS_ADDON_PATH="/home/soeren/src/vtkGRASSBridge/vtk-grass-bridge/WPS/Testing/Python/GrassAddons" GRASS_VERSION="7.0.svn" # !!!!! END EDIT SECTION !!!!!
These settings are used by all automatically generated grass python services. They may change in future!
Example installation:
I have attached a tar.gz archive containing the Python code of the ZOOGrassModuleStarter frame-work and sample zcfg files + service python files. Just copy the content into your cgi directory, modify the main.cfg and the ZOOGrassModuleStarter.py in ZOO_Project and install PyXB [5]. Python 2.6, PyXB and a valid grass7 installation are the only dependencies.
The simple grass modules r.add, r.mult, r.div and r.sub are available here [6]. Thy are not part o grass7.
Obstacles:
- The zcfg files may contain letters which are not supported or wrongly interpreted by the zoo kernel. This is related to parameter descriptions of grass modules, which make use of .,/() and so on.
- ZOO kernel automatically sets obligatorily variables, even if no default value is specified. I will report this in a different ticket.
Enjoy and good Luck
[0] http://grass.osgeo.org/wiki/WPS
[1] http://code.google.com/p/vtk-grass-bridge/source/browse/trunk/WPS/ZOO_Project/GrassXMLtoZCFG.py
[2] http://code.google.com/p/vtk-grass-bridge/source/browse/trunk/WPS/ZOO_Project/GrassXMLtoYAML.py
[3] http://code.google.com/p/vtk-grass-bridge/source/browse/trunk/WPS/ZOO_Project/ZOOGrassModuleStarter.py
[4] http://code.google.com/p/vtk-grass-bridge/source/browse/trunk/WPS/GrassModuleStarter.py
[5] http://pyxb.sourceforge.net/
[6] http://code.google.com/p/vtk-grass-bridge/source/browse/#svn/trunk/WPS/Testing/Python/GrassAddons