Class: QgsProcessingModelAlgorithm¶
Model based algorithm with processing.
Class Hierarchy¶
Base classes¶
Abstract base class for processing algorithms. |
Methods
Attempts to activate the child algorithm with matching id. |
|
Adds a new child algorithm to the model. |
|
Adds a new group box to the model. |
|
Adds a new parameter to the model, with the specified definition and graphical component. |
|
Attempts to convert the model to executable Python code, and returns the generated lines of code. |
|
Returns details of available dependencies for the child algorithm with matching id. |
|
Returns a list of possible sources which can be used for the parameter param for a child childId algorithm in the model |
|
Changes a model parameter's internal name from oldName to newName. |
|
Returns the child algorithm with matching id. |
|
Returns the map of child algorithms contained in the model. |
|
Returns |
|
Creates a new expression context scope for a child algorithm within the model. |
|
Deactivates the child algorithm with matching id. |
|
Returns a list of the child algorithm IDs depending on the child algorithm with the specified childId. |
|
Returns a list of the child algorithm IDs on which the child algorithm with the specified childId depends upon. |
|
Returns the parameter values to use as default values when running this model through the designer dialog. |
|
Reads the model from a file, at the specified path. |
|
Returns a list of the group boxes within the model. |
|
Returns the model's help contents (a free-form map of values describing the algorithm's use and metadata). |
|
Loads this model from a QVariantMap, wrapped in a QVariant variant. |
|
Returns |
|
Given a child algorithm ID and output name, attempts to match it to a parameter definition from the overall model. |
|
Returns an ordered list of outputs for the model. |
|
Returns an ordered list of parameters for the model. |
|
Returns |
|
Returns the destination layer tree group name for outputs created by the model. |
|
Returns the parameter component with matching name. |
|
Returns the map of parameter components used by the model. |
|
Attempts to remove the child algorithm with matching id. |
|
Removes the group box with matching uuid from the model. |
|
Removes an existing model parameter by name. |
|
Sets the child algorithm within the model. |
|
Sets the map of child algorithms contained in the model. |
|
Sets the parameter values to use as default values when running this model through the designer dialog. |
|
Sets the model group. |
|
Sets the model's help contents (a free-form map of values describing the algorithm's use and metadata). |
|
Sets the model name. |
|
Sets the destination layer tree group name for outputs created by the model. |
|
Sets the order for sorting outputs for the model. |
|
Sets a parameter component for the model. |
|
Sets the map of parameter components used by the model. |
|
Sets the order for showing parameters for the model. |
|
Sets the source file path for the model, if available. |
|
Sets the map of custom expression context variables for this model. |
|
Returns the source file path for the model, if available. |
|
Writes the model to a file, at the specified path. |
|
Saves this model to a QVariantMap, wrapped in a QVariant. |
|
Updates the model's parameter definitions to include all relevant destination parameters as required by child algorithm ModelOutputs. |
|
Replaces the definition of an existing parameter (by parameter name) with a new definition. |
|
Validates the model, returning |
|
Validates the child algorithm with matching ID, returning |
|
Returns the map of custom expression context variables defined for this model. |
|
Returns a map of variable name to variable definition for expression context variables which are available for use by child algorithm during model execution. |
Static Methods
Makes a name "safe", by replacing any non-alphanumeric characters with underscores. |
- class qgis.core.QgsProcessingModelAlgorithm[source]¶
Bases:
QgsProcessingAlgorithm
- __init__(name: str | None = '', group: str | None = '', groupId: str | None = '')
Constructor for QgsProcessingModelAlgorithm.
- Parameters:
name (Optional[str] = '')
group (Optional[str] = '')
groupId (Optional[str] = '')
- class VariableDefinition[source]¶
Bases:
object
Definition of a expression context variable available during model execution.
QgsProcessingModelAlgorithm.VariableDefinition(value: Any = None, source:
QgsProcessingModelChildParameterSource
= QgsProcessingModelChildParameterSource.fromStaticValue(QVariant()), description: Optional[str] = ‘’) Constructor for a new VariableDefinition with the specifiedvalue
and original parametersource
, anddescription
.QgsProcessingModelAlgorithm.VariableDefinition(a0: QgsProcessingModelAlgorithm.VariableDefinition)
- description: str¶
Translated description of variable
- source: QgsProcessingModelChildParameterSource¶
Original source of variable’s value
- value: object¶
Value of variable
- activateChildAlgorithm(self, id: str | None) bool [source]¶
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 andFalse
will be returned.See also
- Parameters:
id (Optional[str])
- Return type:
bool
- addChildAlgorithm(self, algorithm: QgsProcessingModelChildAlgorithm) str [source]¶
Adds a new child
algorithm
to the model. If a child algorithm already exists in the model with the same child ID thenalgorithm
will be assigned a new autogenerated unique ID. The assigned child ID will be returned.See also
See also
See also
See also
- Parameters:
algorithm (QgsProcessingModelChildAlgorithm)
- Return type:
str
- addGroupBox(self, groupBox: QgsProcessingModelGroupBox)[source]¶
Adds a new group
box
to the model.If an existing group box with the same uuid already exists then its definition will be replaced.
See also
Added in version 3.14.
- Parameters:
groupBox (QgsProcessingModelGroupBox)
- addModelParameter(self, definition: QgsProcessingParameterDefinition | None, component: QgsProcessingModelParameter)[source]¶
Adds a new parameter to the model, with the specified
definition
and graphicalcomponent
. Ownership ofdefinition
is transferred to the model.See also
See also
- Parameters:
definition (Optional[QgsProcessingParameterDefinition])
component (QgsProcessingModelParameter)
- asPythonCode(self, outputType: QgsProcessing.PythonOutputType, indentSize: int) List[str] [source]¶
Attempts to convert the model to executable Python code, and returns the generated lines of code.
The
outputType
argument dictates the desired script type.The
indentSize
arguments specifies the size of indented lines.- Parameters:
outputType (QgsProcessing.PythonOutputType)
indentSize (int)
- Return type:
List[str]
- availableDependenciesForChildAlgorithm(self, childId: str | None) List[QgsProcessingModelChildDependency] ¶
Returns details of available dependencies for the child algorithm with matching id.
Added in version 3.14.
- Parameters:
childId (Optional[str])
- Return type:
- availableSourcesForChild(self, childId: str | None, param: QgsProcessingParameterDefinition | None) List[QgsProcessingModelChildParameterSource] ¶
Returns a list of possible sources which can be used for the parameter
param
for a childchildId
algorithm in the modelThe source compatibilibity is deducted from the parameter type
Added in version 3.44.
- Parameters:
childId (Optional[str])
param (Optional[QgsProcessingParameterDefinition])
- Return type:
- availableSourcesForChild(self, childId: str | None, parameterTypes: Iterable[str | None] = [], outputTypes: Iterable[str | None] = [], dataTypes: Iterable[int] = []) List[QgsProcessingModelChildParameterSource]
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
(seeQgsProcessingParameterDefinition.type()
) or one of the specifiedoutputTypes
(seeQgsProcessingOutputDefinition.type()
). If specified, an optional list ofdataTypes
can be used to filter the returned sources to those with compatible data types for the parameter/outputs.Use it when you need fine grained support for the requested compatible sources
- Parameters:
childId (Optional[str])
parameterTypes (Iterable[Optional[str]] = [])
outputTypes (Iterable[Optional[str]] = [])
dataTypes (Iterable[int] = [])
- Return type:
- changeParameterName(self, oldName: str | None, newName: str | None)[source]¶
Changes a model parameter’s internal name from
oldName
tonewName
.This method will automatically update all model components to relink using the new name.
Added in version 3.26.
- Parameters:
oldName (Optional[str])
newName (Optional[str])
- childAlgorithm(self, id: str | None) 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.See also
See also
- Parameters:
id (Optional[str])
- Return type:
- childAlgorithms(self) Dict[str, QgsProcessingModelChildAlgorithm] ¶
Returns the map of child algorithms contained in the model. The keys are the child algorithm ids (see QgsProcessingModelAlgorithm.ChildAlgorithm.childId()).
See also
See also
See also
- Return type:
Dict[str, QgsProcessingModelChildAlgorithm]
- childAlgorithmsDependOnParameter(self, name: str | None) bool [source]¶
Returns
True
if any child algorithms depend on the model parameter with the specifiedname
.See also
- Parameters:
name (Optional[str])
- Return type:
bool
- createExpressionContextScopeForChildAlgorithm(self, childId: str | None, context: QgsProcessingContext, modelParameters: Dict[str, Any] = {}, results: Dict[str, Any] = {}) QgsExpressionContextScope | None [source]¶
Creates a new expression context scope for a child algorithm within the model.
See also
- Parameters:
childId (Optional[str])
context (QgsProcessingContext)
modelParameters (Dict[str, Any] = {})
results (Dict[str, Any] = {})
- Return type:
Optional[QgsExpressionContextScope]
- deactivateChildAlgorithm(self, id: str | None)[source]¶
Deactivates the child algorithm with matching
id
. All other child algorithms which depend on the child algorithm will also be deactivated.See also
See also
- Parameters:
id (Optional[str])
- dependentChildAlgorithms(self, childId: str | None, conditionalBranch: str | None = '') Set[str] ¶
Returns a list of the child algorithm IDs depending on the child algorithm with the specified
childId
.Optionally, a specific conditional branch which is created by the child algorithm can be specified in order to restrict the returned list to algorithms which depend on this specific branch.
See also
- Parameters:
childId (Optional[str])
conditionalBranch (Optional[str] = '')
- Return type:
Set[str]
- dependsOnChildAlgorithms(self, childId: str | None) Set[str] ¶
Returns a list of the child algorithm IDs on which the child algorithm with the specified
childId
depends upon.See also
- Parameters:
childId (Optional[str])
- Return type:
Set[str]
- designerParameterValues(self) Dict[str, Any] [source]¶
Returns the parameter values to use as default values when running this model through the designer dialog.
This usually corresponds to the last set of parameter values used when the model was run through the designer.
See also
Added in version 3.14.
- Return type:
Dict[str, Any]
- fromFile(self, path: str | None) bool [source]¶
Reads the model from a file, at the specified
path
.See also
- Parameters:
path (Optional[str])
- Return type:
bool
- groupBoxes(self) List[QgsProcessingModelGroupBox] ¶
Returns a list of the group boxes within the model.
See also
Added in version 3.14.
- Return type:
- 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
- Return type:
Dict[str, Any]
- loadVariant(self, variant: Any) bool [source]¶
Loads this model from a QVariantMap, wrapped in a QVariant
variant
. You can useQgsXmlUtils
.readVariant to load it from an XML document.See also
Added in version 3.4.
- Parameters:
variant (Any)
- Return type:
bool
- modelNameMatchesFilePath(self) bool [source]¶
Returns
True
if the model name matches the current modelsourceFilePath()
.Specifically, this method will return true if the complete base name of
sourceFilePath()
is identical (case-insensitive) to the model name.Added in version 3.24.
- Return type:
bool
- modelParameterFromChildIdAndOutputName(self, childId: str | None, childOutputName: str | None) QgsProcessingParameterDefinition | None [source]¶
Given a child algorithm ID and output name, attempts to match it to a parameter definition from the overall model.
Added in version 3.26.
- Parameters:
childId (Optional[str])
childOutputName (Optional[str])
- Return type:
Optional[QgsProcessingParameterDefinition]
- orderedOutputs(self) List[QgsProcessingModelOutput] ¶
Returns an ordered list of outputs for the model.
See also
Added in version 3.32.
- Return type:
List[QgsProcessingModelOutput]
- orderedParameters(self) List[QgsProcessingModelParameter] ¶
Returns an ordered list of parameters for the model.
See also
Added in version 3.14.
- Return type:
- otherParametersDependOnParameter(self, name: str | None) bool [source]¶
Returns
True
if any other model parameters depend on the parameter with the specifiedname
(e.g. field parameters wherename
is the parent layer parameter).See also
- Parameters:
name (Optional[str])
- Return type:
bool
- outputGroup(self) str [source]¶
Returns the destination layer tree group name for outputs created by the model.
See also
Added in version 3.32.
- Return type:
str
- parameterComponent(self, name: str | None) 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.See also
See also
See also
- Parameters:
name (Optional[str])
- Return type:
- parameterComponents(self) Dict[str, QgsProcessingModelParameter] ¶
Returns the map of parameter components used by the model. The keys should match the algorithm’s parameter names (see
parameterDefinitions()
).See also
See also
- Return type:
Dict[str, QgsProcessingModelParameter]
- removeChildAlgorithm(self, id: str | None) bool [source]¶
Attempts to remove the child algorithm with matching
id
. ReturnsTrue
if the algorithm could be removed, orFalse
if the algorithm could not be removed (e.g. due to other child algorithms depending on it).See also
- Parameters:
id (Optional[str])
- Return type:
bool
- removeGroupBox(self, uuid: str | None)[source]¶
Removes the group box with matching
uuid
from the model.See also
See also
Added in version 3.14.
- Parameters:
uuid (Optional[str])
- removeModelParameter(self, name: str | None)[source]¶
Removes an existing model parameter by
name
. The definition of the matching parameter is deleted.See also
See also
- Parameters:
name (Optional[str])
- static safeName(name: str | None, capitalize: bool = False) str [source]¶
Makes a name “safe”, by replacing any non-alphanumeric characters with underscores.
If
capitalize
isTrue
then the string will be converted to a camel case string.Added in version 3.26.
- Parameters:
name (Optional[str])
capitalize (bool = False)
- Return type:
str
- setChildAlgorithm(self, algorithm: QgsProcessingModelChildAlgorithm)[source]¶
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.See also
See also
- Parameters:
algorithm (QgsProcessingModelChildAlgorithm)
- setChildAlgorithms(self, childAlgorithms: Dict[str | None, QgsProcessingModelChildAlgorithm])[source]¶
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
See also
See also
See also
- Parameters:
childAlgorithms (Dict[Optional[str], QgsProcessingModelChildAlgorithm])
- setDesignerParameterValues(self, values: Dict[str, Any])[source]¶
Sets the parameter
values
to use as default values when running this model through the designer dialog.This usually corresponds to the last set of parameter values used when the model was run through the designer.
See also
Added in version 3.14.
- Parameters:
values (Dict[str, Any])
- setGroup(self, group: str | None)[source]¶
Sets the model
group
.See also
group()
- Parameters:
group (Optional[str])
- setHelpContent(self, contents: Dict[str, Any])[source]¶
Sets the model’s help
contents
(a free-form map of values describing the algorithm’s use and metadata).See also
- Parameters:
contents (Dict[str, Any])
- setName(self, name: str | None)[source]¶
Sets the model
name
.See also
name()
- Parameters:
name (Optional[str])
- setOutputGroup(self, group: str | None)[source]¶
Sets the destination layer tree
group
name for outputs created by the model.See also
Added in version 3.32.
- Parameters:
group (Optional[str])
- setOutputOrder(self, order: Iterable[str | None])[source]¶
Sets the
order
for sorting outputs for the model.The
order
list should consist of “output child algorithm id:output name” formatted strings corresponding to existing model outputs.See also
Added in version 3.32.
- Parameters:
order (Iterable[Optional[str]])
- setParameterComponent(self, component: QgsProcessingModelParameter)[source]¶
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.See also
See also
See also
- Parameters:
component (QgsProcessingModelParameter)
- setParameterComponents(self, parameterComponents: Dict[str | None, QgsProcessingModelParameter])[source]¶
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.See also
See also
See also
- Parameters:
parameterComponents (Dict[Optional[str], QgsProcessingModelParameter])
- setParameterOrder(self, order: Iterable[str | None])[source]¶
Sets the
order
for showing parameters for the model.The
order
list should consist of parameter names corresponding to existing modelparameterComponents()
.See also
Added in version 3.14.
- Parameters:
order (Iterable[Optional[str]])
- setSourceFilePath(self, path: str | None)[source]¶
Sets the source file
path
for the model, if available.See also
- Parameters:
path (Optional[str])
- setVariables(self, variables: Dict[str, Any])[source]¶
Sets the map of custom expression context
variables
for this model.These variables are added to the model’s expression context scope, allowing for preset “constant” expression variables to be utilized within the model.
See also
Added in version 3.8.
- Parameters:
variables (Dict[str, Any])
- sourceFilePath(self) str [source]¶
Returns the source file path for the model, if available.
See also
- Return type:
str
- toFile(self, path: str | None) bool [source]¶
Writes the model to a file, at the specified
path
.See also
- Parameters:
path (Optional[str])
- Return type:
bool
- toVariant(self) Any [source]¶
Saves this model to a QVariantMap, wrapped in a QVariant. You can use
QgsXmlUtils
.writeVariant to save it to an XML document.See also
Added in version 3.4.
- Return type:
Any
- updateDestinationParameters(self)[source]¶
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 | None)[source]¶
Replaces the definition of an existing parameter (by parameter name) with a new
definition
. Ownership ofdefinition
is transferred to the model, and any existing parameter is deleted.See also
See also
- Parameters:
definition (Optional[QgsProcessingParameterDefinition])
- validate(self)[source]¶
Validates the model, returning
True
if all child algorithms in the model are valid.- Returns:
True
if the child is validissues: a list of issues encountered during the validation
Added in version 3.14.
- validateChildAlgorithm(self, childId: str | None)[source]¶
Validates the child algorithm with matching ID, returning
True
if all mandatory inputs to the algorithm have valid values.- Parameters:
childId (Optional[str]) -> (bool) – ID for child to validate
- Returns:
True
if the child is validissues: a list of issues encountered during the validation
Added in version 3.14.
- variables(self) Dict[str, Any] [source]¶
Returns the map of custom expression context variables defined for this model.
These variables are added to the model’s expression context scope, allowing for preset “constant” expression variables to be utilized within the model.
See also
Added in version 3.8.
- Return type:
Dict[str, Any]
- variablesForChildAlgorithm(self, childId: str | None, context: QgsProcessingContext | None = None, modelParameters: Dict[str, Any] = {}, results: Dict[str, Any] = {}) Dict[str, QgsProcessingModelAlgorithm.VariableDefinition] ¶
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 processingcontext
are manadatory. IfmodelParameters
andresults
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 algorithmresults
must be passed.- Parameters:
childId (Optional[str])
context (Optional[QgsProcessingContext] = None)
modelParameters (Dict[str, Any] = {})
results (Dict[str, Any] = {})
- Return type: