QGIS API Documentation 3.41.0-Master (45a0abf3bec)
|
Abstract base class for processing algorithms. More...
#include <qgsprocessingalgorithm.h>
Classes | |
struct | VectorProperties |
Properties of a vector source or sink used in an algorithm. More... | |
Public Member Functions | |
QgsProcessingAlgorithm ()=default | |
Constructor for QgsProcessingAlgorithm. | |
QgsProcessingAlgorithm (const QgsProcessingAlgorithm &other)=delete | |
Algorithms cannot be copied - create() should be used instead. | |
virtual | ~QgsProcessingAlgorithm () |
virtual QVariantMap | asMap (const QVariantMap ¶meters, QgsProcessingContext &context) const |
Returns a JSON serializable variant map containing the specified parameters and context settings. | |
virtual QString | asPythonCommand (const QVariantMap ¶meters, QgsProcessingContext &context) const |
Returns a Python command string which can be executed to run the algorithm using the specified parameters. | |
virtual QString | asQgisProcessCommand (const QVariantMap ¶meters, QgsProcessingContext &context, bool &ok) const |
Returns a command string which will execute the algorithm using the specified parameters via the command line qgis_process tool. | |
virtual bool | canExecute (QString *errorMessage=nullptr) const |
Returns true if the algorithm can execute. | |
virtual bool | checkParameterValues (const QVariantMap ¶meters, QgsProcessingContext &context, QString *message=nullptr) const |
Checks the supplied parameter values to verify that they satisfy the requirements of this algorithm in the supplied context. | |
int | countVisibleParameters () const |
Returns the number of visible (non-hidden) parameters defined by this algorithm. | |
QgsProcessingAlgorithm * | create (const QVariantMap &configuration=QVariantMap()) const |
Creates a copy of the algorithm, ready for execution. | |
virtual QWidget * | createCustomParametersWidget (QWidget *parent=nullptr) const |
If an algorithm subclass implements a custom parameters widget, a copy of this widget should be constructed and returned by this method. | |
virtual QgsExpressionContext | createExpressionContext (const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeatureSource *source=nullptr) const |
Creates an expression context relating to the algorithm. | |
QgsProcessingParameterDefinitions | destinationParameterDefinitions () const |
Returns a list of destination parameters definitions utilized by the algorithm. | |
virtual QString | displayName () const =0 |
Returns the translated algorithm name, which should be used for any user-visible display of the algorithm name. | |
virtual Qgis::ProcessingAlgorithmDocumentationFlags | documentationFlags () const |
Returns the flags describing algorithm behavior for documentation purposes. | |
virtual Qgis::ProcessingAlgorithmFlags | flags () const |
Returns the flags indicating how and when the algorithm operates and should be exposed to users. | |
virtual QString | group () const |
Returns the name of the group this algorithm belongs to. | |
virtual QString | groupId () const |
Returns the unique ID of the group this algorithm belongs to. | |
bool | hasHtmlOutputs () const |
Returns true if this algorithm generates HTML outputs. | |
virtual Q_DECL_DEPRECATED QString | helpString () const |
Returns a localised help string for the algorithm. | |
virtual QString | helpUrl () const |
Returns a url pointing to the algorithm's help page. | |
virtual QIcon | icon () const |
Returns an icon for the algorithm. | |
QString | id () const |
Returns the unique ID for the algorithm, which is a combination of the algorithm provider's ID and the algorithms unique name (e.g. | |
virtual QString | name () const =0 |
Returns the algorithm name, used for identifying the algorithm. | |
QgsProcessingAlgorithm & | operator= (const QgsProcessingAlgorithm &other)=delete |
Algorithms cannot be copied- create() should be used instead. | |
const QgsProcessingOutputDefinition * | outputDefinition (const QString &name) const |
Returns a matching output by name. | |
QgsProcessingOutputDefinitions | outputDefinitions () const |
Returns an ordered list of output definitions utilized by the algorithm. | |
const QgsProcessingParameterDefinition * | parameterDefinition (const QString &name) const |
Returns a matching parameter by name. | |
QgsProcessingParameterDefinitions | parameterDefinitions () const |
Returns an ordered list of parameter definitions utilized by the algorithm. | |
QVariantMap | postProcess (QgsProcessingContext &context, QgsProcessingFeedback *feedback, bool runResult=true) |
Should be called in the main thread following the completion of runPrepared(). | |
bool | prepare (const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback) |
Prepares the algorithm for execution. | |
virtual QVariantMap | preprocessParameters (const QVariantMap ¶meters) |
Pre-processes a set of parameters, allowing the algorithm to clean their values. | |
QgsProcessingProvider * | provider () const |
Returns the provider to which this algorithm belongs. | |
QVariantMap | run (const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback, bool *ok=nullptr, const QVariantMap &configuration=QVariantMap(), bool catchExceptions=true) const |
Executes the algorithm using the specified parameters. | |
QVariantMap | runPrepared (const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback) |
Runs the algorithm, which has been prepared by an earlier call to prepare(). | |
void | setProvider (QgsProcessingProvider *provider) |
Associates this algorithm with its provider. | |
virtual QString | shortDescription () const |
Returns an optional translated short description of the algorithm. | |
virtual QString | shortHelpString () const |
Returns a localised short helper string for the algorithm. | |
virtual QgsProcessingAlgorithm::VectorProperties | sinkProperties (const QString &sink, const QVariantMap ¶meters, QgsProcessingContext &context, const QMap< QString, QgsProcessingAlgorithm::VectorProperties > &sourceProperties) const |
Returns the vector properties which will be used for the sink with matching name. | |
virtual bool | supportInPlaceEdit (const QgsMapLayer *layer) const |
Checks whether this algorithm supports in-place editing on the given layer Default implementation returns false . | |
virtual QString | svgIconPath () const |
Returns a path to an SVG version of the algorithm's icon. | |
virtual QStringList | tags () const |
Returns a list of tags which relate to the algorithm, and are used to assist users in searching for suitable algorithms. | |
virtual bool | validateInputCrs (const QVariantMap ¶meters, QgsProcessingContext &context) const |
Checks whether the coordinate reference systems for the specified set of parameters are valid for the algorithm. | |
Protected Member Functions | |
bool | addOutput (QgsProcessingOutputDefinition *outputDefinition) |
Adds an output definition to the algorithm. | |
bool | addParameter (QgsProcessingParameterDefinition *parameterDefinition, bool createOutput=true) |
Adds a parameter definition to the algorithm. | |
virtual QgsProcessingAlgorithm * | createInstance () const =0 |
Creates a new instance of the algorithm class. | |
virtual void | initAlgorithm (const QVariantMap &configuration=QVariantMap())=0 |
Initializes the algorithm using the specified configuration. | |
QgsAnnotationLayer * | parameterAsAnnotationLayer (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const |
Evaluates the parameter with matching name to an annotation layer. | |
bool | parameterAsBool (const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a static boolean value. | |
bool | parameterAsBoolean (const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a static boolean value. | |
QColor | parameterAsColor (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a color, or returns an invalid color if the parameter was not set. | |
QString | parameterAsCompatibleSourceLayerPath (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr) const |
Evaluates the parameter with matching name to a source vector layer file path of compatible format. | |
QString | parameterAsCompatibleSourceLayerPathAndLayerName (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr, QString *layerName=nullptr) const |
Evaluates the parameter with matching name to a source vector layer file path and layer name of compatible format. | |
QString | parameterAsConnectionName (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a connection name string. | |
QgsCoordinateReferenceSystem | parameterAsCrs (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a coordinate reference system. | |
QString | parameterAsDatabaseTableName (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a database table name string. | |
QDateTime | parameterAsDateTime (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a DateTime, or returns an invalid date time if the parameter was not set. | |
double | parameterAsDouble (const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a static double value. | |
int | parameterAsEnum (const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a enum value. | |
QList< int > | parameterAsEnums (const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const |
Evaluates the parameter with matching name to list of enum values. | |
QString | parameterAsEnumString (const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a static enum string. | |
QStringList | parameterAsEnumStrings (const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const |
Evaluates the parameter with matching name to list of static enum strings. | |
QString | parameterAsExpression (const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const |
Evaluates the parameter with matching name to an expression. | |
QgsRectangle | parameterAsExtent (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem()) const |
Evaluates the parameter with matching name to a rectangular extent. | |
QgsCoordinateReferenceSystem | parameterAsExtentCrs (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const |
Returns the coordinate reference system associated with an extent parameter value. | |
QgsGeometry | parameterAsExtentGeometry (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem()) const |
Evaluates the parameter with matching name to a rectangular extent, and returns a geometry covering this extent. | |
Q_DECL_DEPRECATED QStringList | parameterAsFields (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a list of fields. | |
QString | parameterAsFile (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a file/folder name. | |
QStringList | parameterAsFileList (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a list of files (for QgsProcessingParameterMultipleLayers in QgsProcessing:TypeFile mode). | |
QString | parameterAsFileOutput (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a file based output destination. | |
QgsGeometry | parameterAsGeometry (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem()) const |
Evaluates the parameter with matching name to a geometry. | |
QgsCoordinateReferenceSystem | parameterAsGeometryCrs (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const |
Returns the coordinate reference system associated with a geometry parameter value. | |
int | parameterAsInt (const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a static integer value. | |
QList< int > | parameterAsInts (const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a list of integer values. | |
QgsMapLayer * | parameterAsLayer (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a map layer. | |
QList< QgsMapLayer * > | parameterAsLayerList (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags()) const |
Evaluates the parameter with matching name to a list of map layers. | |
QgsPrintLayout * | parameterAsLayout (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) |
Evaluates the parameter with matching name to a print layout. | |
QgsLayoutItem * | parameterAsLayoutItem (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context, QgsPrintLayout *layout) |
Evaluates the parameter with matching name to a print layout item, taken from the specified layout. | |
QVariantList | parameterAsMatrix (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a matrix/table of values. | |
QgsMeshLayer * | parameterAsMeshLayer (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a mesh layer. | |
QString | parameterAsOutputLayer (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a output layer destination. | |
QgsPointXY | parameterAsPoint (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem()) const |
Evaluates the parameter with matching name to a point. | |
QgsPointCloudLayer * | parameterAsPointCloudLayer (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags()) const |
Evaluates the parameter with matching name to a point cloud layer. | |
QgsCoordinateReferenceSystem | parameterAsPointCrs (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const |
Returns the coordinate reference system associated with an point parameter value. | |
QList< double > | parameterAsRange (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a range of values. | |
QgsRasterLayer * | parameterAsRasterLayer (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a raster layer. | |
QString | parameterAsSchema (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a database schema name string. | |
QgsFeatureSink * | parameterAsSink (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context, QString &destinationIdentifier, const QgsFields &fields, Qgis::WkbType geometryType=Qgis::WkbType::NoGeometry, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem(), QgsFeatureSink::SinkFlags sinkFlags=QgsFeatureSink::SinkFlags(), const QVariantMap &createOptions=QVariantMap(), const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList()) const |
Evaluates the parameter with matching name to a feature sink. | |
QgsProcessingFeatureSource * | parameterAsSource (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a feature source. | |
QString | parameterAsString (const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a static string value. | |
QStringList | parameterAsStrings (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a list of strings (e.g. | |
QgsVectorLayer * | parameterAsVectorLayer (const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const |
Evaluates the parameter with matching name to a vector layer. | |
virtual QVariantMap | postProcessAlgorithm (QgsProcessingContext &context, QgsProcessingFeedback *feedback) |
Allows the algorithm to perform any required cleanup tasks. | |
virtual bool | prepareAlgorithm (const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback) |
Prepares the algorithm to run using the specified parameters. | |
virtual QVariantMap | processAlgorithm (const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback)=0 |
Runs the algorithm using the specified parameters. | |
void | removeParameter (const QString &name) |
Removes the parameter with matching name from the algorithm, and deletes any existing definition. | |
Static Protected Member Functions | |
static QString | invalidPointCloudError (const QVariantMap ¶meters, const QString &name) |
Returns a user-friendly string to use as an error when a point cloud layer input could not be loaded. | |
static QString | invalidRasterError (const QVariantMap ¶meters, const QString &name) |
Returns a user-friendly string to use as an error when a raster layer input could not be loaded. | |
static QString | invalidSinkError (const QVariantMap ¶meters, const QString &name) |
Returns a user-friendly string to use as an error when a sink parameter could not be created. | |
static QString | invalidSourceError (const QVariantMap ¶meters, const QString &name) |
Returns a user-friendly string to use as an error when a source parameter could not be loaded. | |
static QString | writeFeatureError (QgsFeatureSink *sink, const QVariantMap ¶meters, const QString &name) |
Returns a user-friendly string to use as an error when a feature cannot be written into a sink. | |
Friends | |
class | DummyRaiseExceptionAlgorithm |
class | QgsProcessingModelAlgorithm |
class | QgsProcessingProvider |
class | QgsProcessingToolboxProxyModel |
class | TestQgsProcessing |
Abstract base class for processing algorithms.
Definition at line 50 of file qgsprocessingalgorithm.h.
|
default |
Constructor for QgsProcessingAlgorithm.
initAlgorithm() should be called after creating an algorithm to ensure it can correctly configure its parameterDefinitions() and outputDefinitions(). Alternatively, calling create() will return a pre-initialized copy of the algorithm.
|
virtual |
Definition at line 36 of file qgsprocessingalgorithm.cpp.
|
delete |
Algorithms cannot be copied - create() should be used instead.
|
protected |
Adds an output definition to the algorithm.
Ownership of the definition is transferred to the algorithm. Returns true
if the output could be successfully added, or false
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 in addParameter() for a description of when this occurs.
Definition at line 441 of file qgsprocessingalgorithm.cpp.
|
protected |
Adds a parameter definition to the algorithm.
Ownership of the definition is transferred to the algorithm. Returns true
if parameter could be successfully added, or false
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 is true
, then a corresponding output definition will also be created (and added to the algorithm) where appropriate. E.g. when adding a QgsProcessingParameterVectorDestination and createOutput is true
, then a QgsProcessingOutputVectorLayer output will be created and added to the algorithm. There is no need to call addOutput() to manually add a corresponding output for this vector. If createOutput is false
then this automatic output creation will not occur.
Definition at line 393 of file qgsprocessingalgorithm.cpp.
|
virtual |
Returns a JSON serializable variant map containing the specified parameters and context settings.
Definition at line 369 of file qgsprocessingalgorithm.cpp.
|
virtual |
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.
Definition at line 297 of file qgsprocessingalgorithm.cpp.
|
virtual |
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 | algorithm parameters |
context | processing context |
ok | will be set to true if the command was successfully generated |
Definition at line 317 of file qgsprocessingalgorithm.cpp.
|
virtual |
Returns true
if the algorithm can execute.
Algorithm subclasses can return false
here to indicate that they are not able to execute, e.g. as a result of unmet external dependencies. If specified, the errorMessage argument will be filled with a localised error message describing why the algorithm cannot execute.
Definition at line 100 of file qgsprocessingalgorithm.cpp.
|
virtual |
Checks the supplied parameter values to verify that they satisfy the requirements of this algorithm in the supplied context.
The message parameter will be filled with explanatory text if validation fails. Overridden implementations should also check this base class implementation.
true
if parameters are acceptable for the algorithm. Definition at line 105 of file qgsprocessingalgorithm.cpp.
int QgsProcessingAlgorithm::countVisibleParameters | ( | ) | const |
Returns the number of visible (non-hidden) parameters defined by this algorithm.
Definition at line 486 of file qgsprocessingalgorithm.cpp.
QgsProcessingAlgorithm * QgsProcessingAlgorithm::create | ( | const QVariantMap & | configuration = QVariantMap() | ) | const |
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.
Definition at line 42 of file qgsprocessingalgorithm.cpp.
|
virtual |
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 nullptr
, which indicates that an autogenerated parameters widget should be used.
Definition at line 160 of file qgsprocessingalgorithm.cpp.
|
virtual |
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 the QgsExpressionContextGenerator interface.
Definition at line 165 of file qgsprocessingalgorithm.cpp.
|
protectedpure virtual |
Creates a new instance of the algorithm class.
This method should return a 'pristine' instance of the algorithm class.
QgsProcessingParameterDefinitions QgsProcessingAlgorithm::destinationParameterDefinitions | ( | ) | const |
Returns a list of destination parameters definitions utilized by the algorithm.
Definition at line 497 of file qgsprocessingalgorithm.cpp.
|
pure virtual |
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").
|
virtual |
Returns the flags describing algorithm behavior for documentation purposes.
The default is to return no flags.
Definition at line 80 of file qgsprocessingalgorithm.cpp.
|
virtual |
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
Default flags are FlagSupportsBatch and FlagCanCancel.
Reimplemented in QgsProcessingFeatureBasedAlgorithm.
Definition at line 95 of file qgsprocessingalgorithm.cpp.
|
inlinevirtual |
Returns the name of the group this algorithm belongs to.
This string should be localised.
Reimplemented in QgsBatchGeocodeAlgorithm.
Definition at line 211 of file qgsprocessingalgorithm.h.
|
inlinevirtual |
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.
Reimplemented in QgsBatchGeocodeAlgorithm.
Definition at line 220 of file qgsprocessingalgorithm.h.
bool QgsProcessingAlgorithm::hasHtmlOutputs | ( | ) | const |
Returns true
if this algorithm generates HTML outputs.
Definition at line 518 of file qgsprocessingalgorithm.cpp.
|
virtual |
Returns a localised help string for the algorithm.
Algorithm subclasses should implement either helpString() or helpUrl().
Definition at line 70 of file qgsprocessingalgorithm.cpp.
|
virtual |
Returns a url pointing to the algorithm's help page.
Definition at line 75 of file qgsprocessingalgorithm.cpp.
|
virtual |
Returns an icon for the algorithm.
Definition at line 85 of file qgsprocessingalgorithm.cpp.
QString QgsProcessingAlgorithm::id | ( | ) | const |
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" ).
Definition at line 52 of file qgsprocessingalgorithm.cpp.
|
protectedpure virtual |
Initializes the algorithm using the specified configuration.
This should be called directly after creating algorithms and before retrieving any parameterDefinitions() or outputDefinitions().
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.
Implemented in QgsProcessingFeatureBasedAlgorithm.
|
staticprotected |
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 the name should correspond to the invalid point cloud parameter name.
Definition at line 1007 of file qgsprocessingalgorithm.cpp.
|
staticprotected |
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 the name should correspond to the invalid raster parameter name.
Definition at line 958 of file qgsprocessingalgorithm.cpp.
|
staticprotected |
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 the name should correspond to the invalid sink parameter name.
Definition at line 980 of file qgsprocessingalgorithm.cpp.
|
staticprotected |
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 the name should correspond to the invalid source parameter name.
Definition at line 926 of file qgsprocessingalgorithm.cpp.
|
pure virtual |
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.
|
delete |
Algorithms cannot be copied- create() should be used instead.
const QgsProcessingOutputDefinition * QgsProcessingAlgorithm::outputDefinition | ( | const QString & | name | ) | const |
Returns a matching output by name.
Matching is done in a case-insensitive manner.
Definition at line 508 of file qgsprocessingalgorithm.cpp.
|
inline |
Returns an ordered list of output definitions utilized by the algorithm.
Definition at line 293 of file qgsprocessingalgorithm.h.
|
protected |
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.
Definition at line 921 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to a static boolean value.
Definition at line 743 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to a static boolean value.
Definition at line 748 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to a color, or returns an invalid color if the parameter was not set.
Definition at line 891 of file qgsprocessingalgorithm.cpp.
|
protected |
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.
Definition at line 766 of file qgsprocessingalgorithm.cpp.
|
protected |
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. Unlike parameterAsCompatibleSourceLayerPath(), it will not force a conversion in this case and will return the target layer name in the layerName argument.
parameters | input parameter value map |
name | name of target parameter |
context | processing context |
compatibleFormats | a list of lowercase file extensions compatible with the algorithm |
preferredFormat | preferred format extension to use if conversion if required |
feedback | feedback object |
layerName | will be set to the target layer name for multi-layer sources (e.g. Geopackage) |
Definition at line 771 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to a connection name string.
Definition at line 896 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to a coordinate reference system.
Definition at line 806 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to a database table name string.
Definition at line 911 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to a DateTime, or returns an invalid date time if the parameter was not set.
Definition at line 901 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to a static double value.
Definition at line 708 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to a enum value.
Definition at line 723 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to list of enum values.
Definition at line 728 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to a static enum string.
Definition at line 733 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to list of static enum strings.
Definition at line 738 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to an expression.
Definition at line 703 of file qgsprocessingalgorithm.cpp.
|
protected |
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 specified crs. In this case the extent of the reproject rectangle will be returned.
Definition at line 816 of file qgsprocessingalgorithm.cpp.
|
protected |
Returns the coordinate reference system associated with an extent parameter value.
Definition at line 811 of file qgsprocessingalgorithm.cpp.
|
protected |
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 specified crs. Unlike parameterAsExtent(), 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, while parameterAsExtent() returns just the extent of the reprojected rectangle).
Definition at line 821 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to a list of fields.
Definition at line 871 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to a file/folder name.
Definition at line 846 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to a list of files (for QgsProcessingParameterMultipleLayers in QgsProcessing:TypeFile mode).
Definition at line 861 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to a file based output destination.
Definition at line 796 of file qgsprocessingalgorithm.cpp.
|
protected |
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 specified crs.
Definition at line 836 of file qgsprocessingalgorithm.cpp.
|
protected |
Returns the coordinate reference system associated with a geometry parameter value.
Definition at line 841 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to a static integer value.
Definition at line 713 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to a list of integer values.
Definition at line 718 of file qgsprocessingalgorithm.cpp.
|
protected |
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 the context. In either case, callers do not need to handle deletion of the returned layer.
Definition at line 776 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to a list of map layers.
The flags are used to set options for loading layers (e.g. skip index generation).
Definition at line 856 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to a print layout.
Definition at line 881 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to a print layout item, taken from the specified layout.
Definition at line 886 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to a matrix/table of values.
Tables are collapsed to a 1 dimensional list.
Definition at line 851 of file qgsprocessingalgorithm.cpp.
|
protected |
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 the context. In either case, callers do not need to handle deletion of the returned layer.
Definition at line 786 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to a output layer destination.
Definition at line 791 of file qgsprocessingalgorithm.cpp.
|
protected |
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 specified crs.
Definition at line 826 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to a point cloud layer.
The flags 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 the context. In either case, callers do not need to handle deletion of the returned layer.
Definition at line 916 of file qgsprocessingalgorithm.cpp.
|
protected |
Returns the coordinate reference system associated with an point parameter value.
Definition at line 831 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to a range of values.
Definition at line 866 of file qgsprocessingalgorithm.cpp.
|
protected |
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 the context. In either case, callers do not need to handle deletion of the returned layer.
Definition at line 781 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to a database schema name string.
Definition at line 906 of file qgsprocessingalgorithm.cpp.
|
protected |
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 the context.
The fields, geometryType and crs 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 calling QgsProcessingUtils::mapLayerFromString().
The createOptions argument is used to pass on creation options such as layer name.
The datasourceOptions and layerOptions 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.
QgsProcessingException |
Definition at line 753 of file qgsprocessingalgorithm.cpp.
|
protected |
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 the context.
This function creates a new object and the caller takes responsibility for deleting the returned object.
Definition at line 761 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to a static string value.
Definition at line 698 of file qgsprocessingalgorithm.cpp.
|
protected |
Evaluates the parameter with matching name to a list of strings (e.g.
field names or point cloud attributes).
Definition at line 876 of file qgsprocessingalgorithm.cpp.
|
protected |
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 the context. In either case, callers do not need to handle deletion of the returned layer.
Definition at line 801 of file qgsprocessingalgorithm.cpp.
const QgsProcessingParameterDefinition * QgsProcessingAlgorithm::parameterDefinition | ( | const QString & | name | ) | const |
Returns a matching parameter by name.
Matching is done in a case-insensitive manner, but exact case matches will be preferred.
Definition at line 468 of file qgsprocessingalgorithm.cpp.
|
inline |
Returns an ordered list of parameter definitions utilized by the algorithm.
Definition at line 266 of file qgsprocessingalgorithm.h.
QVariantMap QgsProcessingAlgorithm::postProcess | ( | QgsProcessingContext & | context, |
QgsProcessingFeedback * | feedback, | ||
bool | runResult = true |
||
) |
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.
Since QGIS 3.38, postProcess() will always be called even for unsuccessful run executions, to allow the algorithm to gracefully clean up. The runResult argument is used to indicate whether the run was successful. The algorithm's postProcessAlgorithm() method will only be called when runResult is true
.
Definition at line 661 of file qgsprocessingalgorithm.cpp.
|
protectedvirtual |
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 check feedback 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 (returned false
), or if an exception was raised by the processAlgorithm() step.
Definition at line 463 of file qgsprocessingalgorithm.cpp.
bool QgsProcessingAlgorithm::prepare | ( | const QVariantMap & | parameters, |
QgsProcessingContext & | context, | ||
QgsProcessingFeedback * | feedback | ||
) |
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).
Definition at line 572 of file qgsprocessingalgorithm.cpp.
|
protectedvirtual |
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 to processAlgorithm().
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 check feedback to determine whether the algorithm should be canceled and exited early.
If the preparation was successful algorithms must return true
. If a false
value is returned this indicates that the preparation could not be completed, and the algorithm execution will be canceled.
true
if preparation was successful. Reimplemented in QgsBatchGeocodeAlgorithm.
Definition at line 458 of file qgsprocessingalgorithm.cpp.
|
virtual |
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.
Definition at line 132 of file qgsprocessingalgorithm.cpp.
|
protectedpure virtual |
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 the prepareAlgorithm() and postProcessAlgorithm() 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 the processAlgorithm() step.
Algorithm progress should be reported using the supplied feedback object. Additionally, well-behaved algorithms should periodically check feedback to determine whether the algorithm should be canceled and exited early.
This method will not be called if the prepareAlgorithm() step failed (returned false
).
Implementations of processAlgorithm can throw the QgsProcessingException exception to indicate that a fatal error occurred within the execution.
Implemented in QgsProcessingFeatureBasedAlgorithm.
QgsProcessingProvider * QgsProcessingAlgorithm::provider | ( | ) | const |
Returns the provider to which this algorithm belongs.
Definition at line 137 of file qgsprocessingalgorithm.cpp.
|
protected |
Removes the parameter with matching name from the algorithm, and deletes any existing definition.
Definition at line 423 of file qgsprocessingalgorithm.cpp.
QVariantMap QgsProcessingAlgorithm::run | ( | const QVariantMap & | parameters, |
QgsProcessingContext & | context, | ||
QgsProcessingFeedback * | feedback, | ||
bool * | ok = nullptr , |
||
const QVariantMap & | configuration = QVariantMap() , |
||
bool | catchExceptions = true |
||
) | const |
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 from QgsProcessingRegistry and QgsProcessingProvider.
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 to true
if algorithm was successfully run.
If catchExceptions is set to false
, then QgsProcessingException raised during the algorithm run will not be automatically caught and will be raised instead.
Definition at line 533 of file qgsprocessingalgorithm.cpp.
QVariantMap QgsProcessingAlgorithm::runPrepared | ( | const QVariantMap & | parameters, |
QgsProcessingContext & | context, | ||
QgsProcessingFeedback * | feedback | ||
) |
Runs the algorithm, which has been prepared by an earlier call to prepare().
This method is safe to call from any thread. Returns true
if the algorithm was successfully executed. After runPrepared() has finished, the postProcess() method should be called from the main thread to allow the algorithm to perform any required cleanup tasks and return its final result.
Definition at line 590 of file qgsprocessingalgorithm.cpp.
void QgsProcessingAlgorithm::setProvider | ( | QgsProcessingProvider * | provider | ) |
Associates this algorithm with its provider.
No transfer of ownership is involved.
Definition at line 142 of file qgsprocessingalgorithm.cpp.
|
virtual |
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."
Definition at line 60 of file qgsprocessingalgorithm.cpp.
|
virtual |
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.
Definition at line 65 of file qgsprocessingalgorithm.cpp.
|
virtual |
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 provided context 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 either sourceParameters is empty or parameters is empty, and use whatever information is passed in order to make a best guess determination of the output properties.
Reimplemented in QgsProcessingFeatureBasedAlgorithm.
Definition at line 528 of file qgsprocessingalgorithm.cpp.
|
virtual |
Checks whether this algorithm supports in-place editing on the given layer Default implementation returns false
.
true
if the algorithm supports in-place editing Reimplemented in QgsBatchGeocodeAlgorithm, and QgsProcessingFeatureBasedAlgorithm.
Definition at line 1039 of file qgsprocessingalgorithm.cpp.
|
virtual |
Returns a path to an SVG version of the algorithm's icon.
Definition at line 90 of file qgsprocessingalgorithm.cpp.
|
inlinevirtual |
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.
Reimplemented in QgsBatchGeocodeAlgorithm.
Definition at line 158 of file qgsprocessingalgorithm.h.
|
virtual |
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 Returns true
if parameters have passed the CRS check.
Definition at line 189 of file qgsprocessingalgorithm.cpp.
|
staticprotected |
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 the name should correspond to the sink parameter name.
Definition at line 1029 of file qgsprocessingalgorithm.cpp.
|
friend |
Definition at line 1120 of file qgsprocessingalgorithm.h.
|
friend |
Definition at line 1118 of file qgsprocessingalgorithm.h.
|
friend |
Definition at line 1116 of file qgsprocessingalgorithm.h.
|
friend |
Definition at line 1119 of file qgsprocessingalgorithm.h.
|
friend |
Definition at line 1117 of file qgsprocessingalgorithm.h.