Wednesday, 13 May 2015

pyqgis - How to programmatically add an algorithm from external plugin to QGIS processing toolbox?


I'm writing a python plugin for QGIS and I'd like to know if it's possible to provide an interface to it from the processing toolbox.


I can see how the existing algorithms are loaded into processing via providers, but I don't see any obvious way of loading an algorithm without modifying the module. Perhaps it isn't possible and I need to submit a feature request, or attempt at coding it myself.


I was expecting something like:



import processing
from myplugin import mysweetalgorithm
processing.load_algorithm(mysweetalgorithm)

Answer



You can write a processing script which imports your mysweetalgorithm and uses it. It will appear in the scripts section of the Processing toolbox.


Processing is automatically available in scripts so you don't need to import processing manually.


Check the example scripts which are provided with the standard processing installation to learn how to specify outputs and inputs for the algorithm and user interface.


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