mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
[processing][API] rename alglist() to printAlgorithms() to improve
readability. Also introduce algorithmsList() call which returns available Processing algorithms as list
This commit is contained in:
parent
c1e6ba0f40
commit
e1a01106dd
@ -41,18 +41,38 @@ from processing.core.parameters import ParameterSelection
|
||||
from processing.gui.Postprocessing import handleAlgorithmResults
|
||||
|
||||
|
||||
def alglist(text=None):
|
||||
def algorithmsList(text=None):
|
||||
"""Returns list of all available Processing algorithms or list
|
||||
of algorithms which names contains given text.
|
||||
Returned list contains algorithm command-line names.
|
||||
"""
|
||||
lst = []
|
||||
for provider in list(algList.algs.values()):
|
||||
sortedlist = sorted(list(provider.values()), key=lambda alg: alg.name)
|
||||
for alg in sortedlist:
|
||||
if text is None or text.lower() in alg.name.lower():
|
||||
lst.append(alg.commandLineName())
|
||||
return lst
|
||||
|
||||
|
||||
def printAlgorithms(text=None):
|
||||
"""Print list of all available Processing algorithms or list
|
||||
of algorithms which names contains given text.
|
||||
Prints algorithms user-friendly names as well as command-line
|
||||
names.
|
||||
"""
|
||||
s = ''
|
||||
for provider in list(algList.algs.values()):
|
||||
sortedlist = sorted(list(provider.values()), key=lambda alg: alg.name)
|
||||
for alg in sortedlist:
|
||||
if text is None or text.lower() in alg.name.lower():
|
||||
s += alg.name.ljust(50, '-') + '--->' + alg.commandLineName() \
|
||||
+ '\n'
|
||||
s += '{}--->{}\n'.format(alg.name.ljust(50, '-'), alg.commandLineName())
|
||||
print(s)
|
||||
|
||||
|
||||
def algorithmOptions(name):
|
||||
"""Prints all algorithm options with their values.
|
||||
"""
|
||||
alg = Processing.getAlgorithm(name)
|
||||
if alg is not None:
|
||||
opts = ''
|
||||
@ -67,6 +87,9 @@ def algorithmOptions(name):
|
||||
|
||||
|
||||
def algorithmHelp(name):
|
||||
"""Prints algorithm parameters with their types. Also
|
||||
provides information about options if any.
|
||||
"""
|
||||
alg = Processing.getAlgorithm(name)
|
||||
if alg is not None:
|
||||
alg = alg.getCopy()
|
||||
@ -77,12 +100,18 @@ def algorithmHelp(name):
|
||||
|
||||
|
||||
def runalg(algOrName, *args, **kwargs):
|
||||
"""Executes given algorithm and returns its outputs as dictionary
|
||||
object.
|
||||
"""
|
||||
alg = Processing.runAlgorithm(algOrName, None, *args, **kwargs)
|
||||
if alg is not None:
|
||||
return alg.getOutputValuesAsDictionary()
|
||||
|
||||
|
||||
def runandload(name, *args, **kwargs):
|
||||
"""Executes given algorithm and load its results into QGIS project
|
||||
when possible.
|
||||
"""
|
||||
return Processing.runAlgorithm(name, handleAlgorithmResults, *args, **kwargs)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user