I would like to take an existing tool of the grass tool box and modify the code to the specific needs of my task. As I´m struggling to start some kick-off would be great.

How to access code?

What do I have to consider?

How to access/run the code in QGIS?


The Python processing module of QGIS uses the module subprocess to launch directly the GRASS commands with the script GrassUtils.py (in /.../plugins/processing/algs/grass/GrassUtils.py):

1) First it creates a temporary batch file (grass_batch_job.sh or grass_batch_job.bat) in /.../.qgis2/processing/ with the command
(def createGrassBatchJobFileFromGrassCommands(commands)

example of a batch file (by defaut in the GrassUtils.py to test if GRASS is available)

    g.proj -c proj4="+proj=utm +zone=30 +ellps=intl +towgs84=-87,-98,-121,0,0,0,0 +units=m +no_defs"
    v.in.ogr min_area=0.0001 snap=-1 dsn="/Users/Shared//QGIS_2.4/Contents/MacOS/../Resources/python/plugins/processing/tests/data" layer=points output=tmp14039872425711 --overwrite -o
    g.region n=4458983.8488 s=4458921.97814 e=270855.745301 w=270778.60198 res=1
    v.voronoi input=tmp14039872425711 output=output7c801e59498a40a589500b1ec3e79d40 --overwrite
    v.out.ogr -s -c -e -z input=output7c801e59498a40a589500b1ec3e79d40 dsn="/var/folders/vu/vu099NovH-KZpE5TEa83BU+++TI/-Tmp-/processing/0086845b324144c099469f2da59ebd05" format=ESRI_Shapefile olayer=output type=auto

2) Then it execute this batch file with the function def executeGrass(commands, progress, outputCommands=None):

proc = subprocess.Popen(

So, there is no need to change the Python code, the important elements are the GRASS commands and the path to find them. Some specific command of GRASS GIS are not implemented in Processing but you can use them with the Grass olugin.

  • Ok thanks. To be more specific, I want to use the Multiple Flow Direction algorithm (MFD) which is implemented in r.terraflow. In my case I need the MFD from one starting point and overflowing an given area e.g. 1 sqkm. What is the way to achieve this?
    – Daniel
    Jul 3 '14 at 8:44
  • With the items in the Toolbox, you cannot. If you know Python you can try to create a new entry or use GRASS GIS directly
    – gene
    Jul 3 '14 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.