Thursday 25 August 2016

pyqgis - Difference between processing.runalg() and general.runalg()


In the discussion from a question I asked several days ago (Using the processing framework in a PyQGIS standalone application), someone suggested that I use general.runalg() instead of processing.runalg() for running QGIS algorithms.


I've now used both, and haven't noticed a difference in either performance or syntax between them. I'm just wondering what sort of differences there are between these two methods, and which one I should be using.



Answer



Open a QGIS Python Console and run this:



import processing 
help( processing.runalg )

You will get:


Help on function runalg in module processing.tools.general:

runalg(algOrName, *args, **kwargs)

Which indicates us that by using processing.runalg(), you're actually calling general.runalg().


Note that if you want to call general.runalg() explicitly, you need to import the general module from processing.tools.



In summary, use whatever you want, just make sure you initialize Processing (Processing.initialize()) before calling runalg() if you're running a standalone PyQGIS script.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...