3

I have been trying to use processing toolbox via Python console in QGIS 2.0.1. I am able to write the following commands:

enter image description here

I am particularly interested to run 'r.statistics' from GRASS module.

enter image description here

My question is how to arrange the input parameters sequentially and what does each parameter mean? For example, in the above screenshot, when I type the help, I can see the parameter inputs,

processing.runalg('grass:r.statistics', base, cover, method, -c, GRASS region parameter, Grass region cell size, output)

I can understand that 'base = input raster', 'method = avg, mean, std' and 'output=outputfile to eb declared'.

But I am not sure what are 'cover=', '-c','GRASS region means'? How can I get further help on that? If I were to run the function 'r.statistics' via processing toolbox, how should the exact/correct command look like?

processing.runalg('grass:r.statistics', 'C:\mydata\dem.tif', cover, '1', -c, GRASS region parameter, Grass region cell size, 'C:\mydata\outputdem.tif') 

Can anyone help me what to put in place of rest of the parameters?

Thanks in advance.

Kadir Şahbaz
78.6k57 gold badges260 silver badges407 bronze badges
asked Oct 28, 2013 at 10:39

1 Answer 1

11

To learn the processing module in Python, the easiest solution for me is:

  1. execute the Processing command (from the Toolbox), for example v.to.rast.val
  2. examine the "processing_qgis.log" file in the ".qgis2/processing/" folder

where you can examine all the running algorithms:

 ALGORITHM|Mon Oct 28 2013 
 12:30:34|processing.runalg("grass:v.to.rast.value","/Users/Shared/polygon.shp",0,1,"202563.92575,204206.182887,89106.9864984,89783.2100251",0,-1,0.0001,"/Users/Shared/polyraster.tif")

The actual commands are in:

  • "grass_batch_job.sh" or "grass_batch_job.bat" files (in the ".qgis2/processing/" folder) for GRASS GIS;
  • "saga_batch_job.sh" or "saga_batch_job.bat" files for SAGA GIS;
  • "processing_script.r" file for R.

So, in the Python console:

import processing
processing.runalg("grass:v.to.rast.value","/Users/Shared/polygon.shp",0,1,"202563.92575,204206.182887,89106.9864984,89783.2100251",0,-1,0.0001,"/Users/Shared/polyraster.tif")
processing.runalg("grass:r.statistics","/Users/Shared/polyraster.tif","/Users/Shared/mydem.asc",1,True,"202086.577,205625.414407,88411.048,90534.3504441",0,"/Users/Shared/test.tif")

You can also use one of the displayed layers:

vectorlayer = qgis.utils.iface.mapCanvas().currentLayer().source()
processing.runalg("grass:v.to.rast.value",vectorlayer,0,1,"202563.92575,204206.182887,89106.9864984,89783.2100251",0,-1,0.0001,"/Users/Shared/polyraster.tif")

but before, you need to understand all the parameters of the command r.statistics and the problems as r.statistics limitation to CELL

answered Oct 28, 2013 at 11:40
6
  • You can actually access the log from within QGIS. It's not necessary to dig out the file from some folder. Commented Oct 28, 2013 at 13:39
  • Perhaps, but these files are interesting if you really want to understand how processing (or sextante) works. Commented Oct 28, 2013 at 14:17
  • Hi All,Thanks for the reply. As suggested by gene, how would I execute the Processing command of 'v.to.rast.value'? Do I have to run the v.to.rast.value from GRASS gui via Qgis first to see log file? Then shall I check qgis/processing ? Commented Oct 28, 2013 at 14:43
  • gene, how did you generate the following log file? ALGORITHM|Mon Oct 28 2013 12:30:34|processing.runalg("grass:v.to.rast.value","/Users/Shared/polygon.shp",0,1,"202563.92575,204206.182887 Did you run v.to.rast.value from GRASS gui initially to see the log file in qgis2/processing folder? Commented Oct 28, 2013 at 14:47
  • I use the Toolbox command GRASS.../vector (v*)/v.to.rast.value (not from the GRASS plugin) Commented Oct 28, 2013 at 15:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.