QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
36 qDeleteAll( mParameters );
37 qDeleteAll( mOutputs );
42 std::unique_ptr< QgsProcessingAlgorithm > creation(
createInstance() );
46 creation->initAlgorithm( configuration );
47 return creation.release();
53 return QStringLiteral(
"%1:%2" ).arg( mProvider->
id(),
name() );
102 if ( !def->checkValueIsAcceptable( parameters.value( def->name() ), &context ) )
115 *message = QObject::tr(
"Incorrect parameter value for %1" ).arg( def->name() );
142 if ( definition->isDestination() )
169 else if (
c.scopeCount() == 0 )
188 bool foundCrs =
false;
201 else if ( !foundCrs && layer->
crs().
isValid() )
213 if ( foundCrs && source->sourceCrs().isValid() &&
crs != source->sourceCrs() )
217 else if ( !foundCrs && source->sourceCrs().isValid() )
220 crs = source->sourceCrs();
227 const auto constLayers = layers;
233 if ( foundCrs && layer->crs().isValid() &&
crs != layer->crs() )
237 else if ( !foundCrs && layer->crs().isValid() )
247 if ( foundCrs && extentCrs.
isValid() &&
crs != extentCrs )
251 else if ( !foundCrs && extentCrs.
isValid() )
260 if ( foundCrs && pointCrs.
isValid() &&
crs != pointCrs )
264 else if ( !foundCrs && pointCrs.
isValid() )
273 if ( foundCrs && geomCrs.
isValid() &&
crs != geomCrs )
277 else if ( !foundCrs && geomCrs.
isValid() )
290 QString s = QStringLiteral(
"processing.run(\"%1\"," ).arg(
id() );
298 if ( !parameters.contains( def->name() ) )
301 parts << QStringLiteral(
"'%1':%2" ).arg( def->name(), def->valueAsPythonString( parameters.value( def->name() ), context ) );
304 s += QStringLiteral(
" {%1})" ).arg( parts.join(
',' ) );
315 if ( existingDef && existingDef->
name() == definition->
name() )
317 QgsMessageLog::logMessage( QObject::tr(
"Duplicate parameter %1 registered for alg %2" ).arg( definition->
name(),
id() ), QObject::tr(
"Processing" ) );
329 mParameters << definition;
333 return createAutoOutputForParameter( definition );
344 mParameters.removeAll( def );
351 mOutputs.removeAll( outputDef );
364 QgsMessageLog::logMessage( QObject::tr(
"Duplicate output %1 registered for alg %2" ).arg( definition->
name(),
id() ), QObject::tr(
"Processing" ) );
369 mOutputs << definition;
380 return QVariantMap();
388 if ( def->name() ==
name )
395 if ( def->name().compare(
name, Qt::CaseInsensitive ) == 0 )
417 if ( def->isDestination() )
427 if ( def->name().compare(
name, Qt::CaseInsensitive ) == 0 )
437 if ( def->type() == QLatin1String(
"outputHtml" ) )
450 std::unique_ptr< QgsProcessingAlgorithm > alg(
create( configuration ) );
454 bool res = alg->prepare( parameters, context, feedback );
456 return QVariantMap();
461 runRes = alg->runPrepared( parameters, context, feedback );
465 if ( !catchExceptions )
470 return QVariantMap();
476 QVariantMap ppRes = alg->postProcess( context, feedback );
477 if ( !ppRes.isEmpty() )
485 Q_ASSERT_X( QThread::currentThread() == context.
temporaryLayerStore()->thread(),
"QgsProcessingAlgorithm::prepare",
"prepare() must be called from the same thread as context was created in" );
486 Q_ASSERT_X( !mHasPrepared,
"QgsProcessingAlgorithm::prepare",
"prepare() has already been called for the algorithm instance" );
502 Q_ASSERT_X( mHasPrepared,
"QgsProcessingAlgorithm::runPrepared", QStringLiteral(
"prepare() was not called for the algorithm instance %1" ).arg(
name() ).toLatin1() );
503 Q_ASSERT_X( !mHasExecuted,
"QgsProcessingAlgorithm::runPrepared",
"runPrepared() was already called for this algorithm instance" );
509 if ( context.
thread() == QThread::currentThread() )
514 runContext = &context;
525 mLocalContext->copyThreadSafeSettings( context );
527 runContext = mLocalContext.get();
532 QVariantMap runResults =
processAlgorithm( parameters, *runContext, feedback );
540 mLocalContext->pushToThread( context.
thread() );
549 mLocalContext->pushToThread( context.
thread() );
558 Q_ASSERT_X( QThread::currentThread() == context.
temporaryLayerStore()->thread(),
"QgsProcessingAlgorithm::postProcess",
"postProcess() must be called from the same thread the context was created in" );
559 Q_ASSERT_X( mHasExecuted,
"QgsProcessingAlgorithm::postProcess", QStringLiteral(
"algorithm instance %1 was not executed" ).arg(
name() ).toLatin1() );
560 Q_ASSERT_X( !mHasPostProcessed,
"QgsProcessingAlgorithm::postProcess",
"postProcess() was already called for this algorithm instance" );
569 mLocalContext.reset();
572 mHasPostProcessed =
true;
581 return QVariantMap();
630 QgsFeatureSink *
QgsProcessingAlgorithm::parameterAsSink(
const QVariantMap ¶meters,
const QString &name,
QgsProcessingContext &context, QString &destinationIdentifier,
const QgsFields &fields,
QgsWkbTypes::Type geometryType,
const QgsCoordinateReferenceSystem &
crs, QgsFeatureSink::SinkFlags sinkFlags,
const QVariantMap &createOptions,
const QStringList &datasourceOptions,
const QStringList &layerOptions )
const
635 return QgsProcessingParameters::parameterAsSink(
parameterDefinition(
name ), parameters, fields, geometryType,
crs, context, destinationIdentifier, sinkFlags, createOptions, datasourceOptions, layerOptions );
790 if ( !parameters.contains(
name ) )
791 return QObject::tr(
"Could not load source layer for %1: no value specified for parameter" ).arg(
name );
794 QVariant var = parameters.value(
name );
813 if ( !var.toString().isEmpty() )
814 return QObject::tr(
"Could not load source layer for %1: %2 not found" ).arg(
name, var.toString() );
816 return QObject::tr(
"Could not load source layer for %1: invalid value" ).arg(
name );
822 if ( !parameters.contains(
name ) )
823 return QObject::tr(
"Could not load source layer for %1: no value specified for parameter" ).arg(
name );
826 QVariant var = parameters.value(
name );
835 if ( !var.toString().isEmpty() )
836 return QObject::tr(
"Could not load source layer for %1: %2 not found" ).arg(
name, var.toString() );
838 return QObject::tr(
"Could not load source layer for %1: invalid value" ).arg(
name );
844 if ( !parameters.contains(
name ) )
845 return QObject::tr(
"Could not create destination layer for %1: no value specified for parameter" ).arg(
name );
848 QVariant var = parameters.value(
name );
862 if ( !var.toString().isEmpty() )
863 return QObject::tr(
"Could not create destination layer for %1: %2" ).arg(
name, var.toString() );
865 return QObject::tr(
"Could not create destination layer for %1: invalid value" ).arg(
name );
885 output->setAutoCreated(
true );
919 return QStringLiteral(
"INPUT" );
924 return QObject::tr(
"Input layer" );
944 return QgsFeatureSink::SinkFlags();
969 return mSource->sourceCrs();
978 std::unique_ptr< QgsFeatureSink > sink(
parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest,
993 long count = mSource->featureCount();
998 double step = count > 0 ? 100.0 / count : 1;
1009 for (
QgsFeature transformedFeature : transformed )
1021 QVariantMap outputs;
1022 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
1033 const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
1074 if ( sink == QLatin1String(
"OUTPUT" ) )
1078 const VectorProperties inputProps = sourceProperties.value( QStringLiteral(
"INPUT" ) );
1087 std::unique_ptr< QgsProcessingFeatureSource > source(
parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsCoordinateReferenceSystem crs
virtual QString shortDescription() const
Returns an optional translated short description of the algorithm.
virtual QgsProcessingOutputDefinition * toOutputDefinition() const =0
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
void setProgress(double progress)
Sets the current progress for the feedback object.
static QVariantList parameterAsMatrix(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a matrix/table of values.
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
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...
bool prepare(const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Prepares the algorithm for execution.
void removeParameter(const QString &name)
Removes the parameter with matching name from the algorithm, and deletes any existing definition.
static QgsCoordinateReferenceSystem parameterAsCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a coordinate reference system.
QStringList parameterAsFileList(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a list of files (for QgsProcessingParameterMultipleLaye...
static QString parameterAsConnectionName(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a connection name string.
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.
QgsPrintLayout * parameterAsLayout(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context)
Evaluates the parameter with matching name to a print layout.
A store for object properties.
virtual bool canExecute(QString *errorMessage=nullptr) const
Returns true if the algorithm can execute.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
QgsCoordinateReferenceSystem parameterAsExtentCrs(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context)
Returns the coordinate reference system associated with an extent parameter value.
QgsProcessingAlgorithm * mAlgorithm
Pointer to algorithm which owns this parameter.
void prepareSource(const QVariantMap ¶meters, QgsProcessingContext &context)
Read the source from parameters and context and set it.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
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 QgsGeometry parameterAsGeometry(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a geometry.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
virtual QString id() const =0
Returns the unique provider id, used for identifying the provider.
QgsCoordinateReferenceSystem crs
Coordinate Reference System.
Base class for providing feedback from a processing algorithm.
virtual QgsWkbTypes::Type outputWkbType(QgsWkbTypes::Type inputWkbType) const
Maps the input WKB geometry type (inputWkbType) to the corresponding output WKB type generated by the...
static QString parameterAsDatabaseTableName(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database table name.
const QgsCoordinateReferenceSystem & crs
static QStringList parameterAsFields(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of fields.
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 void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
@ TypeVectorPolygon
Vector polygon layers.
QgsExpressionContextScope * createExpressionContextScope() const
Returns an expression context scope suitable for this source.
bool addParameter(QgsProcessingParameterDefinition *parameterDefinition, bool createOutput=true)
Adds a parameter definition to the algorithm.
QgsVectorLayer * parameterAsVectorLayer(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a vector layer.
Container of fields for a vector layer.
virtual QString inputParameterDescription() const
Returns the translated description of the parameter corresponding to the input layer.
static QgsMapLayer * parameterAsLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint=QgsProcessingUtils::LayerHint::UnknownType)
Evaluates the parameter with matching definition to a map layer.
Abstract base class for processing providers.
static QgsCoordinateReferenceSystem parameterAsExtentCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an extent parameter value.
virtual void initParameters(const QVariantMap &configuration=QVariantMap())
Initializes any extra parameters added by the algorithm subclass.
static QString typeName()
Returns the type name for the parameter class.
QThread * thread()
Returns the thread in which the context lives.
static QString typeName()
Returns the type name for the parameter class.
virtual QgsProcessingAlgorithm * createInstance() const =0
Creates a new instance of the algorithm class.
Base class for the definition of processing parameters.
@ TypeVectorLine
Vector line layers.
QString parameterAsCompatibleSourceLayerPath(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr)
Evaluates the parameter with matching name to a source vector layer file path of compatible format.
virtual QString svgIconPath() const
Returns a path to an SVG version of the algorithm's icon.
An input feature source (such as vector layers) parameter for processing algorithms.
QgsGeometry parameterAsExtentGeometry(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching name to a rectangular extent, and returns a geometry covering t...
Encapsulates settings relating to a feature sink or output raster layer for a processing algorithm.
Type
The WKB type describes the number of dimensions a geometry has.
QVariantMap run(const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback, bool *ok=nullptr, const QVariantMap &configuration=QVariantMap(), bool catchExceptions=true) const SIP_THROW(QgsProcessingException)
Executes the algorithm using the specified parameters.
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...
Type propertyType() const
Returns the property type.
bool supportInPlaceEdit(const QgsMapLayer *layer) const override
Checks whether this algorithm supports in-place editing on the given layer Default implementation for...
virtual bool prepareAlgorithm(const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback) SIP_THROW(QgsProcessingException)
Prepares the algorithm to run using the specified parameters.
int parameterAsEnum(const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a enum value.
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
QString parameterAsString(const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static string value.
@ TypeVectorPoint
Vector point layers.
static QString parameterAsSchema(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database schema name.
static QgsRasterLayer * parameterAsRasterLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a raster layer.
QgsProperty source
Source definition.
const QgsProcessingOutputDefinition * outputDefinition(const QString &name) const
Returns a matching output by name.
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...
QList< QgsExpressionContextScope * > takeScopes()
Returns all scopes from this context and remove them, leaving this context without any context.
A rectangle specified with double values.
double parameterAsDouble(const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static double value.
virtual QgsFeatureSink::SinkFlags sinkFlags() const
Returns the feature sink flags to be used for the output.
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...
@ Available
Properties are available.
QList< const QgsProcessingParameterDefinition * > QgsProcessingParameterDefinitions
List of processing parameters.
QgsCoordinateReferenceSystem parameterAsPointCrs(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context)
Returns the coordinate reference system associated with an point parameter value.
virtual QgsProcessingFeatureSource::Flag sourceFlags() const
Returns the processing feature source flags to be used in the algorithm.
static QString typeName()
Returns the type name for the parameter class.
bool parameterAsBoolean(const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static boolean value.
void setSupportsNonFileBasedOutput(bool supportsNonFileBasedOutput)
Sets whether the destination parameter supports non filed-based outputs, such as memory layers or dir...
QString parameterAsSchema(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context)
Evaluates the parameter with matching name to a database schema name string.
A feature sink output for processing algorithms.
static QList< double > parameterAsRange(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a range of values.
Base class for all parameter definitions which represent file or layer destinations,...
static QString parameterAsFile(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a file/folder name.
QString parameterAsOutputLayer(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a output layer destination.
Base class for the definition of processing outputs.
static QList< QgsMapLayer * > parameterAsLayerList(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of map layers.
bool addOutput(QgsProcessingOutputDefinition *outputDefinition)
Adds an output definition to the algorithm.
Encapsulates settings relating to a feature source input to a processing algorithm.
bool autoCreated() const
Returns true if the output was automatically created when adding a parameter.
This class wraps a request for features to a vector layer (or directly its vector data provider).
QString parameterAsFile(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a file/folder name.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
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...
QList< QgsMapLayer * > parameterAsLayerList(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a list of map layers.
Print layout, a QgsLayout subclass for static or atlas-based layouts.
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.
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.
void takeResultsFrom(QgsProcessingContext &context)
Takes the results from another context and merges them with the results currently stored in this cont...
@ TypeVector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
virtual QString name() const =0
Returns the algorithm name, used for identifying the algorithm.
QString id() const
Returns the unique ID for the algorithm, which is a combination of the algorithm provider's ID and th...
void initAlgorithm(const QVariantMap &configuration=QVariantMap()) override
Initializes the algorithm using the specified configuration.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
virtual QVariantMap processAlgorithm(const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback) SIP_THROW(QgsProcessingException)=0
Runs the algorithm using the specified parameters.
static QString typeName()
Returns the type name for the parameter class.
static QgsVectorLayer * parameterAsVectorLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a vector layer.
static QgsPointXY parameterAsPoint(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a point.
virtual QgsFeatureList processFeature(const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback) SIP_THROW(QgsProcessingException)=0
Processes an individual input feature from the source.
static QDateTime parameterAsDateTime(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static datetime value.
Contains information about the context in which a processing algorithm is executed.
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.
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.
QgsProcessingAlgorithm::Flags flags() const override
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
virtual ~QgsProcessingAlgorithm()
QString name() const
Returns the name of the parameter.
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...
QVariantMap processAlgorithm(const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback) override SIP_THROW(QgsProcessingException)
Runs the algorithm using the specified parameters.
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...
@ TypeVectorAnyGeometry
Any vector layer with geometry.
bool hasHtmlOutputs() const
Returns true if this algorithm generates HTML outputs.
QStringList parameterAsFields(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a list of fields.
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 QgsExpressionContextScope * processingAlgorithmScope(const QgsProcessingAlgorithm *algorithm, const QVariantMap ¶meters, QgsProcessingContext &context)
Creates a new scope which contains variables and functions relating to a processing algorithm,...
virtual QgsCoordinateReferenceSystem outputCrs(const QgsCoordinateReferenceSystem &inputCrs) const
Maps the input source coordinate reference system (inputCrs) to a corresponding output CRS generated ...
QList< QgsFeature > QgsFeatureList
QgsGeometry parameterAsGeometry(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem()) const
Evaluates the parameter with matching name to a geometry.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
virtual QString shortHelpString() const
Returns a localised short helper string for the algorithm.
static QgsPrintLayout * parameterAsLayout(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a print layout.
static QgsCoordinateReferenceSystem parameterAsPointCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an point parameter value.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
QList< double > parameterAsRange(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a range of values.
QgsMapLayer * parameterAsLayer(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a map layer.
Base class for graphical items within a QgsLayout.
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.
static QString typeName()
Returns the type name for the parameter class.
Represents a raster layer.
static QStringList parameterAsFileList(const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of files (for QgsProcessingParameterMultip...
QVariantMap runPrepared(const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback) SIP_THROW(QgsProcessingException)
Runs the algorithm, which has been prepared by an earlier call to prepare().
static QgsCoordinateReferenceSystem parameterAsGeometryCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Returns the coordinate reference system associated with a geometry parameter value.
QString parameterAsDatabaseTableName(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context)
Evaluates the parameter with matching name to a database table name string.
virtual bool supportInPlaceEdit(const QgsMapLayer *layer) const
Checks whether this algorithm supports in-place editing on the given layer Default implementation ret...
virtual QgsProcessing::SourceType outputLayerType() const
Returns the layer type for layers generated by this algorithm, if this is possible to determine in ad...
This class represents a coordinate reference system (CRS).
QgsMapLayerStore * temporaryLayerStore()
Returns a reference to the layer store used for storing temporary layers during algorithm execution.
QgsProcessingParameterDefinitions destinationParameterDefinitions() const
Returns a list of destination parameters definitions utilized by the algorithm.
Single scope for storing variables and functions for use within a QgsExpressionContext.
QString parameterAsCompatibleSourceLayerPathAndLayerName(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr, QString *layerName=nullptr)
Evaluates the parameter with matching name to a source vector layer file path and layer name of compa...
virtual QString outputName() const =0
Returns the translated, user visible name for any layers created by this algorithm.
virtual QgsFields outputFields(const QgsFields &inputFields) const
Maps the input source fields (inputFields) to corresponding output fields generated by the algorithm.
A class to represent a 2D point.
static QgsMeshLayer * parameterAsMeshLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition and value to a mesh layer.
virtual QString helpUrl() const
Returns a url pointing to the algorithm's help page.
bool isCanceled() const
Tells whether the operation has been canceled already.
@ FlagCanCancel
Algorithm can be canceled.
void setProvider(QgsProcessingProvider *provider)
Associates this algorithm with its provider.
virtual QWidget * createCustomParametersWidget(QWidget *parent=nullptr) const
If an algorithm subclass implements a custom parameters widget, a copy of this widget should be const...
QgsRasterLayer * parameterAsRasterLayer(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a raster layer.
Flag
Flags controlling how QgsProcessingFeatureSource fetches features.
bool parameterAsBool(const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static boolean value.
Abstract base class for processing algorithms.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
QString parameterAsFileOutput(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a file based output destination.
int countVisibleParameters() const
Returns the number of visible (non-hidden) parameters defined by this algorithm.
bool nextFeature(QgsFeature &f)
virtual QIcon icon() const
Returns an icon for the algorithm.
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
A geometry is the spatial representation of a feature.
virtual QString inputParameterName() const
Returns the name of the parameter corresponding to the input layer.
@ FlagHidden
Parameter is hidden and should not be shown to users.
Properties of a vector source or sink used in an algorithm.
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.
Represents a vector layer which manages a vector based data sets.
QgsPointXY parameterAsPoint(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem()) const
Evaluates the parameter with matching name to a point.
QgsProcessingAlgorithm * create(const QVariantMap &configuration=QVariantMap()) const SIP_THROW(QgsProcessingException)
Creates a copy of the algorithm, ready for execution.
virtual QVariantMap preprocessParameters(const QVariantMap ¶meters)
Pre-processes a set of parameters, allowing the algorithm to clean their values.
Base class for all map layer types.
virtual QVariantMap postProcessAlgorithm(QgsProcessingContext &context, QgsProcessingFeedback *feedback) SIP_THROW(QgsProcessingException)
Allows the algorithm to perform any required cleanup tasks.
static QString parameterAsOutputLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a output layer destination.
QgsWkbTypes::Type wkbType
Geometry (WKB) type.
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.
QgsExpressionContext & expressionContext()
Returns the expression context.
QgsFeatureSource subclass which proxies methods to an underlying QgsFeatureSource,...
QgsProcessingFeatureSource * parameterAsSource(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a feature source.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
QgsCoordinateReferenceSystem parameterAsGeometryCrs(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context)
Returns the coordinate reference system associated with a geometry parameter value.
@ FlagRequiresMatchingCrs
Algorithm requires that all input layers have matching coordinate reference systems.
virtual QgsExpressionContext createExpressionContext(const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeatureSource *source=nullptr) const
Creates an expression context relating to the algorithm.
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...
virtual Q_DECL_DEPRECATED QString helpString() const
Returns a localised help string for the algorithm.
static GeometryType geometryType(Type type) SIP_HOLDGIL
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
@ FlagSupportsBatch
Algorithm supports batch mode.
QVariantMap postProcess(QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Should be called in the main thread following the completion of runPrepared().
virtual bool isDestination() const
Returns true if this parameter represents a file or layer destination, e.g.
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source's coordinate reference system.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QVariant staticValue() const
Returns the current static value for the property.
static QString parameterAsFileOutput(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a file based output destination.
QColor parameterAsColor(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context)
Evaluates the parameter with matching name to a color, or returns an invalid color if the parameter w...
static QString parameterAsExpression(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to an expression.
static QgsFeatureSink * parameterAsSink(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsFields &fields, QgsWkbTypes::Type 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 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 ...
QgsProperty sink
Sink/layer definition.
virtual Flags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
QgsFeatureSink * parameterAsSink(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context, QString &destinationIdentifier, const QgsFields &fields, QgsWkbTypes::Type geometryType=QgsWkbTypes::NoGeometry, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem(), QgsFeatureSink::SinkFlags sinkFlags=QgsFeatureSink::SinkFlags(), const QVariantMap &createOptions=QVariantMap(), const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList()) const SIP_THROW(QgsProcessingException)
Evaluates the parameter with matching name to a feature sink.
QgsProcessingProvider * provider() const
Returns the provider to which this algorithm belongs.
@ StaticProperty
Static property (QgsStaticProperty)
QString name() const
Returns the name of the output.
Wrapper for iterator of features from vector data provider or vector layer.
int parameterAsInt(const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static integer value.
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
static int parameterAsEnum(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition 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.
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.
SourceType
Data source types enum.
virtual bool supportsNonFileBasedOutput() const
Returns true if the provider supports non-file based outputs (such as memory layers or direct databas...
Custom exception class for processing related exceptions.
virtual QList< int > inputLayerTypes() const
Returns the valid input layer types for the source layer for this algorithm.
QgsCoordinateReferenceSystem parameterAsCrs(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a coordinate reference system.
QString parameterAsExpression(const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to an expression.
An interface for objects which accept features via addFeature(s) methods.
QDateTime parameterAsDateTime(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context)
Evaluates the parameter with matching name to a DateTime, or returns an invalid date time if the para...
static double parameterAsDouble(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static double value.
virtual QgsFeatureRequest request() const
Returns the feature request used for fetching features to process from the source layer.
static int parameterAsInt(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static integer value.
@ FlagSupportsInPlaceEdits
Algorithm supports in-place editing.
static QgsProcessingFeatureSource * parameterAsSource(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a feature source.
static QString typeName()
Returns the type name for the parameter class.
const QgsProcessingParameterDefinition * parameterDefinition(const QString &name) const
Returns a matching parameter by name.
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
QString parameterAsConnectionName(const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context)
Evaluates the parameter with matching name to a connection name string.
static bool parameterAsBool(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static boolean value.
QgsProcessingAlgorithm::PropertyAvailability availability
Availability of the properties. By default properties are not available.
static QString parameterAsString(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static string value.