4

I use following code for searching adequate id name for each algorithm presents in Processing Toolbox (gdal, grass7, qgis, saga) for QGIS 3.

from os import listdir
from os.path import isfile, join

gdal_path_algs = processing.algs.gdal.__path__[0]
grass_path_algs = processing.algs.grass7.__path__[0] + '/description'
qgis_path_algs = processing.algs.qgis.__path__[0]
saga_path_algs = processing.algs.saga.__path__[0] + '/description'

gdal_algs = [ 'gdal:' + file[:-3].lower() for file in listdir(gdal_path_algs) if isfile(join(gdal_path_algs, file)) ]
grass_algs = [ 'grass7:' + file[:-4].lower() for file in listdir(grass_path_algs) if isfile(join(grass_path_algs, file)) ]
qgis_algs = [ 'qgis:' + file[:-3].lower() for file in listdir(qgis_path_algs) if isfile(join(qgis_path_algs, file)) ]
saga_algs = [ 'saga:' + file[:-4].lower() for file in listdir(saga_path_algs) if isfile(join(saga_path_algs, file)) ]

#print (gdal_algs)
#print (grass_algs)
#print (qgis_algs)
print (saga_algs)

However, when list algorithms is printed at Python Console, for instance saga, some of them has special characters ("-", "(", ")") or author's name of algorithm and id's name doesn't work for retrieving parameters list by using 'algorithmHelp' processing method.

Afterwards, I founded out that tooltips displayed when I put cursor over algorithm's name at Processing Toolbox (see following image) had correct information I need. How can I get information displayed at tooltips for each algorithm's name at Processing Toolbox for QGIS 3 as alternative approach of my above code?

enter image description here

4

Perhaps it might be better to obtain the algorithms' details directly from the QgsApplication::processingRegistry(), you could then store the display names and algorithm ID in a dictionary (or list). Then you can call the ID by entering the name displayed in the Processing Toolbox or from the tooltip:

gdal_algs = {}
grass_algs = {}
qgis_algs = {}
saga_algs = {}

for algs in QgsApplication.processingRegistry().algorithms():
    if 'gdal' in algs.id():
        gdal_algs[algs.displayName()] = 'Algorithm ID: ' + algs.id()
    if 'grass7' in algs.id():
        grass_algs[algs.displayName()] = 'Algorithm ID: ' + algs.id()
    if 'qgis' in algs.id():
        qgis_algs[algs.displayName()] = 'Algorithm ID: ' + algs.id()
    if 'saga' in algs.id():
        saga_algs[algs.displayName()] = 'Algorithm ID: ' + algs.id()

Then use the following to get the ID of your chosen algorithm:

saga_algs['Imcorr - feature tracking']

>>>'Algorithm ID: saga:imcorrfeaturetracking'

I'm not sure how to access the tooltip directly to get the same info.


EDIT:

You could also just bundle all algorithms into a single dictionary and call the algorithmHelp() function for the tool you're interested in:

algorithms = {}
for algs in QgsApplication.processingRegistry().algorithms():
        algorithms[algs.displayName()] = algs.id()

processing.algorithmHelp(algorithms['Imcorr - feature tracking'])
  • 1
    Thanks a lot Joseph. This is the answer that I wanted. This is information displayed at each tooltip. – xunilk Mar 15 '18 at 14:25
  • 1
    @xunilk - Most welcome, glad it helped! Edited post to include another method to directly get the help parameters by creating a single dictionary instead :) – Joseph Mar 15 '18 at 14:34
  • 1
    Thanks again @Joseph. For my plugin I think is enough with this list form: algs = [ alg.id() for alg in QgsApplication.processingRegistry().algorithms() ]. I'll see it later. – xunilk Mar 15 '18 at 15:38

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.