Subgroup: Processing
Class: QgsProcessingFeatureBasedAlgorithm¶
-
class
qgis.core.
QgsProcessingFeatureBasedAlgorithm
¶ Bases:
qgis._core.QgsProcessingAlgorithm
An abstract QgsProcessingAlgorithm base class for processing algorithms which operate “feature-by-feature”.
Feature based algorithms are algorithms which operate on individual features in isolation. These are algorithms where one feature is output for each input feature, and the output feature result for each input feature is not dependent on any other features present in the source.
For instance, algorithms like “centroids” and “buffers” are feature based algorithms since the centroid or buffer of a feature is calculated for each feature in isolation. An algorithm like “dissolve” is NOT suitable for a feature based algorithm as the dissolved output depends on multiple input features and these features cannot be processed in isolation.
Using QgsProcessingFeatureBasedAlgorithm as the base class for feature based algorithms allows shortcutting much of the common algorithm code for handling iterating over sources and pushing features to output sinks. It also allows the algorithm execution to be optimised in future (for instance allowing automatic multi-thread processing of the algorithm, or use of the algorithm in “chains”, avoiding the need for temporary outputs in multi-step models).
New in version 3.0: Methods
addOutput
addParameter
asPythonCommand
Returns a Python command string which can be executed to run the algorithm using the specified parameters
.canExecute
Returns true if the algorithm can execute. checkParameterValues
Checks the supplied parameter
values to verify that they satisfy the requirements of this algorithm in the suppliedcontext
.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. createInstance
destinationParameterDefinitions
Returns a list of destination parameters definitions utilized by the algorithm. displayName
Returns the translated algorithm name, which should be used for any user-visible display of the algorithm name. flags
Returns the flags indicating how and when the algorithm operates and should be exposed to users. group
Returns the name of the group this algorithm belongs to. groupId
Returns the unique ID of the group this algorithm belongs to. hasHtmlOutputs
Returns true if this algorithm generates HTML outputs. helpString
Returns a localised help string for the algorithm. helpUrl
Returns a url pointing to the algorithm’s help page. icon
Returns an icon for the algorithm. 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
initParameters
Initializes any extra parameters added by the algorithm subclass. inputLayerTypes
Returns the valid input layer types for the source layer for this algorithm. name
Returns the algorithm name, used for identifying the algorithm. outputCrs
Maps the input source coordinate reference system ( inputCrs
) to a corresponding output CRS generated by the algorithm.outputDefinition
Returns a matching output by name
.outputDefinitions
Returns an ordered list of output definitions utilized by the algorithm. outputFields
Maps the input source fields ( inputFields
) to corresponding output fields generated by the algorithm.outputLayerType
Returns the layer type for layers generated by this algorithm, if this is possible to determine in advance. outputName
Returns the translated, user visible name for any layers created by this algorithm. outputWkbType
Maps the input WKB geometry type ( inputWkbType
) to the corresponding output WKB type generated 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
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
processFeature
Processes an individual input feature
from the source.provider
Returns the provider to which this algorithm belongs. removeParameter
request
Returns the feature request used for fetching features to process from the source layer. run
Executes the algorithm using the specified parameters
.runPrepared
Runs the algorithm, which has been prepared by an earlier call to prepare(). setProvider
Associates this algorithm with its provider. shortHelpString
Returns a localised short helper string for the algorithm. sourceCrs
Returns the source’s coordinate reference system. sourceFlags
Returns the processing feature source flags to be used in the algorithm. svgIconPath
Returns a path to an SVG version of the algorithm’s icon. tags
Returns a list of tags which relate to the algorithm, and are used to assist users in searching for suitable algorithms. validateInputCrs
Checks whether the coordinate reference systems for the specified set of parameters
are valid for the algorithm.Attributes
FlagCanCancel
FlagCanRunInBackground
FlagDeprecated
FlagHideFromModeler
FlagHideFromToolbox
FlagRequiresMatchingCrs
FlagSupportsBatch
-
addOutput
()¶
-
addParameter
()¶
-
createInstance
()¶
-
initAlgorithm
(self, configuration: Dict[str, Any] = QVariantMap())¶
-
initParameters
(self, configuration: Dict[str, Any] = QVariantMap())¶ Initializes any extra parameters added by the algorithm subclass. There is no need to declare the input source or output sink, as these are automatically created by QgsProcessingFeatureBasedAlgorithm.
-
inputLayerTypes
(self) → List[int]¶ Returns the valid input layer types for the source layer for this algorithm. By default vector layers with any geometry types (excluding non-spatial, geometryless layers) are accepted.
-
outputCrs
(self, inputCrs: QgsCoordinateReferenceSystem) → QgsCoordinateReferenceSystem¶ Maps the input source coordinate reference system (
inputCrs
) to a corresponding output CRS generated by the algorithm. The default behavior is that the algorithm maintains the same CRS as the input source.This is called once by the base class when creating the output sink for the algorithm (i.e. it is not called once per feature processed).
-
outputFields
(self, inputFields: QgsFields) → QgsFields¶ Maps the input source fields (
inputFields
) to corresponding output fields generated by the algorithm. The default behavior is that the algorithm maintains the same fields as are input. Algorithms which add, remove or modify existing fields should override this method and implement logic here to indicate which fields are output by the algorithm.This is called once by the base class when creating the output sink for the algorithm (i.e. it is not called once per feature processed).
-
outputLayerType
(self) → QgsProcessing.SourceType¶ Returns the layer type for layers generated by this algorithm, if this is possible to determine in advance.
-
outputName
(self) → str¶ Returns the translated, user visible name for any layers created by this algorithm. This name will be used as the default name when loading the resultant layer into a QGIS project.
-
outputWkbType
(self, inputWkbType: QgsWkbTypes.Type) → QgsWkbTypes.Type¶ Maps the input WKB geometry type (
inputWkbType
) to the corresponding output WKB type generated by the algorithm. The default behavior is that the algorithm maintains the same WKB type. This is called once by the base class when creating the output sink for the algorithm (i.e. it is not called once per feature processed).
-
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
()¶
-
postProcessAlgorithm
()¶
-
prepareAlgorithm
()¶
-
processAlgorithm
(self, parameters: Dict[str, Any], context: QgsProcessingContext, feedback: QgsProcessingFeedback) → Dict[str, Any]¶
-
processFeature
(self, feature: QgsFeature, context: QgsProcessingContext, feedback: QgsProcessingFeedback) → QgsFeature¶ Processes an individual input
feature
from the source. Algorithms should implement their logic in this method for performing the algorithm’s operation (e.g. replacing the feature’s geometry with the centroid of the original feature geometry for a ‘centroid’ type algorithm).Implementations should return the modified feature. Returning an invalid feature (e.g. a default constructed
QgsFeature
) will indicate that this feature should be ‘skipped’, and will not be added to the algorithm’s output. Subclasses can use this approach to filter the incoming features as desired.The provided
feedback
object can be used to push messages to the log and for giving feedback to users. Note that handling of progress reports and algorithm cancelation is handled by the base class and subclasses do not need to reimplement this logic.Algorithms can throw a QgsProcessingException if a fatal error occurred which should prevent the algorithm execution from continuing. This can be annoying for users though as it can break valid model execution - so use with extreme caution, and consider using
feedback
to instead report non-fatal processing failures for features instead.
-
removeParameter
()¶
-
request
(self) → QgsFeatureRequest¶ Returns the feature request used for fetching features to process from the source layer. The default implementation requests all attributes and geometry.
-
sourceCrs
(self) → QgsCoordinateReferenceSystem¶ Returns the source’s coordinate reference system. This will only return a valid CRS when called from a subclasses’ processFeature() implementation.
-
sourceFlags
(self) → QgsProcessingFeatureSource.Flag¶ Returns the processing feature source flags to be used in the algorithm.
-