2

I have been trying to use processing toolbox via python console in Qgis 2.0.1. I am able to write the following comamnds:

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 dfoes 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.

10

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

  • You can actually access the log from within QGIS. It's not necessary to dig out the file from some folder. – underdark Oct 28 '13 at 13:39
  • Perhaps, but these files are interesting if you really want to understand how processing (or sextante) works. – gene Oct 28 '13 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 ? – Zaman Oct 28 '13 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? – Zaman Oct 28 '13 at 14:47
  • I use the Toolbox command GRASS.../vector (v*)/v.to.rast.value (not from the GRASS plugin) – gene Oct 28 '13 at 15:07

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.