24
24
# This will get replaced with a git SHA1 when you do a git archive
25
25
26
26
__revision__ = '$Format:%H$'
27
-
28
- import os
29
- import configparser
30
-
31
27
from qgis .core import (QgsApplication ,
32
28
QgsProcessingAlgorithm ,
33
29
QgsProcessingParameterEnum ,
43
39
44
40
45
41
def 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
48
49
"""
49
50
alg = QgsApplication .processingRegistry ().algorithmById (id )
50
51
if alg is not None :
@@ -100,6 +101,9 @@ def run(algOrName, parameters, onFinish=None, feedback=None, context=None, is_ch
100
101
:param context: Processing context object
101
102
:param is_child_algorithm: Set to True if this algorithm is being run as part of a larger algorithm,
102
103
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]
103
107
"""
104
108
if onFinish or not is_child_algorithm :
105
109
return Processing .runAlgorithm (algOrName , parameters , onFinish , feedback , context )
@@ -114,8 +118,17 @@ def post_process(_alg, _context, _feedback):
114
118
115
119
116
120
def 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
118
123
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]
119
132
"""
120
133
if isinstance (algOrName , QgsProcessingAlgorithm ):
121
134
alg = algOrName
@@ -127,21 +140,30 @@ def runAndLoadResults(algOrName, parameters, feedback=None, context=None):
127
140
if not param .name () in parameters :
128
141
continue
129
142
130
- if isinstance (param , (QgsProcessingParameterFeatureSink , QgsProcessingParameterVectorDestination , QgsProcessingParameterRasterDestination )):
143
+ if isinstance (param , (QgsProcessingParameterFeatureSink , QgsProcessingParameterVectorDestination ,
144
+ QgsProcessingParameterRasterDestination )):
131
145
p = parameters [param .name ()]
132
146
if not isinstance (p , QgsProcessingOutputLayerDefinition ):
133
147
parameters [param .name ()] = QgsProcessingOutputLayerDefinition (p , QgsProject .instance ())
134
148
else :
135
149
p .destinationProject = QgsProject .instance ()
136
150
parameters [param .name ()] = p
137
151
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 )
139
154
140
155
141
156
def 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
143
159
with a given set of parameters. It is the caller's responsibility to execute
144
160
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]
145
167
"""
146
168
if isinstance (algOrName , QgsProcessingAlgorithm ):
147
169
alg = algOrName .create ()
@@ -162,10 +184,15 @@ def createAlgorithmDialog(algOrName, parameters={}):
162
184
163
185
164
186
def execAlgorithmDialog (algOrName , parameters = {}):
165
- """Executes an algorithm dialog for the specified algorithm, prepopulated
187
+ """
188
+ Executes an algorithm dialog for the specified algorithm, prepopulated
166
189
with a given set of parameters.
167
190
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]
169
196
"""
170
197
dlg = createAlgorithmDialog (algOrName , parameters )
171
198
if dlg is None :
0 commit comments