2424# This will get replaced with a git SHA1 when you do a git archive
2525
2626__revision__ = '$Format:%H$'
27-
28- import os
29- import configparser
30-
3127from qgis .core import (QgsApplication ,
3228 QgsProcessingAlgorithm ,
3329 QgsProcessingParameterEnum ,
4339
4440
4541def algorithmHelp (id ):
46- """Prints algorithm parameters with their types. Also
47- provides information about options if any.
42+ """
43+ Prints algorithm parameters with their types. Also
44+ provides information about parameters and outputs,
45+ and their acceptable values.
46+
47+ :param id: An algorithm's ID
48+ :type id: str
4849 """
4950 alg = QgsApplication .processingRegistry ().algorithmById (id )
5051 if alg is not None :
@@ -100,6 +101,9 @@ def run(algOrName, parameters, onFinish=None, feedback=None, context=None, is_ch
100101 :param context: Processing context object
101102 :param is_child_algorithm: Set to True if this algorithm is being run as part of a larger algorithm,
102103 i.e. it is a sub-part of an algorithm which calls other Processing algorithms.
104+
105+ :returns algorithm results as a dictionary, or None if execution failed
106+ :rtype: Union[dict, None]
103107 """
104108 if onFinish or not is_child_algorithm :
105109 return Processing .runAlgorithm (algOrName , parameters , onFinish , feedback , context )
@@ -114,8 +118,17 @@ def post_process(_alg, _context, _feedback):
114118
115119
116120def runAndLoadResults (algOrName , parameters , feedback = None , context = None ):
117- """Executes given algorithm and load its results into QGIS project
121+ """
122+ Executes given algorithm and load its results into the current QGIS project
118123 when possible.
124+
125+ :param algOrName: Either an instance of an algorithm, or an algorithm's ID
126+ :param parameters: Algorithm parameters dictionary
127+ :param feedback: Processing feedback object
128+ :param context: Processing context object
129+
130+ :returns algorithm results as a dictionary, or None if execution failed
131+ :rtype: Union[dict, None]
119132 """
120133 if isinstance (algOrName , QgsProcessingAlgorithm ):
121134 alg = algOrName
@@ -127,21 +140,30 @@ def runAndLoadResults(algOrName, parameters, feedback=None, context=None):
127140 if not param .name () in parameters :
128141 continue
129142
130- if isinstance (param , (QgsProcessingParameterFeatureSink , QgsProcessingParameterVectorDestination , QgsProcessingParameterRasterDestination )):
143+ if isinstance (param , (QgsProcessingParameterFeatureSink , QgsProcessingParameterVectorDestination ,
144+ QgsProcessingParameterRasterDestination )):
131145 p = parameters [param .name ()]
132146 if not isinstance (p , QgsProcessingOutputLayerDefinition ):
133147 parameters [param .name ()] = QgsProcessingOutputLayerDefinition (p , QgsProject .instance ())
134148 else :
135149 p .destinationProject = QgsProject .instance ()
136150 parameters [param .name ()] = p
137151
138- return Processing .runAlgorithm (alg , parameters = parameters , onFinish = handleAlgorithmResults , feedback = feedback , context = context )
152+ return Processing .runAlgorithm (alg , parameters = parameters , onFinish = handleAlgorithmResults , feedback = feedback ,
153+ context = context )
139154
140155
141156def createAlgorithmDialog (algOrName , parameters = {}):
142- """Creates and returns an algorithm dialog for the specified algorithm, prepopulated
157+ """
158+ Creates and returns an algorithm dialog for the specified algorithm, prepopulated
143159 with a given set of parameters. It is the caller's responsibility to execute
144160 and delete this dialog.
161+
162+ :param algOrName: Either an instance of an algorithm, or an algorithm's ID
163+ :param parameters: Initial algorithm parameters dictionary
164+
165+ :returns algorithm results as a dictionary, or None if execution failed
166+ :rtype: Union[dict, None]
145167 """
146168 if isinstance (algOrName , QgsProcessingAlgorithm ):
147169 alg = algOrName .create ()
@@ -162,10 +184,15 @@ def createAlgorithmDialog(algOrName, parameters={}):
162184
163185
164186def execAlgorithmDialog (algOrName , parameters = {}):
165- """Executes an algorithm dialog for the specified algorithm, prepopulated
187+ """
188+ Executes an algorithm dialog for the specified algorithm, prepopulated
166189 with a given set of parameters.
167190
168- Returns the algorithm's results.
191+ :param algOrName: Either an instance of an algorithm, or an algorithm's ID
192+ :param parameters: Initial algorithm parameters dictionary
193+
194+ :returns algorithm results as a dictionary, or None if execution failed
195+ :rtype: Union[dict, None]
169196 """
170197 dlg = createAlgorithmDialog (algOrName , parameters )
171198 if dlg is None :
0 commit comments