Class: QgsProcessingAlgorithm¶
Abstract base class for processing algorithms.
Note
This is an abstract class, with methods which must be implemented by a subclass.
The following methods must be implemented: createInstance()
, displayName()
, initAlgorithm()
, name()
, processAlgorithm()
Class Hierarchy¶
Subclasses¶
An abstract |
|
Model based algorithm with processing. |
Enums
alias of |
|
alias of |
Abstract Methods
Creates a new instance of the algorithm class. |
|
Returns the translated algorithm name, which should be used for any user-visible display of the algorithm name. |
|
Initializes the algorithm using the specified configuration. |
|
Returns the algorithm name, used for identifying the algorithm. |
|
Runs the algorithm using the specified parameters. |
Methods
Adds an output definition to the algorithm. |
|
Adds a parameter definition to the algorithm. |
|
Returns the number of visible (non-hidden) parameters defined by this algorithm. |
|
Creates a copy of the algorithm, ready for execution. |
|
Returns a list of destination parameters definitions utilized by the algorithm. |
|
Returns |
|
Returns the unique ID for the algorithm, which is a combination of the algorithm provider's ID and the algorithms unique name (e.g. "qgis:mergelayers" ). |
|
Returns a matching output by name. |
|
Returns an ordered list of output definitions utilized by the algorithm. |
|
Evaluates the parameter with matching name to an annotation layer. |
|
Evaluates the parameter with matching name to a static boolean value. |
|
Evaluates the parameter with matching name to a static boolean value. |
|
Evaluates the parameter with matching name to a color, or returns an invalid color if the parameter was not set. |
|
Evaluates the parameter with matching name to a source vector layer file path of compatible format. |
|
Evaluates the parameter with matching name to a source vector layer file path and layer name of compatible format. |
|
Evaluates the parameter with matching name to a connection name string. |
|
Evaluates the parameter with matching name to a coordinate reference system. |
|
Evaluates the parameter with matching name to a database table name string. |
|
Evaluates the parameter with matching name to a DateTime, or returns an invalid date time if the parameter was not set. |
|
Evaluates the parameter with matching name to a static double value. |
|
Evaluates the parameter with matching name to a enum value. |
|
Evaluates the parameter with matching name to a static enum string. |
|
Evaluates the parameter with matching name to list of static enum strings. |
|
Evaluates the parameter with matching name to list of enum values. |
|
Evaluates the parameter with matching name to an expression. |
|
Evaluates the parameter with matching name to a rectangular extent. |
|
Returns the coordinate reference system associated with an extent parameter value. |
|
Evaluates the parameter with matching name to a rectangular extent, and returns a geometry covering this extent. |
|
Evaluates the parameter with matching name to a list of fields. |
|
Evaluates the parameter with matching name to a file/folder name. |
|
Evaluates the parameter with matching name to a list of files (for |
|
Evaluates the parameter with matching name to a file based output destination. |
|
Evaluates the parameter with matching name to a geometry. |
|
Returns the coordinate reference system associated with a geometry parameter value. |
|
Evaluates the parameter with matching name to a static integer value. |
|
Evaluates the parameter with matching name to a list of integer values. |
|
Evaluates the parameter with matching name to a map layer. |
|
Evaluates the parameter with matching name to a list of map layers. |
|
Evaluates the parameter with matching name to a print layout. |
|
Evaluates the parameter with matching name to a print layout item, taken from the specified layout. |
|
Evaluates the parameter with matching name to a matrix/table of values. |
|
Evaluates the parameter with matching name to a mesh layer. |
|
Evaluates the parameter with matching name to a output layer destination. |
|
Evaluates the parameter with matching name to a point. |
|
Evaluates the parameter with matching name to a point cloud layer. |
|
Returns the coordinate reference system associated with an point parameter value. |
|
Evaluates the parameter with matching name to a range of values. |
|
Evaluates the parameter with matching name to a raster layer. |
|
Evaluates the parameter with matching name to a database schema name string. |
|
Evaluates the parameter with matching name to a feature sink. |
|
Evaluates the parameter with matching name to a feature source. |
|
Evaluates the parameter with matching name to a static string value. |
|
Evaluates the parameter with matching name to a list of strings (e.g. field names or point cloud attributes). |
|
Evaluates the parameter with matching name to a vector layer. |
|
Returns a matching parameter by name. |
|
Returns an ordered list of parameter definitions utilized by the algorithm. |
|
Should be called in the main thread following the completion of |
|
Prepares the algorithm for execution. |
|
Returns the provider to which this algorithm belongs. |
|
Removes the parameter with matching name from the algorithm, and deletes any existing definition. |
|
Executes the algorithm using the specified parameters. |
|
Runs the algorithm, which has been prepared by an earlier call to |
|
Associates this algorithm with its provider. |
Virtual Methods
In PyQGIS, only methods marked as virtual
can be safely overridden in a Python subclass of QgsProcessingAlgorithm. See the FAQ for more details.
Returns a JSON serializable variant map containing the specified parameters and context settings. |
|
Returns a Python command string which can be executed to run the algorithm using the specified parameters. |
|
Returns a command string which will execute the algorithm using the specified parameters via the command line qgis_process tool. |
|
Returns a map of default auto-generated parameters to fill in, based on existing parameters. |
|
Returns |
|
Checks the supplied parameter values to verify that they satisfy the requirements of this algorithm in the supplied context. |
|
If an algorithm subclass implements a custom parameters widget, a copy of this widget should be constructed and returned by this method. |
|
Creates an expression context relating to the algorithm. |
|
Returns the flags describing algorithm behavior for documentation purposes. |
|
Returns the flags indicating how and when the algorithm operates and should be exposed to users. |
|
Returns the name of the group this algorithm belongs to. |
|
Returns the unique ID of the group this algorithm belongs to. |
|
Returns a localised help string for the algorithm. |
|
Returns a url pointing to the algorithm's help page. |
|
Returns an icon for the algorithm. |
|
Allows the algorithm to perform any required cleanup tasks. |
|
Prepares the algorithm to run using the specified parameters. |
|
Pre-processes a set of parameters, allowing the algorithm to clean their values. |
|
Returns an optional translated short description of the algorithm. |
|
Returns a localised short helper string for the algorithm. |
|
Returns the vector properties which will be used for the sink with matching name. |
|
Checks whether this algorithm supports in-place editing on the given layer Default implementation returns |
|
Returns a path to an SVG version of the algorithm's icon. |
|
Returns a list of tags which relate to the algorithm, and are used to assist users in searching for suitable algorithms. |
|
Checks whether the coordinate reference systems for the specified set of parameters are valid for the algorithm. |
Static Methods
Returns a user-friendly string to use as an error when a point cloud layer input could not be loaded. |
|
Returns a user-friendly string to use as an error when a raster layer input could not be loaded. |
|
Returns a user-friendly string to use as an error when a sink parameter could not be created. |
|
Returns a user-friendly string to use as an error when a source parameter could not be loaded. |
|
Returns a user-friendly string to use as an error when a feature cannot be written into a sink. |
- class qgis.core.QgsProcessingAlgorithm[source]¶
Bases:
object
- __init__()
Constructor for QgsProcessingAlgorithm.
initAlgorithm()
should be called after creating an algorithm to ensure it can correctly configure itsparameterDefinitions()
andoutputDefinitions()
. Alternatively, callingcreate()
will return a pre-initialized copy of the algorithm.
- Flag¶
alias of
ProcessingAlgorithmFlag
- Flags¶
alias of
ProcessingAlgorithmFlags
- PropertyAvailability¶
alias of
ProcessingPropertyAvailability
- class VectorProperties¶
Bases:
object
Properties of a vector source or sink used in an algorithm.
Added in version 3.14.
- availability: ProcessingPropertyAvailability¶
Availability of the properties. By default properties are not available.
- crs: QgsCoordinateReferenceSystem¶
Coordinate Reference System
- addOutput(self, outputDefinition: QgsProcessingOutputDefinition | None) bool [source]¶
Adds an output
definition
to the algorithm. Ownership of the definition is transferred to the algorithm. ReturnsTrue
if the output could be successfully added, orFalse
if the output could not be added (e.g. as a result of a duplicate name).This should usually be called from a subclass’
initAlgorithm()
implementation.Note that in some cases output creation can be automatically performed when calling
addParameter()
. See the notes inaddParameter()
for a description of when this occurs.See also
See also
- Parameters:
outputDefinition (Optional[QgsProcessingOutputDefinition])
- Return type:
bool
- addParameter(self, parameterDefinition: QgsProcessingParameterDefinition | None, createOutput: bool = True) bool [source]¶
Adds a parameter
definition
to the algorithm. Ownership of the definition is transferred to the algorithm. ReturnsTrue
if parameter could be successfully added, orFalse
if the parameter could not be added (e.g. as a result of a duplicate name).This should usually be called from a subclass’
initAlgorithm()
implementation.If the
createOutput
argument isTrue
, then a corresponding output definition will also be created (and added to the algorithm) where appropriate. E.g. when adding aQgsProcessingParameterVectorDestination
andcreateOutput
isTrue
, then aQgsProcessingOutputVectorLayer
output will be created and added to the algorithm. There is no need to calladdOutput()
to manually add a corresponding output for this vector. IfcreateOutput
isFalse
then this automatic output creation will not occur.See also
See also
- Parameters:
parameterDefinition (Optional[QgsProcessingParameterDefinition])
createOutput (bool = True)
- Return type:
bool
- virtual asMap(self, parameters: Dict[str, Any], context: QgsProcessingContext) Dict[str, Any] [source]¶
Returns a JSON serializable variant map containing the specified
parameters
andcontext
settings.Added in version 3.24.
- Parameters:
parameters (Dict[str, Any])
context (QgsProcessingContext)
- Return type:
Dict[str, Any]
- virtual asPythonCommand(self, parameters: Dict[str, Any], context: QgsProcessingContext) str [source]¶
Returns a Python command string which can be executed to run the algorithm using the specified
parameters
.Algorithms which cannot be run from a Python command should return an empty string.
- Parameters:
parameters (Dict[str, Any])
context (QgsProcessingContext)
- Return type:
str
- virtual asQgisProcessCommand(self, parameters: Dict[str, Any], context: QgsProcessingContext)[source]¶
Returns a command string which will execute the algorithm using the specified
parameters
via the command line qgis_process tool.Note that some combinations of parameter types and values cannot be represented as a qgis_process string.
- Parameters:
parameters (Dict[str, Any]) – algorithm parameters
context (
QgsProcessingContext
) -> (str) – processing context
- Returns:
equivalent qgis_process command
ok:
True
if the command was successfully generated
Added in version 3.24.
- virtual autogenerateParameterValues(self, existingParameters: Dict[str, Any], changedParameter: str | None, mode: Qgis.ProcessingMode) Dict[str, Any] [source]¶
Returns a map of default auto-generated parameters to fill in, based on existing parameters.
This method is used to automatically fill parameter values when a row is added or modified in the batch processing interface, or automatically update other parameter values when parameters are modified in the toolbox mode.
- Parameters:
existingParameters (Dict[str, Any]) – map of current parameter values
changedParameter (Optional[str]) – name of parameter which has just been changed, triggering the update of default parameter values
mode (Qgis.ProcessingMode) – current Processing mode. Allows different autogenerate behavior for batch mode, modeler or toolbox.
- Return type:
Dict[str, Any]
- Returns:
map of default parameter values to use for the algorithm. Any matching parameters included in the map will be automatically overridden with the value from the returned map. Parameter names not included in the returned map will remain unchanged.
The default behavior is to return an empty map, indicating that no parameters should be automatically generated.
Added in version 3.44.
- virtual canExecute(self)[source]¶
Returns
True
if the algorithm can execute. Algorithm subclasses can returnFalse
here to indicate that they are not able to execute, e.g. as a result of unmet external dependencies. If specified, theerrorMessage
argument will be filled with a localised error message describing why the algorithm cannot execute.
- virtual checkParameterValues(self, parameters: Dict[str, Any], context: QgsProcessingContext)[source]¶
Checks the supplied
parameter
values to verify that they satisfy the requirements of this algorithm in the suppliedcontext
. Themessage
parameter will be filled with explanatory text if validation fails. Overridden implementations should also check this base class implementation.- Returns:
True
if parameters are acceptable for the algorithm.- Parameters:
parameters (Dict[str, Any])
context (
QgsProcessingContext
) -> (bool)
- countVisibleParameters(self) int [source]¶
Returns the number of visible (non-hidden) parameters defined by this algorithm.
- Return type:
int
- create(self, configuration: Dict[str, Any] = {}) QgsProcessingAlgorithm | None [source]¶
Creates a copy of the algorithm, ready for execution.
This method returns a new, preinitialized copy of the algorithm, ready for executing.
The
configuration
argument allows passing of a map of configuration settings to the algorithm, allowing it to dynamically adjust its initialized parameters and outputs according to this configuration. This is generally used only for algorithms in a model, allowing them to adjust their behavior at run time according to some user configuration.Raises a
QgsProcessingException
if a new algorithm instance could not be created, e.g. if there is an issue with the subclass’createInstance()
method.See also
- Parameters:
configuration (Dict[str, Any] = {})
- Return type:
Optional[QgsProcessingAlgorithm]
- virtual createCustomParametersWidget(self, parent: QWidget | None = None) QWidget | None [source]¶
If an algorithm subclass implements a custom parameters widget, a copy of this widget should be constructed and returned by this method. The base class implementation returns
None
, which indicates that an autogenerated parameters widget should be used.- Parameters:
parent (Optional[QWidget] = None)
- Return type:
Optional[QWidget]
- virtual createExpressionContext(self, parameters: Dict[str, Any], context: QgsProcessingContext, source: QgsProcessingFeatureSource | None = None) QgsExpressionContext [source]¶
Creates an expression context relating to the algorithm. This can be called by algorithms to create a new expression context ready for evaluating expressions within the algorithm. Optionally, a
source
can be specified which will be used to populate the context if it implements theQgsExpressionContextGenerator
interface.- Parameters:
parameters (Dict[str, Any])
context (QgsProcessingContext)
source (Optional[QgsProcessingFeatureSource] = None)
- Return type:
- abstract createInstance(self) QgsProcessingAlgorithm | None [source]¶
Creates a new instance of the algorithm class.
This method should return a ‘pristine’ instance of the algorithm class.
- Return type:
Optional[QgsProcessingAlgorithm]
- destinationParameterDefinitions(self) List[QgsProcessingParameterDefinition] [source]¶
Returns a list of destination parameters definitions utilized by the algorithm.
See also
- Return type:
- abstract displayName(self) str [source]¶
Returns the translated algorithm name, which should be used for any user-visible display of the algorithm name.
Algorithm display names should be short, e.g. ideally no more than 3 or 4 words. The name should use sentence case (e.g. “Raster layer statistics”, not “Raster Layer Statistics”).
See also
See also
- Return type:
str
- virtual documentationFlags(self) Qgis.ProcessingAlgorithmDocumentationFlags [source]¶
Returns the flags describing algorithm behavior for documentation purposes.
The default is to return no flags.
Added in version 3.40.
- Return type:
- virtual flags(self) Qgis.ProcessingAlgorithmFlags [source]¶
Returns the flags indicating how and when the algorithm operates and should be exposed to users. Default flags are FlagSupportsBatch and FlagCanCancel.
- Return type:
- virtual group(self) str [source]¶
Returns the name of the group this algorithm belongs to. This string should be localised.
See also
See also
- Return type:
str
- virtual groupId(self) str [source]¶
Returns the unique ID of the group this algorithm belongs to. This string should be fixed for the algorithm, and must not be localised. The group id should be unique within each provider. Group id should contain lowercase alphanumeric characters only and no spaces or other formatting characters.
See also
- Return type:
str
- hasHtmlOutputs(self) bool [source]¶
Returns
True
if this algorithm generates HTML outputs.- Return type:
bool
- virtual helpString(self) str [source]¶
Returns a localised help string for the algorithm. Algorithm subclasses should implement either
helpString()
orhelpUrl()
.See also
See also
Deprecated since version 3.40: Unused, will be removed in QGIS 4.0.
- Return type:
str
- virtual helpUrl(self) str [source]¶
Returns a url pointing to the algorithm’s help page.
See also
See also
- Return type:
str
- id(self) str [source]¶
Returns the unique ID for the algorithm, which is a combination of the algorithm provider’s ID and the algorithms unique name (e.g. “qgis:mergelayers” ).
See also
See also
- Return type:
str
- abstract initAlgorithm(self, configuration: Dict[str, Any] = {})[source]¶
Initializes the algorithm using the specified
configuration
.This should be called directly after creating algorithms and before retrieving any
parameterDefinitions()
oroutputDefinitions()
.Subclasses should use their implementations to add all required input parameter and output definitions (which can be dynamically adjusted according to
configuration
).Dynamic configuration can be used by algorithms which alter their behavior when used inside processing models. For instance, a “feature router” type algorithm which sends input features to one of any number of outputs sinks based on some preconfigured filter parameters can use the init method to create these outputs based on the specified
configuration
.See also
See also
- Parameters:
configuration (Dict[str, Any] = {})
- static invalidPointCloudError(parameters: Dict[str, Any], name: str | None) str [source]¶
Returns a user-friendly string to use as an error when a point cloud layer input could not be loaded.
The
parameters
argument should give the algorithms parameter map, and thename
should correspond to the invalid point cloud parameter name.See also
See also
See also
Added in version 3.32.
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
- Return type:
str
- static invalidRasterError(parameters: Dict[str, Any], name: str | None) str [source]¶
Returns a user-friendly string to use as an error when a raster layer input could not be loaded.
The
parameters
argument should give the algorithms parameter map, and thename
should correspond to the invalid raster parameter name.See also
See also
See also
Added in version 3.2.
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
- Return type:
str
- static invalidSinkError(parameters: Dict[str, Any], name: str | None) str [source]¶
Returns a user-friendly string to use as an error when a sink parameter could not be created.
The
parameters
argument should give the algorithms parameter map, and thename
should correspond to the invalid sink parameter name.See also
See also
See also
Added in version 3.2.
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
- Return type:
str
- static invalidSourceError(parameters: Dict[str, Any], name: str | None) str [source]¶
Returns a user-friendly string to use as an error when a source parameter could not be loaded.
The
parameters
argument should give the algorithms parameter map, and thename
should correspond to the invalid source parameter name.See also
See also
See also
Added in version 3.2.
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
- Return type:
str
- abstract name(self) str [source]¶
Returns the algorithm name, used for identifying the algorithm. This string should be fixed for the algorithm, and must not be localised. The name should be unique within each provider. Names should contain lowercase alphanumeric characters only and no spaces or other formatting characters.
See also
See also
See also
- Return type:
str
- outputDefinition(self, name: str | None) QgsProcessingOutputDefinition | None [source]¶
Returns a matching output by
name
. Matching is done in a case-insensitive manner.See also
- Parameters:
name (Optional[str])
- Return type:
Optional[QgsProcessingOutputDefinition]
- outputDefinitions(self) List[QgsProcessingOutputDefinition] [source]¶
Returns an ordered list of output definitions utilized by the algorithm.
See also
See also
- Return type:
- parameterAsAnnotationLayer(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) QgsAnnotationLayer | None [source]¶
Evaluates the parameter with matching
name
to an annotation layer.Annotation layers will be taken from
context
’s active project. Callers do not need to handle deletion of the returned layer.Warning
Working with annotation layers is generally not thread safe (unless the layers are from a
QgsProject
loaded directly in a background thread). Ensure your algorithm returns the QgsProcessingAlgorithm.FlagNoThreading flag or only accesses annotation layers from aprepareAlgorithm()
orpostProcessAlgorithm()
step.Added in version 3.22.
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
Optional[QgsAnnotationLayer]
- parameterAsBool(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) bool [source]¶
Evaluates the parameter with matching
name
to a static boolean value.- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
bool
- parameterAsBoolean(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) bool [source]¶
Evaluates the parameter with matching
name
to a static boolean value.Added in version 3.8.
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
bool
- parameterAsColor(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) QColor [source]¶
Evaluates the parameter with matching
name
to a color, or returns an invalid color if the parameter was not set.Added in version 3.10.
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
QColor
- parameterAsCompatibleSourceLayerPath(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext, compatibleFormats: Iterable[str | None], preferredFormat: str | None = '', feedback: QgsProcessingFeedback | None = None) str [source]¶
Evaluates the parameter with matching
name
to a source vector layer file path of compatible format.If the parameter is evaluated to an existing layer, and that layer is not of the format listed in the
compatibleFormats
argument, then the layer will first be exported to a compatible format in a temporary location. The function will then return the path to that temporary file.compatibleFormats
should consist entirely of lowercase file extensions, e.g. ‘shp’.The
preferredFormat
argument is used to specify to desired file extension to use when a temporary layer export is required.When an algorithm is capable of handling multi-layer input files (such as Geopackage), it is preferable to use
parameterAsCompatibleSourceLayerPathAndLayerName()
which may avoid conversion in more situations.- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
compatibleFormats (Iterable[Optional[str]])
preferredFormat (Optional[str] = '')
feedback (Optional[QgsProcessingFeedback] = None)
- Return type:
str
- parameterAsCompatibleSourceLayerPathAndLayerName(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext, compatibleFormats: Iterable[str | None], preferredFormat: str | None = '', feedback: QgsProcessingFeedback | None = None)[source]¶
Evaluates the parameter with matching
name
to a source vector layer file path and layer name of compatible format.If the parameter is evaluated to an existing layer, and that layer is not of the format listed in the
compatibleFormats
argument, then the layer will first be exported to a compatible format in a temporary location. The function will then return the path to that temporary file.compatibleFormats
should consist entirely of lowercase file extensions, e.g. ‘shp’.The
preferredFormat
argument is used to specify to desired file extension to use when a temporary layer export is required. This defaults to shapefiles, because shapefiles are the future (don’t believe the geopackage hype!).This method should be preferred over
parameterAsCompatibleSourceLayerPath()
when an algorithm is able to correctly handle files with multiple layers. UnlikeparameterAsCompatibleSourceLayerPath()
, it will not force a conversion in this case and will return the target layer name in thelayerName
argument.- Parameters:
parameters (Dict[str, Any]) – input parameter value map
name (Optional[str]) – name of target parameter
context (QgsProcessingContext) – processing context
compatibleFormats (Iterable[Optional[str]]) – a list of lowercase file extensions compatible with the algorithm
preferredFormat (Optional[str] = '') – preferred format extension to use if conversion if required
feedback (Optional[QgsProcessingFeedback] = None) -> (str) – feedback object
- Returns:
path to source layer, or nearly converted compatible layer
layerName: the target layer name for multi-layer sources (e.g. Geopackage)
Added in version 3.10.
- parameterAsConnectionName(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) str [source]¶
Evaluates the parameter with matching
name
to a connection name string.Added in version 3.14.
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
str
- parameterAsCrs(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) QgsCoordinateReferenceSystem [source]¶
Evaluates the parameter with matching
name
to a coordinate reference system.- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
- parameterAsDatabaseTableName(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) str [source]¶
Evaluates the parameter with matching
name
to a database table name string.Added in version 3.14.
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
str
- parameterAsDateTime(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) QDateTime [source]¶
Evaluates the parameter with matching
name
to a DateTime, or returns an invalid date time if the parameter was not set.Added in version 3.14.
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
QDateTime
- parameterAsDouble(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) float [source]¶
Evaluates the parameter with matching
name
to a static double value.- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
float
- parameterAsEnum(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) int [source]¶
Evaluates the parameter with matching
name
to a enum value.- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
int
- parameterAsEnumString(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) str [source]¶
Evaluates the parameter with matching
name
to a static enum string.Added in version 3.18.
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
str
- parameterAsEnumStrings(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) List[str] [source]¶
Evaluates the parameter with matching
name
to list of static enum strings.Added in version 3.18.
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
List[str]
- parameterAsEnums(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) List[int] ¶
Evaluates the parameter with matching
name
to list of enum values.- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
List[int]
- parameterAsExpression(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) str [source]¶
Evaluates the parameter with matching
name
to an expression.- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
str
- parameterAsExtent(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext, crs: QgsCoordinateReferenceSystem = QgsCoordinateReferenceSystem()) QgsRectangle [source]¶
Evaluates the parameter with matching
name
to a rectangular extent.If
crs
is set, and the original coordinate reference system of the parameter can be determined, then the extent will be automatically reprojected so that it is in the specifiedcrs
. In this case the extent of the reproject rectangle will be returned.See also
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
crs (
QgsCoordinateReferenceSystem
= QgsCoordinateReferenceSystem())
- Return type:
- parameterAsExtentCrs(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) QgsCoordinateReferenceSystem [source]¶
Returns the coordinate reference system associated with an extent parameter value.
See also
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
- parameterAsExtentGeometry(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext, crs: QgsCoordinateReferenceSystem = QgsCoordinateReferenceSystem()) QgsGeometry [source]¶
Evaluates the parameter with matching
name
to a rectangular extent, and returns a geometry covering this extent.If
crs
is set, and the original coordinate reference system of the parameter can be determined, then the extent will be automatically reprojected so that it is in the specifiedcrs
. UnlikeparameterAsExtent()
, the reprojected rectangle returned by this function will no longer be a rectangle itself (i.e. this method returns the geometry of the actual reprojected rectangle, whileparameterAsExtent()
returns just the extent of the reprojected rectangle).See also
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
crs (
QgsCoordinateReferenceSystem
= QgsCoordinateReferenceSystem())
- Return type:
- parameterAsFields(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) List[str] [source]¶
Evaluates the parameter with matching
name
to a list of fields.Deprecated since version 3.40: Use
parameterAsStrings()
instead.- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
List[str]
- parameterAsFile(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) str [source]¶
Evaluates the parameter with matching
name
to a file/folder name.- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
str
- parameterAsFileList(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) List[str] [source]¶
Evaluates the parameter with matching
name
to a list of files (forQgsProcessingParameterMultipleLayers
inQgsProcessing
:TypeFile mode).Added in version 3.10.
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
List[str]
- parameterAsFileOutput(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) str [source]¶
Evaluates the parameter with matching
name
to a file based output destination.- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
str
- parameterAsGeometry(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext, crs: QgsCoordinateReferenceSystem = QgsCoordinateReferenceSystem()) QgsGeometry [source]¶
Evaluates the parameter with matching
name
to a geometry.If
crs
is set then the geometry will be automatically reprojected so that it is in the specifiedcrs
.See also
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
crs (
QgsCoordinateReferenceSystem
= QgsCoordinateReferenceSystem())
- Return type:
- parameterAsGeometryCrs(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) QgsCoordinateReferenceSystem [source]¶
Returns the coordinate reference system associated with a geometry parameter value.
See also
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
- parameterAsInt(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) int [source]¶
Evaluates the parameter with matching
name
to a static integer value.- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
int
- parameterAsInts(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) List[int] ¶
Evaluates the parameter with matching
name
to a list of integer values.Added in version 3.4.
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
List[int]
- parameterAsLayer(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) QgsMapLayer | None [source]¶
Evaluates the parameter with matching
name
to a map layer.Layers will either be taken from
context
’s active project, or loaded from external sources and stored temporarily in thecontext
. In either case, callers do not need to handle deletion of the returned layer.- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
Optional[QgsMapLayer]
- parameterAsLayerList(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext, flags: QgsProcessing.LayerOptionsFlags | QgsProcessing.LayerOptionsFlag = QgsProcessing.LayerOptionsFlags()) List[QgsMapLayer] ¶
Evaluates the parameter with matching
name
to a list of map layers. Theflags
are used to set options for loading layers (e.g. skip index generation).- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
flags (Union[QgsProcessing.LayerOptionsFlags, QgsProcessing.LayerOptionsFlag] = QgsProcessing.LayerOptionsFlags())
- Return type:
List[QgsMapLayer]
- parameterAsLayout(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) QgsPrintLayout | None [source]¶
Evaluates the parameter with matching
name
to a print layout.Warning
This method is not safe to run in a background thread, so it must either be used within a prepareAlgorithm implementation (which runs in the main thread), or the algorithm must return the FlagNoThreading flag.
Added in version 3.8.
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
Optional[QgsPrintLayout]
- parameterAsLayoutItem(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext, layout: QgsPrintLayout | None) QgsLayoutItem | None [source]¶
Evaluates the parameter with matching
name
to a print layout item, taken from the specifiedlayout
.Warning
This method is not safe to run in a background thread, so it must either be used within a prepareAlgorithm implementation (which runs in the main thread), or the algorithm must return the FlagNoThreading flag.
Added in version 3.8.
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
layout (Optional[QgsPrintLayout])
- Return type:
Optional[QgsLayoutItem]
- parameterAsMatrix(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) List[Any] [source]¶
Evaluates the parameter with matching
name
to a matrix/table of values. Tables are collapsed to a 1 dimensional list.- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
List[Any]
- parameterAsMeshLayer(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) QgsMeshLayer | None [source]¶
Evaluates the parameter with matching
name
to a mesh layer.Layers will either be taken from
context
’s active project, or loaded from external sources and stored temporarily in thecontext
. In either case, callers do not need to handle deletion of the returned layer.Added in version 3.6.
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
Optional[QgsMeshLayer]
- parameterAsOutputLayer(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) str [source]¶
Evaluates the parameter with matching
name
to a output layer destination.- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
str
- parameterAsPoint(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext, crs: QgsCoordinateReferenceSystem = QgsCoordinateReferenceSystem()) QgsPointXY [source]¶
Evaluates the parameter with matching
name
to a point.If
crs
is set then the point will be automatically reprojected so that it is in the specifiedcrs
.See also
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
crs (
QgsCoordinateReferenceSystem
= QgsCoordinateReferenceSystem())
- Return type:
- parameterAsPointCloudLayer(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext, flags: QgsProcessing.LayerOptionsFlags | QgsProcessing.LayerOptionsFlag = QgsProcessing.LayerOptionsFlags()) QgsPointCloudLayer | None [source]¶
Evaluates the parameter with matching
name
to a point cloud layer. Theflags
are used to set options for loading layer (e.g. skip index generation).Layers will either be taken from
context
’s active project, or loaded from external sources and stored temporarily in thecontext
. In either case, callers do not need to handle deletion of the returned layer.Added in version 3.22.
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
flags (Union[QgsProcessing.LayerOptionsFlags, QgsProcessing.LayerOptionsFlag] = QgsProcessing.LayerOptionsFlags())
- Return type:
Optional[QgsPointCloudLayer]
- parameterAsPointCrs(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) QgsCoordinateReferenceSystem [source]¶
Returns the coordinate reference system associated with an point parameter value.
See also
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
- parameterAsRange(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) List[float] ¶
Evaluates the parameter with matching
name
to a range of values.- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
List[float]
- parameterAsRasterLayer(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) QgsRasterLayer | None [source]¶
Evaluates the parameter with matching
name
to a raster layer.Layers will either be taken from
context
’s active project, or loaded from external sources and stored temporarily in thecontext
. In either case, callers do not need to handle deletion of the returned layer.- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
Optional[QgsRasterLayer]
- parameterAsSchema(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) str [source]¶
Evaluates the parameter with matching
name
to a database schema name string.Added in version 3.14.
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
str
- parameterAsSink(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext, fields: QgsFields, geometryType: Qgis.WkbType = Qgis.WkbType.NoGeometry, crs: QgsCoordinateReferenceSystem = QgsCoordinateReferenceSystem(), sinkFlags: QgsFeatureSink.SinkFlags | QgsFeatureSink.SinkFlag = QgsFeatureSink.SinkFlags(), createOptions: Dict[str, Any] = {}, datasourceOptions: Iterable[str | None] = [], layerOptions: Iterable[str | None] = [])[source]¶
Evaluates the parameter with matching
name
to a feature sink.Sinks will either be taken from
context
’s active project, or created from external providers and stored temporarily in thecontext
.The
fields
,geometryType
andcrs
parameters dictate the properties of the resulting feature sink.The
destinationIdentifier
argument will be set to a string which can be used to retrieve the layer corresponding to the sink, e.g. via callingQgsProcessingUtils.mapLayerFromString()
.The
createOptions
argument is used to pass on creation options such as layer name.The
datasourceOptions
andlayerOptions
arguments is used to pass on GDAL-specific format driver options.This function creates a new object and the caller takes responsibility for deleting the returned object.
- Raises:
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
fields (QgsFields)
geometryType (Qgis.WkbType = Qgis.WkbType.NoGeometry)
crs (
QgsCoordinateReferenceSystem
= QgsCoordinateReferenceSystem())sinkFlags (Union[QgsFeatureSink.SinkFlags, QgsFeatureSink.SinkFlag] = QgsFeatureSink.SinkFlags())
createOptions (Dict[str, Any] = {})
datasourceOptions (Iterable[Optional[str]] = [])
layerOptions (Iterable[Optional[str]] = []) -> (Optional[QgsFeatureSink])
- parameterAsSource(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) QgsProcessingFeatureSource | None [source]¶
Evaluates the parameter with matching
name
to a feature source.Sources will either be taken from
context
’s active project, or loaded from external sources and stored temporarily in thecontext
.This function creates a new object and the caller takes responsibility for deleting the returned object.
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
Optional[QgsProcessingFeatureSource]
- parameterAsString(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) str [source]¶
Evaluates the parameter with matching
name
to a static string value.- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
str
- parameterAsStrings(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) List[str] [source]¶
Evaluates the parameter with matching
name
to a list of strings (e.g. field names or point cloud attributes).Added in version 3.32.
- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
List[str]
- parameterAsVectorLayer(self, parameters: Dict[str, Any], name: str | None, context: QgsProcessingContext) QgsVectorLayer | None [source]¶
Evaluates the parameter with matching
name
to a vector layer.Layers will either be taken from
context
’s active project, or loaded from external sources and stored temporarily in thecontext
. In either case, callers do not need to handle deletion of the returned layer.- Parameters:
parameters (Dict[str, Any])
name (Optional[str])
context (QgsProcessingContext)
- Return type:
Optional[QgsVectorLayer]
- parameterDefinition(self, name: str | None) QgsProcessingParameterDefinition | None [source]¶
Returns a matching parameter by
name
. Matching is done in a case-insensitive manner, but exact case matches will be preferred.See also
- Parameters:
name (Optional[str])
- Return type:
Optional[QgsProcessingParameterDefinition]
- parameterDefinitions(self) List[QgsProcessingParameterDefinition] [source]¶
Returns an ordered list of parameter definitions utilized by the algorithm.
See also
See also
See also
- Return type:
- postProcess(self, context: QgsProcessingContext, feedback: QgsProcessingFeedback | None, runResult: bool = True) Dict[str, Any] [source]¶
Should be called in the main thread following the completion of
runPrepared()
. This method allows the algorithm to perform any required cleanup tasks. The returned variant map includes the results evaluated by the algorithm.Note
This method modifies the algorithm instance, so it is not safe to call on algorithms directly retrieved from
QgsProcessingRegistry
andQgsProcessingProvider
. Instead, a copy of the algorithm should be created withclone()
andprepare()
/runPrepared()
called on the copy.Since QGIS 3.38,
postProcess()
will always be called even for unsuccessful run executions, to allow the algorithm to gracefully clean up. TherunResult
argument is used to indicate whether the run was successful. The algorithm’spostProcessAlgorithm()
method will only be called whenrunResult
isTrue
.- Parameters:
context (QgsProcessingContext)
feedback (Optional[QgsProcessingFeedback])
runResult (bool = True)
- Return type:
Dict[str, Any]
- virtual postProcessAlgorithm(self, context: QgsProcessingContext, feedback: QgsProcessingFeedback | None) Dict[str, Any] [source]¶
Allows the algorithm to perform any required cleanup tasks. The returned variant map includes the results evaluated by the algorithm. These may be output layer references, or calculated values such as statistical calculations.
The
context
argument specifies the context in which the algorithm was run.Postprocess progress should be reported using the supplied
feedback
object. Additionally, well-behaved algorithms should periodically checkfeedback
to determine whether the post processing should be canceled and exited early.postProcessAlgorithm should be used to handle any thread-sensitive cleanup which is required by the algorithm. It will always be called from the same thread that
context
has thread affinity with. While this will generally be the main thread, it is not guaranteed. For instance, algorithms which are run as a step in a larger model or as a subcomponent of a script-based algorithm will call postProcessAlgorithm from the same thread as that model/script it being executed in.postProcessAlgorithm will not be called if the
prepareAlgorithm()
step failed (returnedFalse
), or if an exception was raised by theprocessAlgorithm()
step.- Return type:
Dict[str, Any]
- Returns:
A map of algorithm outputs. These may be output layer references, or calculated values such as statistical calculations. Implementations which return a non-empty map will override any results returned by
processAlgorithm()
.
See also
See also
- Parameters:
context (QgsProcessingContext)
feedback (Optional[QgsProcessingFeedback])
- prepare(self, parameters: Dict[str, Any], context: QgsProcessingContext, feedback: QgsProcessingFeedback | None) bool [source]¶
Prepares the algorithm for execution. This must be run in the main thread, and allows the algorithm to pre-evaluate input parameters in a thread-safe manner. This must be called before calling
runPrepared()
(which is safe to do in any thread).See also
See also
Note
This method modifies the algorithm instance, so it is not safe to call on algorithms directly retrieved from
QgsProcessingRegistry
andQgsProcessingProvider
. Instead, a copy of the algorithm should be created withclone()
andprepare()
/runPrepared()
called on the copy.- Parameters:
parameters (Dict[str, Any])
context (QgsProcessingContext)
feedback (Optional[QgsProcessingFeedback])
- Return type:
bool
- virtual prepareAlgorithm(self, parameters: Dict[str, Any], context: QgsProcessingContext, feedback: QgsProcessingFeedback | None) bool [source]¶
Prepares the algorithm to run using the specified
parameters
. Algorithms should implement their logic for evaluating parameter values here. The evaluated parameter results should be stored in member variables ready for a call toprocessAlgorithm()
.The
context
argument specifies the context in which the algorithm is being run.prepareAlgorithm should be used to handle any thread-sensitive preparation which is required by the algorithm. It will always be called from the same thread that
context
has thread affinity with. While this will generally be the main thread, it is not guaranteed. For instance, algorithms which are run as a step in a larger model or as a subcomponent of a script-based algorithm will call prepareAlgorithm from the same thread as that model/script it being executed in.Note that the processAlgorithm step uses a temporary context with affinity for the thread in which the algorithm is executed, making it safe for processAlgorithm implementations to load sources and sinks without issue. Implementing prepareAlgorithm is only required if special thread safe handling is required by the algorithm.
Algorithm preparation progress should be reported using the supplied
feedback
object. Additionally, well-behaved algorithms should periodically checkfeedback
to determine whether the algorithm should be canceled and exited early.If the preparation was successful algorithms must return
True
. If aFalse
value is returned this indicates that the preparation could not be completed, and the algorithm execution will be canceled.- Return type:
bool
- Returns:
True
if preparation was successful.
See also
See also
- Parameters:
parameters (Dict[str, Any])
context (QgsProcessingContext)
feedback (Optional[QgsProcessingFeedback])
- virtual preprocessParameters(self, parameters: Dict[str, Any]) Dict[str, Any] [source]¶
Pre-processes a set of
parameters
, allowing the algorithm to clean their values.This method is automatically called after users enter parameters, e.g. via the algorithm dialog. This method should NOT be called manually by algorithms.
- Parameters:
parameters (Dict[str, Any])
- Return type:
Dict[str, Any]
- abstract processAlgorithm(self, parameters: Dict[str, Any], context: QgsProcessingContext, feedback: QgsProcessingFeedback | None) Dict[str, Any] [source]¶
Runs the algorithm using the specified
parameters
. Algorithms should implement their custom processing logic here.The
context
argument gives a temporary context with thread affinity matching the thread in which the algorithm is being run. This is a cut-back copy of the context passed to theprepareAlgorithm()
andpostProcessAlgorithm()
steps, but it is generally safe for most algorithms to utilize this context for loading layers and creating sinks. Any loaded layers or sinks created within this temporary context will be transferred back to the main execution context upon successful completion of theprocessAlgorithm()
step.Algorithm progress should be reported using the supplied
feedback
object. Additionally, well-behaved algorithms should periodically checkfeedback
to determine whether the algorithm should be canceled and exited early.This method will not be called if the
prepareAlgorithm()
step failed (returnedFalse
).Implementations of processAlgorithm can throw the
QgsProcessingException
exception to indicate that a fatal error occurred within the execution.- Return type:
Dict[str, Any]
- Returns:
A map of algorithm outputs. These may be output layer references, or calculated values such as statistical calculations. Unless the algorithm subclass overrides the
postProcessAlgorithm()
step this returned map will be used as the output for the algorithm.
See also
See also
- Parameters:
parameters (Dict[str, Any])
context (QgsProcessingContext)
feedback (Optional[QgsProcessingFeedback])
- provider(self) QgsProcessingProvider | None [source]¶
Returns the provider to which this algorithm belongs.
- Return type:
Optional[QgsProcessingProvider]
- removeParameter(self, name: str | None)[source]¶
Removes the parameter with matching
name
from the algorithm, and deletes any existing definition.- Parameters:
name (Optional[str])
- run(self, parameters: Dict[str, Any], context: QgsProcessingContext, feedback: QgsProcessingFeedback | None, configuration: Dict[str, Any] = {}, catchExceptions: bool = True)[source]¶
Executes the algorithm using the specified
parameters
. This method internally creates a copy of the algorithm before running it, so it is safe to call on algorithms directly retrieved fromQgsProcessingRegistry
andQgsProcessingProvider
.The
context
argument specifies the context in which the algorithm is being run.Algorithm progress should be reported using the supplied
feedback
object.If specified,
ok
will be set toTrue
if algorithm was successfully run.If
catchExceptions
is set toFalse
, thenQgsProcessingException
raised during the algorithm run will not be automatically caught and will be raised instead.- Returns:
A map of algorithm outputs. These may be output layer references, or calculated values such as statistical calculations.
Note
this method can only be called from the main thread. Use
prepare()
,runPrepared()
andpostProcess()
if you need to run algorithms from a background thread, or use theQgsProcessingAlgRunnerTask
class.- Parameters:
parameters (Dict[str, Any])
context (QgsProcessingContext)
feedback (Optional[QgsProcessingFeedback])
configuration (Dict[str, Any] = {})
catchExceptions (bool = True) -> (Dict[str, Any])
- runPrepared(self, parameters: Dict[str, Any], context: QgsProcessingContext, feedback: QgsProcessingFeedback | None) Dict[str, Any] [source]¶
Runs the algorithm, which has been prepared by an earlier call to
prepare()
. This method is safe to call from any thread. ReturnsTrue
if the algorithm was successfully executed. AfterrunPrepared()
has finished, thepostProcess()
method should be called from the main thread to allow the algorithm to perform any required cleanup tasks and return its final result.See also
See also
Note
This method modifies the algorithm instance, so it is not safe to call on algorithms directly retrieved from
QgsProcessingRegistry
andQgsProcessingProvider
. Instead, a copy of the algorithm should be created withclone()
andprepare()
/runPrepared()
called on the copy.- Parameters:
parameters (Dict[str, Any])
context (QgsProcessingContext)
feedback (Optional[QgsProcessingFeedback])
- Return type:
Dict[str, Any]
- setProvider(self, provider: QgsProcessingProvider | None)[source]¶
Associates this algorithm with its provider. No transfer of ownership is involved.
- Parameters:
provider (Optional[QgsProcessingProvider])
- virtual shortDescription(self) str [source]¶
Returns an optional translated short description of the algorithm. This should be at most a single sentence, e.g. “Converts 2D features to 3D by sampling a DEM raster.”
Added in version 3.2.
- Return type:
str
- virtual shortHelpString(self) str [source]¶
Returns a localised short helper string for the algorithm. This string should provide a basic description about what the algorithm does and the parameters and outputs associated with it.
See also
See also
- Return type:
str
- virtual sinkProperties(self, sink: str | None, parameters: Dict[str, Any], context: QgsProcessingContext, sourceProperties: Dict[str | None, QgsProcessingAlgorithm.VectorProperties]) QgsProcessingAlgorithm.VectorProperties [source]¶
Returns the vector properties which will be used for the
sink
with matching name.The
parameters
argument specifies the values of all parameters which would be used to generate the sink. These can be used alongside the providedcontext
in order to pre-evaluate inputs when required in order to determine the sink’s properties.The
sourceProperties
map will contain the vector properties of the various sources used as inputs to the algorithm. These will only be available in certain circumstances (e.g. when the algorithm is used within a model), so implementations will need to be adaptable to circumstances when eithersourceParameters
is empty orparameters
is empty, and use whatever information is passed in order to make a best guess determination of the output properties.Added in version 3.14.
- Parameters:
sink (Optional[str])
parameters (Dict[str, Any])
context (QgsProcessingContext)
sourceProperties (Dict[Optional[str], QgsProcessingAlgorithm.VectorProperties])
- Return type:
- virtual supportInPlaceEdit(self, layer: QgsMapLayer | None) bool [source]¶
Checks whether this algorithm supports in-place editing on the given
layer
Default implementation returnsFalse
.- Return type:
bool
- Returns:
True
if the algorithm supports in-place editing
Added in version 3.4.
- Parameters:
layer (Optional[QgsMapLayer])
- virtual svgIconPath(self) str [source]¶
Returns a path to an SVG version of the algorithm’s icon.
See also
- Return type:
str
- virtual tags(self) List[str] [source]¶
Returns a list of tags which relate to the algorithm, and are used to assist users in searching for suitable algorithms. These tags should be localised.
- Return type:
List[str]
- virtual validateInputCrs(self, parameters: Dict[str, Any], context: QgsProcessingContext) bool [source]¶
Checks whether the coordinate reference systems for the specified set of
parameters
are valid for the algorithm. For instance, the base implementation performs checks to ensure that all input CRS are equal ReturnsTrue
ifparameters
have passed the CRS check.- Parameters:
parameters (Dict[str, Any])
context (QgsProcessingContext)
- Return type:
bool
- static writeFeatureError(sink: QgsFeatureSink | None, parameters: Dict[str, Any], name: str | None) str [source]¶
Returns a user-friendly string to use as an error when a feature cannot be written into a sink.
The
sink
argument is the sink into which the feature cannot be written.The
parameters
argument should give the algorithms parameter map, and thename
should correspond to the sink parameter name.Added in version 3.22.
- Parameters:
sink (Optional[QgsFeatureSink])
parameters (Dict[str, Any])
name (Optional[str])
- Return type:
str