33#include <QRegularExpression>
34#include <QRegularExpressionMatch>
38 qDeleteAll( mParameters );
39 qDeleteAll( mOutputs );
44 std::unique_ptr< QgsProcessingAlgorithm > creation(
createInstance() );
48 creation->initAlgorithm( configuration );
49 return creation.release();
55 return QStringLiteral(
"%1:%2" ).arg( mProvider->
id(),
name() );
104 if ( !def->checkValueIsAcceptable( parameters.value( def->name() ), &context ) )
119 *message = QObject::tr(
"Incorrect parameter value for %1" ).arg( def->name() );
146 if ( definition->isDestination() )
173 else if (
c.scopeCount() == 0 )
192 bool foundCrs =
false;
205 else if ( !foundCrs && layer->
crs().
isValid() )
217 if ( foundCrs && source->sourceCrs().isValid() &&
crs != source->sourceCrs() )
221 else if ( !foundCrs && source->sourceCrs().isValid() )
224 crs = source->sourceCrs();
231 const auto constLayers = layers;
237 if ( foundCrs && layer->crs().isValid() &&
crs != layer->crs() )
241 else if ( !foundCrs && layer->crs().isValid() )
251 if ( foundCrs && extentCrs.
isValid() &&
crs != extentCrs )
255 else if ( !foundCrs && extentCrs.
isValid() )
264 if ( foundCrs && pointCrs.
isValid() &&
crs != pointCrs )
268 else if ( !foundCrs && pointCrs.
isValid() )
277 if ( foundCrs && geomCrs.
isValid() &&
crs != geomCrs )
281 else if ( !foundCrs && geomCrs.
isValid() )
294 QString s = QStringLiteral(
"processing.run(\"%1\"," ).arg(
id() );
302 if ( !parameters.contains( def->name() ) )
305 parts << QStringLiteral(
"'%1':%2" ).arg( def->name(), def->valueAsPythonString( parameters.value( def->name() ), context ) );
308 s += QStringLiteral(
" {%1})" ).arg( parts.join(
',' ) );
316 parts.append( QStringLiteral(
"qgis_process" ) );
317 parts.append( QStringLiteral(
"run" ) );
318 parts.append(
id() );
320 QgsProcessingContext::ProcessArgumentFlags argumentFlags;
327 auto escapeIfNeeded = [](
const QString & input ) -> QString
330 const thread_local QRegularExpression nonAlphaNumericRx( QStringLiteral(
"[^a-zA-Z0-9.\\-/_]" ) );
331 if ( nonAlphaNumericRx.match( input ).hasMatch() )
333 QString escaped = input;
334 escaped.replace(
'\'', QLatin1String(
"'\\''" ) );
335 return QStringLiteral(
"'%1'" ).arg( escaped );
348 if ( !parameters.contains( def->name() ) )
351 const QStringList partValues = def->valueAsStringList( parameters.value( def->name() ), context, ok );
355 for (
const QString &partValue : partValues )
357 parts << QStringLiteral(
"--%1=%2" ).arg( def->name(), escapeIfNeeded( partValue ) );
361 return parts.join(
' ' );
370 properties.remove( QStringLiteral(
"project_path" ) );
372 QVariantMap paramValues;
378 if ( !parameters.contains( def->name() ) )
381 paramValues.insert( def->name(), def->valueAsJsonObject( parameters.value( def->name() ), context ) );
384 properties.insert( QStringLiteral(
"inputs" ), paramValues );
395 if ( existingDef && existingDef->
name() == definition->
name() )
397 QgsMessageLog::logMessage( QObject::tr(
"Duplicate parameter %1 registered for alg %2" ).arg( definition->
name(),
id() ), QObject::tr(
"Processing" ) );
409 mParameters << definition;
413 return createAutoOutputForParameter( definition );
424 mParameters.removeAll( def );
431 mOutputs.removeAll( outputDef );
444 QgsMessageLog::logMessage( QObject::tr(
"Duplicate output %1 registered for alg %2" ).arg( definition->
name(),
id() ), QObject::tr(
"Processing" ) );
449 mOutputs << definition;
460 return QVariantMap();
468 if ( def->name() ==
name )
475 if ( def->name().compare(
name, Qt::CaseInsensitive ) == 0 )
497 if ( def->isDestination() )
507 if ( def->name().compare(
name, Qt::CaseInsensitive ) == 0 )
517 if ( def->type() == QLatin1String(
"outputHtml" ) )
530 std::unique_ptr< QgsProcessingAlgorithm > alg(
create( configuration ) );
534 bool res = alg->prepare( parameters, context, feedback );
536 return QVariantMap();
541 runRes = alg->runPrepared( parameters, context, feedback );
545 if ( !catchExceptions )
550 return QVariantMap();
556 QVariantMap ppRes = alg->postProcess( context, feedback );
557 if ( !ppRes.isEmpty() )
566 Q_ASSERT_X( QThread::currentThread() == context.
temporaryLayerStore()->thread(),
"QgsProcessingAlgorithm::prepare",
"prepare() must be called from the same thread as context was created in" );
567 Q_ASSERT_X( !mHasPrepared,
"QgsProcessingAlgorithm::prepare",
"prepare() has already been called for the algorithm instance" );
583 Q_ASSERT_X( mHasPrepared,
"QgsProcessingAlgorithm::runPrepared", QStringLiteral(
"prepare() was not called for the algorithm instance %1" ).arg(
name() ).toLatin1() );
584 Q_ASSERT_X( !mHasExecuted,
"QgsProcessingAlgorithm::runPrepared",
"runPrepared() was already called for this algorithm instance" );
590 if ( context.
thread() == QThread::currentThread() )
595 runContext = &context;
606 mLocalContext->copyThreadSafeSettings( context );
608 runContext = mLocalContext.get();
613 QVariantMap runResults =
processAlgorithm( parameters, *runContext, feedback );
621 mLocalContext->pushToThread( context.
thread() );
630 mLocalContext->pushToThread( context.
thread() );
640 Q_ASSERT_X( QThread::currentThread() == context.
temporaryLayerStore()->thread(),
"QgsProcessingAlgorithm::postProcess",
"postProcess() must be called from the same thread the context was created in" );
641 Q_ASSERT_X( mHasExecuted,
"QgsProcessingAlgorithm::postProcess", QStringLiteral(
"algorithm instance %1 was not executed" ).arg(
name() ).toLatin1() );
642 Q_ASSERT_X( !mHasPostProcessed,
"QgsProcessingAlgorithm::postProcess",
"postProcess() was already called for this algorithm instance" );
651 mLocalContext.reset();
654 mHasPostProcessed =
true;
663 return QVariantMap();
722QgsFeatureSink *
QgsProcessingAlgorithm::parameterAsSink(
const QVariantMap ¶meters,
const QString &name,
QgsProcessingContext &context, QString &destinationIdentifier,
const QgsFields &fields,
Qgis::WkbType geometryType,
const QgsCoordinateReferenceSystem &
crs, QgsFeatureSink::SinkFlags sinkFlags,
const QVariantMap &createOptions,
const QStringList &datasourceOptions,
const QStringList &layerOptions )
const
727 return QgsProcessingParameters::parameterAsSink(
parameterDefinition(
name ), parameters, fields, geometryType,
crs, context, destinationIdentifier, sinkFlags, createOptions, datasourceOptions, layerOptions );
897 if ( !parameters.contains(
name ) )
898 return QObject::tr(
"Could not load source layer for %1: no value specified for parameter" ).arg(
name );
901 QVariant var = parameters.value(
name );
902 if ( var.userType() == QMetaType::type(
"QgsProcessingFeatureSourceDefinition" ) )
907 else if ( var.userType() == QMetaType::type(
"QgsProcessingOutputLayerDefinition" ) )
912 if ( var.userType() == QMetaType::type(
"QgsProperty" ) )
920 if ( !var.toString().isEmpty() )
921 return QObject::tr(
"Could not load source layer for %1: %2 not found" ).arg(
name, var.toString() );
923 return QObject::tr(
"Could not load source layer for %1: invalid value" ).arg(
name );
929 if ( !parameters.contains(
name ) )
930 return QObject::tr(
"Could not load source layer for %1: no value specified for parameter" ).arg(
name );
933 QVariant var = parameters.value(
name );
934 if ( var.userType() == QMetaType::type(
"QgsProperty" ) )
942 if ( !var.toString().isEmpty() )
943 return QObject::tr(
"Could not load source layer for %1: %2 not found" ).arg(
name, var.toString() );
945 return QObject::tr(
"Could not load source layer for %1: invalid value" ).arg(
name );
951 if ( !parameters.contains(
name ) )
952 return QObject::tr(
"Could not create destination layer for %1: no value specified for parameter" ).arg(
name );
955 QVariant var = parameters.value(
name );
956 if ( var.userType() == QMetaType::type(
"QgsProcessingOutputLayerDefinition" ) )
961 if ( var.userType() == QMetaType::type(
"QgsProperty" ) )
969 if ( !var.toString().isEmpty() )
970 return QObject::tr(
"Could not create destination layer for %1: %2" ).arg(
name, var.toString() );
972 return QObject::tr(
"Could not create destination layer for %1: invalid value" ).arg(
name );
978 if ( !parameters.contains(
name ) )
979 return QObject::tr(
"Could not load source layer for %1: no value specified for parameter" ).arg(
name );
982 QVariant var = parameters.value(
name );
983 if ( var.userType() == QMetaType::type(
"QgsProperty" ) )
991 if ( !var.toString().isEmpty() )
992 return QObject::tr(
"Could not load source layer for %1: %2 not found" ).arg(
name, var.toString() );
994 return QObject::tr(
"Could not load source layer for %1: invalid value" ).arg(
name );
1001 Q_UNUSED( parameters );
1002 if ( !
name.isEmpty() )
1003 return QObject::tr(
"Could not write feature into %1" ).arg(
name );
1005 return QObject::tr(
"Could not write feature" );
1024 output->setAutoCreated(
true );
1058 return QStringLiteral(
"INPUT" );
1063 return QObject::tr(
"Input layer" );
1068 return QList<int>();
1078 return Qgis::ProcessingFeatureSourceFlags();
1083 return QgsFeatureSink::SinkFlags();
1088 return inputWkbType;
1108 return mSource->sourceCrs();
1117 std::unique_ptr< QgsFeatureSink > sink(
parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest,
1132 long count = mSource->featureCount();
1137 double step = count > 0 ? 100.0 / count : 1;
1148 for (
QgsFeature transformedFeature : transformed )
1160 QVariantMap outputs;
1161 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
1172 const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
1213 if ( sink == QLatin1String(
"OUTPUT" ) )
1217 const VectorProperties inputProps = sourceProperties.value( QStringLiteral(
"INPUT" ) );
1226 std::unique_ptr< QgsProcessingFeatureSource > source(
parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
ProcessingSourceType
Processing data source types.
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
@ VectorAnyGeometry
Any vector layer with geometry.
@ VectorPoint
Vector point layers.
@ VectorPolygon
Vector polygon layers.
@ VectorLine
Vector line layers.
@ Critical
Critical/error message.
@ Available
Properties are available.
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
WkbType
The WKB type describes the number of dimensions a geometry has.
@ SupportsBatch
Algorithm supports batch mode.
@ SupportsInPlaceEdits
Algorithm supports in-place editing.
@ RequiresMatchingCrs
Algorithm requires that all input layers have matching coordinate reference systems.
@ CanCancel
Algorithm can be canceled.
@ RequiresProject
The algorithm requires that a valid QgsProject is available from the processing context in order to e...
@ Hidden
Parameter is hidden and should not be shown to users.
Represents a map layer containing a set of georeferenced annotations, e.g.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
This class represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
Single scope for storing variables and functions for use within a QgsExpressionContext.
static QgsExpressionContextScope * processingAlgorithmScope(const QgsProcessingAlgorithm *algorithm, const QVariantMap ¶meters, QgsProcessingContext &context)
Creates a new scope which contains variables and functions relating to a processing algorithm,...
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QList< QgsExpressionContextScope * > takeScopes()
Returns all scopes from this context and remove them, leaving this context without any context.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
This class wraps a request for features to a vector layer (or directly its vector data provider).
An interface for objects which accept features via addFeature(s) methods.
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool isCanceled() const
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
Base class for graphical items within a QgsLayout.
Base class for all map layer types.
QgsCoordinateReferenceSystem crs
Represents a mesh layer supporting display of data on structured or unstructured meshes.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Represents a map layer supporting display of point clouds.
A class to represent a 2D point.
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Abstract base class for processing algorithms.
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 parameterAsConnectionName(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a connection name string.
const QgsProcessingOutputDefinition * outputDefinition(const QString &name) const
Returns a matching output by name.
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 compa...
QStringList parameterAsStrings(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a list of strings (e.g.
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 t...
virtual QgsProcessingAlgorithm * createInstance() const =0
Creates a new instance of the algorithm class.
QgsMapLayer * parameterAsLayer(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a map layer.
QgsRasterLayer * parameterAsRasterLayer(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a raster layer.
virtual bool prepareAlgorithm(const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Prepares the algorithm to run using the specified parameters.
int parameterAsInt(const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static integer value.
virtual QString helpUrl() const
Returns a url pointing to the algorithm's help page.
int parameterAsEnum(const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a enum value.
void setProvider(QgsProcessingProvider *provider)
Associates this algorithm with its provider.
virtual QIcon icon() const
Returns an icon for the algorithm.
virtual QString shortHelpString() const
Returns a localised short helper string for the algorithm.
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...
virtual Qgis::ProcessingAlgorithmFlags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
virtual QString shortDescription() const
Returns an optional translated short description of the algorithm.
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.
QgsProcessingFeatureSource * parameterAsSource(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a feature source.
virtual ~QgsProcessingAlgorithm()
int countVisibleParameters() const
Returns the number of visible (non-hidden) parameters defined by this algorithm.
QString parameterAsFile(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a file/folder name.
QString id() const
Returns the unique ID for the algorithm, which is a combination of the algorithm provider's ID and th...
virtual QVariantMap preprocessParameters(const QVariantMap ¶meters)
Pre-processes a set of parameters, allowing the algorithm to clean their values.
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.
QgsVectorLayer * parameterAsVectorLayer(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a vector layer.
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.
QStringList parameterAsFileList(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a list of files (for QgsProcessingParameterMultipleLaye...
bool prepare(const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Prepares the algorithm for execution.
QString parameterAsDatabaseTableName(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a database table name string.
QString parameterAsExpression(const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to an expression.
void removeParameter(const QString &name)
Removes the parameter with matching name from the algorithm, and deletes any existing definition.
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.
QgsAnnotationLayer * parameterAsAnnotationLayer(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to an annotation layer.
bool addParameter(QgsProcessingParameterDefinition *parameterDefinition, bool createOutput=true)
Adds a parameter definition to the algorithm.
QgsGeometry parameterAsGeometry(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem()) const
Evaluates the parameter with matching name to a geometry.
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 comm...
bool parameterAsBoolean(const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static boolean value.
QList< double > parameterAsRange(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a range of values.
QVariantList parameterAsMatrix(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a matrix/table of values.
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.
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.
bool hasHtmlOutputs() const
Returns true if this algorithm generates HTML outputs.
bool addOutput(QgsProcessingOutputDefinition *outputDefinition)
Adds an output definition to the algorithm.
double parameterAsDouble(const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static double value.
QgsCoordinateReferenceSystem parameterAsPointCrs(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Returns the coordinate reference system associated with an point parameter value.
QVariantMap postProcess(QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Should be called in the main thread following the completion of runPrepared().
QString parameterAsString(const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static string value.
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.
QgsPrintLayout * parameterAsLayout(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context)
Evaluates the parameter with matching name to a print layout.
virtual QVariantMap processAlgorithm(const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback)=0
Runs the algorithm using the specified parameters.
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 parameterAsCrs(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a coordinate reference system.
QString parameterAsFileOutput(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a file based output destination.
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.
const QgsProcessingParameterDefinition * parameterDefinition(const QString &name) const
Returns a matching parameter by name.
virtual QString svgIconPath() const
Returns a path to an SVG version of the algorithm's icon.
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.
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.
QString parameterAsSchema(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a database schema name string.
virtual Q_DECL_DEPRECATED QString helpString() const
Returns a localised help string for the algorithm.
QStringList parameterAsEnumStrings(const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to list of static enum strings.
QgsPointXY parameterAsPoint(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem()) const
Evaluates the parameter with matching name to a point.
virtual QWidget * createCustomParametersWidget(QWidget *parent=nullptr) const
If an algorithm subclass implements a custom parameters widget, a copy of this widget should be const...
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.
QgsCoordinateReferenceSystem parameterAsExtentCrs(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Returns the coordinate reference system associated with an extent parameter value.
QgsMeshLayer * parameterAsMeshLayer(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a mesh layer.
QgsCoordinateReferenceSystem parameterAsGeometryCrs(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Returns the coordinate reference system associated with a geometry parameter value.
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 parame...
QString parameterAsEnumString(const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static enum string.
virtual QVariantMap postProcessAlgorithm(QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Allows the algorithm to perform any required cleanup tasks.
virtual bool canExecute(QString *errorMessage=nullptr) const
Returns true if the algorithm can execute.
QgsProcessingProvider * provider() const
Returns the provider to which this algorithm belongs.
QgsProcessingAlgorithm * create(const QVariantMap &configuration=QVariantMap()) const
Creates a copy of the algorithm, ready for execution.
virtual QVariantMap asMap(const QVariantMap ¶meters, QgsProcessingContext &context) const
Returns a JSON serializable variant map containing the specified parameters and context settings.
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.
virtual bool supportInPlaceEdit(const QgsMapLayer *layer) const
Checks whether this algorithm supports in-place editing on the given layer Default implementation ret...
bool parameterAsBool(const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static boolean value.
virtual QString name() const =0
Returns the algorithm name, used for identifying the algorithm.
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.
QList< int > parameterAsEnums(const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to list of enum values.
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 i...
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.
QVariantMap runPrepared(const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Runs the algorithm, which has been prepared by an earlier call to prepare().
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 para...
QString parameterAsOutputLayer(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a output layer destination.
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 w...
Contains information about the context in which a processing algorithm is executed.
QThread * thread()
Returns the thread in which the context lives.
@ IncludeProjectPath
Include the associated project path argument.
QgsExpressionContext & expressionContext()
Returns the expression context.
void takeResultsFrom(QgsProcessingContext &context)
Takes the results from another context and merges them with the results currently stored in this cont...
QVariantMap exportToMap() const
Exports the context's settings to a variant map.
QStringList asQgisProcessArguments(QgsProcessingContext::ProcessArgumentFlags flags=QgsProcessingContext::ProcessArgumentFlags()) const
Returns list of the equivalent qgis_process arguments representing the settings from the context.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
QgsMapLayerStore * temporaryLayerStore()
Returns a reference to the layer store used for storing temporary layers during algorithm execution.
Base class for all parameter definitions which represent file or layer destinations,...
virtual QgsProcessingOutputDefinition * toOutputDefinition() const =0
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
void setSupportsNonFileBasedOutput(bool supportsNonFileBasedOutput)
Sets whether the destination parameter supports non filed-based outputs, such as memory layers or dir...
Custom exception class for processing related exceptions.
virtual QgsFeatureRequest request() const
Returns the feature request used for fetching features to process from the source layer.
virtual QgsFeatureList processFeature(const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback)=0
Processes an individual input feature from the source.
bool supportInPlaceEdit(const QgsMapLayer *layer) const override
Checks whether this algorithm supports in-place editing on the given layer Default implementation for...
virtual QString inputParameterName() const
Returns the name of the parameter corresponding to the input layer.
QgsProcessingAlgorithm::VectorProperties sinkProperties(const QString &sink, const QVariantMap ¶meters, QgsProcessingContext &context, const QMap< QString, QgsProcessingAlgorithm::VectorProperties > &sourceProperties) const override
Returns the vector properties which will be used for the sink with matching name.
virtual void initParameters(const QVariantMap &configuration=QVariantMap())
Initializes any extra parameters added by the algorithm subclass.
Qgis::ProcessingAlgorithmFlags flags() const override
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
virtual Qgis::WkbType outputWkbType(Qgis::WkbType inputWkbType) const
Maps the input WKB geometry type (inputWkbType) to the corresponding output WKB type generated by the...
virtual Qgis::ProcessingSourceType outputLayerType() const
Returns the layer type for layers generated by this algorithm, if this is possible to determine in ad...
virtual QgsCoordinateReferenceSystem outputCrs(const QgsCoordinateReferenceSystem &inputCrs) const
Maps the input source coordinate reference system (inputCrs) to a corresponding output CRS generated ...
void prepareSource(const QVariantMap ¶meters, QgsProcessingContext &context)
Read the source from parameters and context and set it.
QVariantMap processAlgorithm(const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback) override
Runs the algorithm using the specified parameters.
virtual QgsFields outputFields(const QgsFields &inputFields) const
Maps the input source fields (inputFields) to corresponding output fields generated by the algorithm.
virtual QString outputName() const =0
Returns the translated, user visible name for any layers created by this algorithm.
virtual QString inputParameterDescription() const
Returns the translated description of the parameter corresponding to the input layer.
virtual QgsFeatureSink::SinkFlags sinkFlags() const
Returns the feature sink flags to be used for the output.
void initAlgorithm(const QVariantMap &configuration=QVariantMap()) override
Initializes the algorithm using the specified configuration.
virtual QList< int > inputLayerTypes() const
Returns the valid input layer types for the source layer for this algorithm.
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source's coordinate reference system.
virtual Qgis::ProcessingFeatureSourceFlags sourceFlags() const
Returns the processing feature source flags to be used in the algorithm.
Encapsulates settings relating to a feature source input to a processing algorithm.
QgsProperty source
Source definition.
QgsFeatureSource subclass which proxies methods to an underlying QgsFeatureSource,...
QgsExpressionContextScope * createExpressionContextScope() const
Returns an expression context scope suitable for this source.
Base class for providing feedback from a processing algorithm.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
Base class for the definition of processing outputs.
QString name() const
Returns the name of the output.
bool autoCreated() const
Returns true if the output was automatically created when adding a parameter.
Encapsulates settings relating to a feature sink or output raster layer for a processing algorithm.
QgsProperty sink
Sink/layer definition.
Base class for the definition of processing parameters.
QgsProcessingAlgorithm * mAlgorithm
Pointer to algorithm which owns this parameter.
virtual bool isDestination() const
Returns true if this parameter represents a file or layer destination, e.g.
QString name() const
Returns the name of the parameter.
static QString typeName()
Returns the type name for the parameter class.
A feature sink output for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
An input feature source (such as vector layers) parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static int parameterAsEnum(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a enum value.
static double parameterAsDouble(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static double value.
static QgsPointXY parameterAsPoint(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a point.
static QString parameterAsOutputLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a output layer destination.
static QgsFeatureSink * parameterAsSink(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsFields &fields, Qgis::WkbType geometryType, const QgsCoordinateReferenceSystem &crs, QgsProcessingContext &context, QString &destinationIdentifier, QgsFeatureSink::SinkFlags sinkFlags=QgsFeatureSink::SinkFlags(), const QVariantMap &createOptions=QVariantMap(), const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList())
Evaluates the parameter with matching definition to a feature sink.
static QgsPrintLayout * parameterAsLayout(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a print layout.
static QList< QgsMapLayer * > parameterAsLayerList(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a list of map layers.
static QgsRectangle parameterAsExtent(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a rectangular extent.
static QgsCoordinateReferenceSystem parameterAsGeometryCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Returns the coordinate reference system associated with a geometry parameter value.
static QgsAnnotationLayer * parameterAsAnnotationLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to an annotation layer.
static QString parameterAsEnumString(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static enum string.
static QList< double > parameterAsRange(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a range of values.
static QStringList parameterAsStrings(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of strings (e.g.
static QList< int > parameterAsInts(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of integer values.
static QString parameterAsConnectionName(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a connection name string.
static QgsProcessingFeatureSource * parameterAsSource(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a feature source.
static QString parameterAsFileOutput(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a file based output destination.
static QgsPointCloudLayer * parameterAsPointCloudLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a point cloud layer.
static QgsCoordinateReferenceSystem parameterAsPointCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an point parameter value.
static QgsLayoutItem * parameterAsLayoutItem(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, QgsPrintLayout *layout)
Evaluates the parameter with matching definition to a print layout item, taken from the specified lay...
static bool parameterAsBool(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static boolean value.
static QString parameterAsCompatibleSourceLayerPathAndLayerName(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr, QString *layerName=nullptr)
Evaluates the parameter with matching definition to a source vector layer file path and layer name of...
static QgsMeshLayer * parameterAsMeshLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition and value to a mesh layer.
static QString parameterAsCompatibleSourceLayerPath(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr)
Evaluates the parameter with matching definition to a source vector layer file path of compatible for...
static QColor parameterAsColor(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Returns the color associated with an point parameter value, or an invalid color if the parameter was ...
static QgsVectorLayer * parameterAsVectorLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a vector layer.
static int parameterAsInt(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static integer value.
static QString parameterAsDatabaseTableName(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database table name.
static QString parameterAsSchema(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database schema name.
static QgsGeometry parameterAsGeometry(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a geometry.
static QgsMapLayer * parameterAsLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint=QgsProcessingUtils::LayerHint::UnknownType, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a map layer.
static QString parameterAsExpression(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to an expression.
static QString parameterAsString(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static string value.
static QgsRasterLayer * parameterAsRasterLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a raster layer.
static QList< int > parameterAsEnums(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of enum values.
static QStringList parameterAsEnumStrings(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of static enum strings.
static QgsGeometry parameterAsExtentGeometry(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a rectangular extent, and returns a geometry cove...
static QStringList parameterAsFileList(const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of files (for QgsProcessingParameterMultip...
static QgsCoordinateReferenceSystem parameterAsExtentCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an extent parameter value.
static QDateTime parameterAsDateTime(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static datetime value.
static QString parameterAsFile(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a file/folder name.
static QVariantList parameterAsMatrix(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a matrix/table of values.
static QgsCoordinateReferenceSystem parameterAsCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a coordinate reference system.
Abstract base class for processing providers.
virtual QString id() const =0
Returns the unique provider id, used for identifying the provider.
virtual bool supportsNonFileBasedOutput() const
Returns true if the provider supports non-file based outputs (such as memory layers or direct databas...
A store for object properties.
Qgis::PropertyType propertyType() const
Returns the property type.
QVariant value(const QgsExpressionContext &context, const QVariant &defaultValue=QVariant(), bool *ok=nullptr) const
Calculates the current value of the property, including any transforms which are set for the property...
QVariant staticValue() const
Returns the current static value for the property.
Represents a raster layer.
A rectangle specified with double values.
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.
static Qgis::GeometryType geometryType(Qgis::WkbType type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
QList< QgsFeature > QgsFeatureList
QList< const QgsProcessingParameterDefinition * > QgsProcessingParameterDefinitions
List of processing parameters.
const QgsCoordinateReferenceSystem & outputCrs
const QgsCoordinateReferenceSystem & crs
Properties of a vector source or sink used in an algorithm.
Qgis::WkbType wkbType
Geometry (WKB) type.
QgsCoordinateReferenceSystem crs
Coordinate Reference System.
Qgis::ProcessingPropertyAvailability availability
Availability of the properties. By default properties are not available.