Subgroup: Processing

Class: QgsProcessingModelAlgorithm

class qgis.core.QgsProcessingModelAlgorithm

Bases: qgis._core.QgsProcessingAlgorithm

Model based algorithm with processing.

New in version 3.0: Methods

activateChildAlgorithm Attempts to activate the child algorithm with matching id.
addChildAlgorithm Adds a new child algorithm to the model.
addModelParameter Adds a new parameter to the model, with the specified definition and graphical component.
addOutput
addParameter
asPythonCode Attempts to convert the model to executable Python code.
asPythonCommand
availableSourcesForChild Returns a list of possible sources which can be used for the parameters for a child algorithm in the model.
canExecute
checkParameterValues Checks the supplied parameter values to verify that they satisfy the requirements of this algorithm in the supplied context.
childAlgorithm Returns the child algorithm with matching id.
childAlgorithms Returns the map of child algorithms contained in the model.
childAlgorithmsDependOnParameter Returns true if any child algorithms depend on the model parameter with the specified name.
countVisibleParameters Returns the number of visible (non-hidden) parameters defined by this algorithm.
create Creates a copy of the algorithm, ready for execution.
createCustomParametersWidget If an algorithm subclass implements a custom parameters widget, a copy of this widget should be constructed and returned by this method.
createExpressionContext Creates an expression context relating to the algorithm.
createExpressionContextScopeForChildAlgorithm Creates a new expression context scope for a child algorithm within the model.
createInstance
deactivateChildAlgorithm Deactivates the child algorithm with matching id.
dependentChildAlgorithms Returns a list of the child algorithm IDs depending on the child algorithm with the specified childId.
dependsOnChildAlgorithms Returns a list of the child algorithm IDs on which the child algorithm with the specified childId depends upon.
destinationParameterDefinitions Returns a list of destination parameters definitions utilized by the algorithm.
displayName
flags Returns the flags indicating how and when the algorithm operates and should be exposed to users.
fromFile Reads the model from a file, at the specified path.
group
groupId
hasHtmlOutputs Returns true if this algorithm generates HTML outputs.
helpContent Returns the model’s help contents (a free-form map of values describing the algorithm’s use and metadata).
helpString Returns a localised help string for the algorithm.
helpUrl
icon
id Returns the unique ID for the algorithm, which is a combination of the algorithm provider’s ID and the algorithms unique name (e.g.
initAlgorithm
name
otherParametersDependOnParameter Returns true if any other model parameters depend on the parameter with the specified name (e.g.
outputDefinition Returns a matching output by name.
outputDefinitions Returns an ordered list of output definitions utilized by the algorithm.
parameterAsBool
parameterAsCompatibleSourceLayerPath
parameterAsCrs
parameterAsDouble
parameterAsEnum
parameterAsEnums
parameterAsExpression
parameterAsExtent
parameterAsExtentCrs
parameterAsExtentGeometry
parameterAsFields
parameterAsFile
parameterAsFileOutput
parameterAsInt
parameterAsLayer
parameterAsLayerList
parameterAsMatrix
parameterAsOutputLayer
parameterAsPoint
parameterAsPointCrs
parameterAsRange
parameterAsRasterLayer
parameterAsSink
parameterAsSource
parameterAsString
parameterAsVectorLayer
parameterComponent Returns the parameter component with matching name.
parameterComponents Returns the map of parameter components used by the model.
parameterDefinition Returns a matching parameter by name.
parameterDefinitions Returns an ordered list of parameter definitions utilized by the algorithm.
postProcess Should be called in the main thread following the completion of runPrepared().
postProcessAlgorithm
prepare Prepares the algorithm for execution.
prepareAlgorithm
processAlgorithm
provider Returns the provider to which this algorithm belongs.
removeChildAlgorithm Attempts to remove the child algorithm with matching id.
removeModelParameter Removes an existing model parameter by name.
removeParameter
run Executes the algorithm using the specified parameters.
runPrepared Runs the algorithm, which has been prepared by an earlier call to prepare().
setChildAlgorithm Sets the child algorithm within the model.
setChildAlgorithms Sets the map of child algorithms contained in the model.
setGroup Sets the model group.
setHelpContent Sets the model’s help contents (a free-form map of values describing the algorithm’s use and metadata).
setName Sets the model name.
setParameterComponent Sets a parameter component for the model.
setParameterComponents Sets the map of parameter components used by the model.
setProvider Associates this algorithm with its provider.
setSourceFilePath Sets the source file path for the model, if available.
shortHelpString
sourceFilePath Returns the source file path for the model, if available.
svgIconPath
tags Returns a list of tags which relate to the algorithm, and are used to assist users in searching for suitable algorithms.
toFile Writes the model to a file, at the specified path.
updateDestinationParameters Updates the model’s parameter definitions to include all relevant destination parameters as required by child algorithm ModelOutputs.
updateModelParameter Replaces the definition of an existing parameter (by parameter name) with a new definition.
validateInputCrs Checks whether the coordinate reference systems for the specified set of parameters are valid for the algorithm.
variablesForChildAlgorithm Returns a map of variable name to variable definition for expression context variables which are available for use by child algorithm during model execution.

Attributes

FlagCanCancel
FlagCanRunInBackground
FlagDeprecated
FlagHideFromModeler
FlagHideFromToolbox
FlagRequiresMatchingCrs
FlagSupportsBatch
class VariableDefinition

Bases: sip.wrapper

Definition of a expression context variable available during model execution.

New in version 3.0.

description
source
value
activateChildAlgorithm(self, id: str) → bool

Attempts to activate the child algorithm with matching id. If any child algorithms on which the child depends are not active, then the child will not be activated and false will be returned.

addChildAlgorithm(self, algorithm: QgsProcessingModelChildAlgorithm) → str

Adds a new child algorithm to the model. If a child algorithm already exists in the model with the same child ID then algorithm will be assigned a new autogenerated unique ID. The assigned child ID will be returned.

See also

childAlgorithm()

addModelParameter(self, definition: QgsProcessingParameterDefinition, component: QgsProcessingModelParameter)

Adds a new parameter to the model, with the specified definition and graphical component. Ownership of definition is transferred to the model.

addOutput()
addParameter()
asPythonCode(self) → str

Attempts to convert the model to executable Python code.

asPythonCommand(self, parameters: Dict[str, Any], context: QgsProcessingContext) → str
availableSourcesForChild(self, childId: str, parameterTypes: Iterable[str] = [], outputTypes: Iterable[str] = [], dataTypes: Iterable[int] = []) → object

Returns a list of possible sources which can be used for the parameters for a child algorithm in the model. Returned sources are those which match either one of the specified parameterTypes (see QgsProcessingParameterDefinition.type() ) or on of the specified outputTypes (see QgsProcessingOutputDefinition.type() ). If specified, an optional list of dataTypes can be used to filter the returned sources to those with compatible data types for the parameter/outputs.

canExecute(self) → Tuple[bool, str]
childAlgorithm(self, id: str) → QgsProcessingModelChildAlgorithm

Returns the child algorithm with matching id. If no child algorithm exists with this ID a new algorithm will be added to the model and returned.

childAlgorithms(self) → object

Returns the map of child algorithms contained in the model. The keys are the child algorithm ids (see QgsProcessingModelAlgorithm.ChildAlgorithm.childId()).

See also

childAlgorithm()

childAlgorithmsDependOnParameter(self, name: str) → bool

Returns true if any child algorithms depend on the model parameter with the specified name.

createExpressionContextScopeForChildAlgorithm(self, childId: str, context: QgsProcessingContext, modelParameters: Dict[str, Any] = QVariantMap(), results: Dict[str, Any] = QVariantMap()) → QgsExpressionContextScope

Creates a new expression context scope for a child algorithm within the model.

createInstance(self) → QgsProcessingAlgorithm
deactivateChildAlgorithm(self, id: str)

Deactivates the child algorithm with matching id. All other child algorithms which depend on the child algorithm will also be deactivated.

dependentChildAlgorithms(self, childId: str) → Set[str]

Returns a list of the child algorithm IDs depending on the child algorithm with the specified childId.

dependsOnChildAlgorithms(self, childId: str) → Set[str]

Returns a list of the child algorithm IDs on which the child algorithm with the specified childId depends upon.

displayName(self) → str
fromFile(self, path: str) → bool

Reads the model from a file, at the specified path.

See also

toFile()

group(self) → str
groupId(self) → str
helpContent(self) → Dict[str, Any]

Returns the model’s help contents (a free-form map of values describing the algorithm’s use and metadata).

See also

setHelpContent()

helpUrl(self) → str
icon(self) → QIcon
initAlgorithm(self, configuration: Dict[str, Any] = QVariantMap())
name(self) → str
otherParametersDependOnParameter(self, name: str) → bool

Returns true if any other model parameters depend on the parameter with the specified name (e.g. field parameters where name is the parent layer parameter).

parameterAsBool()
parameterAsCompatibleSourceLayerPath()
parameterAsCrs()
parameterAsDouble()
parameterAsEnum()
parameterAsEnums()
parameterAsExpression()
parameterAsExtent()
parameterAsExtentCrs()
parameterAsExtentGeometry()
parameterAsFields()
parameterAsFile()
parameterAsFileOutput()
parameterAsInt()
parameterAsLayer()
parameterAsLayerList()
parameterAsMatrix()
parameterAsOutputLayer()
parameterAsPoint()
parameterAsPointCrs()
parameterAsRange()
parameterAsRasterLayer()
parameterAsSink()
parameterAsSource()
parameterAsString()
parameterAsVectorLayer()
parameterComponent(self, name: str) → QgsProcessingModelParameter

Returns the parameter component with matching name. If no parameter component exists with this name a new component will be added to the model and returned.

parameterComponents(self) → object

Returns the map of parameter components used by the model. The keys should match the algorithm’s parameter names (see parameterDefinitions() ).

postProcessAlgorithm()
prepareAlgorithm()
processAlgorithm(self, parameters: Dict[str, Any], context: QgsProcessingContext, feedback: QgsProcessingFeedback) → Dict[str, Any]
removeChildAlgorithm(self, id: str) → bool

Attempts to remove the child algorithm with matching id. Returns true if the algorithm could be removed, or false if the algorithm could not be removed (e.g. due to other child algorithms depending on it).

removeModelParameter(self, name: str)

Removes an existing model parameter by name. The definition of the matching parameter is deleted.

removeParameter()
setChildAlgorithm(self, algorithm: QgsProcessingModelChildAlgorithm)

Sets the child algorithm within the model. If a child algorithm already exists in the model with the same child ID then that algorithm will be replaced.

setChildAlgorithms(self, childAlgorithms: Dict[str, QgsProcessingModelChildAlgorithm])

Sets the map of child algorithms contained in the model. The keys are the child algorithm ids (see QgsProcessingModelAlgorithm.ChildAlgorithm.childId()). All existing child algorithms will be replaced.

See also

childAlgorithm()

setGroup(self, group: str)

Sets the model group.

See also

group()

setHelpContent(self, contents: Dict[str, Any])

Sets the model’s help contents (a free-form map of values describing the algorithm’s use and metadata).

See also

helpContent()

setName(self, name: str)

Sets the model name.

See also

name()

setParameterComponent(self, component: QgsProcessingModelParameter)

Sets a parameter component for the model. If a parameter component already exists in the model with the same parameter name then that component will be replaced.

setParameterComponents(self, parameterComponents: Dict[str, QgsProcessingModelParameter])

Sets the map of parameter components used by the model. The keys should match the algorithm’s parameter names (see parameterDefinitions() ). All existing parameter components will be replaced.

setSourceFilePath(self, path: str)

Sets the source file path for the model, if available.

See also

sourceFilePath()

shortHelpString(self) → str
sourceFilePath(self) → str

Returns the source file path for the model, if available.

svgIconPath(self) → str
toFile(self, path: str) → bool

Writes the model to a file, at the specified path.

See also

fromFile()

updateDestinationParameters(self)

Updates the model’s parameter definitions to include all relevant destination parameters as required by child algorithm ModelOutputs. Must be called whenever child algorithm ModelOutputs are altered.

updateModelParameter(self, definition: QgsProcessingParameterDefinition)

Replaces the definition of an existing parameter (by parameter name) with a new definition. Ownership of definition is transferred to the model, and any existing parameter is deleted.

variablesForChildAlgorithm(self, childId: str, context: QgsProcessingContext, modelParameters: Dict[str, Any] = QVariantMap(), results: Dict[str, Any] = QVariantMap()) → object

Returns a map of variable name to variable definition for expression context variables which are available for use by child algorithm during model execution.

The child algorithm childId and processing context are manadatory. If modelParameters and results are not specified, then only the variable names and sources will be returned, but all variable values will be null. This can be used to determine in advance which variables will be available for a specific child algorithm, e.g. for use in expression builder widgets.

In order to calculate the actual variable value, the input model modelParameters and already executed child algorithm results must be passed.