QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
QgsProcessingContext Class Reference

Contains information about the context in which a processing algorithm is executed. More...

#include <qgsprocessingcontext.h>

Classes

class  LayerDetails
 Details for layers to load into projects. More...
 

Public Types

enum  Flag { Unused = 1 << 0 }
 Flags that affect how processing algorithms are run. More...
 
typedef QFlags< FlagFlags
 
enum class  ProcessArgumentFlag : int { IncludeProjectPath = 1 << 0 }
 Flags controlling the results given by asQgisProcessArguments(). More...
 
typedef QFlags< ProcessArgumentFlagProcessArgumentFlags
 

Public Member Functions

 QgsProcessingContext ()
 
 QgsProcessingContext (const QgsProcessingContext &other)=delete
 
 ~QgsProcessingContext ()
 
void addLayerToLoadOnCompletion (const QString &layer, const QgsProcessingContext::LayerDetails &details)
 Adds a layer to load (by ID or datasource) into the canvas upon completion of the algorithm or model.
 
Qgis::AreaUnit areaUnit () const
 Returns the area unit to use for area calculations.
 
QStringList asQgisProcessArguments (QgsProcessingContext::ProcessArgumentFlags flags=QgsProcessingContext::ProcessArgumentFlags()) const
 Returns list of the equivalent qgis_process arguments representing the settings from the context.
 
void copyThreadSafeSettings (const QgsProcessingContext &other)
 Copies all settings which are safe for use across different threads from other to this context.
 
QgsDateTimeRange currentTimeRange () const
 Returns the current time range to use for temporal operations.
 
QString defaultEncoding () const
 Returns the default encoding to use for newly created files.
 
std::function< void(const QgsFeature &) > defaultInvalidGeometryCallbackForCheck (Qgis::InvalidGeometryCheck check, QgsFeatureSource *source=nullptr) const
 Returns the default callback function to use for a particular invalid geometry check.
 
Qgis::DistanceUnit distanceUnit () const
 Returns the distance unit to use for distance calculations.
 
QString ellipsoid () const
 Returns the ellipsoid to use for distance and area calculations.
 
QVariantMap exportToMap () const
 Exports the context's settings to a variant map.
 
QgsExpressionContextexpressionContext ()
 Returns the expression context.
 
const QgsExpressionContextexpressionContext () const
 Returns the expression context.
 
QgsProcessingFeedbackfeedback ()
 Returns the associated feedback object.
 
QgsProcessingContext::Flags flags () const
 Returns any flags set in the context.
 
QgsMapLayergetMapLayer (const QString &identifier)
 Returns a map layer from the context with a matching identifier.
 
std::function< void(const QgsFeature &) > invalidGeometryCallback (QgsFeatureSource *source=nullptr) const
 Returns the callback function to use when encountering an invalid geometry and invalidGeometryCheck() is set to GeometryAbortOnInvalid.
 
Qgis::InvalidGeometryCheck invalidGeometryCheck () const
 Returns the behavior used for checking invalid geometries in input layers.
 
QMap< QString, QgsProcessingContext::LayerDetailslayersToLoadOnCompletion () const
 Returns a map of layers (by ID or datasource) to LayerDetails, to load into the canvas upon completion of the algorithm or model.
 
QgsProcessingContext::LayerDetailslayerToLoadOnCompletionDetails (const QString &layer)
 Returns a reference to the details for a given layer which is loaded on completion of the algorithm or model.
 
Qgis::ProcessingLogLevel logLevel () const
 Returns the logging level for algorithms to use when pushing feedback messages to users.
 
int maximumThreads () const
 Returns the (optional) number of threads to use when running algorithms.
 
QgsProcessingModelInitialRunConfigmodelInitialRunConfig ()
 Returns a reference to the model initial run configuration, used to run a model algorithm.
 
QgsProcessingModelResultmodelResult ()
 Returns a reference to the model results, populated when the context is used to run a model algorithm.
 
QgsProcessingModelResult modelResult () const
 Returns the model results, populated when the context is used to run a model algorithm.
 
QgsProcessingContextoperator= (const QgsProcessingContext &other)=delete
 
QString preferredRasterFormat () const
 Returns the preferred raster format to use for vector outputs.
 
QString preferredVectorFormat () const
 Returns the preferred vector format to use for vector outputs.
 
QgsProjectproject () const
 Returns the project in which the algorithm is being executed.
 
void pushToThread (QThread *thread)
 Pushes the thread affinity for the context (including all layers contained in the temporaryLayerStore()) into another thread.
 
void setAreaUnit (Qgis::AreaUnit areaUnit)
 Sets the unit to use for area calculations.
 
void setCurrentTimeRange (const QgsDateTimeRange &currentTimeRange)
 Sets the current time range to use for temporal operations.
 
void setDefaultEncoding (const QString &encoding)
 Sets the default encoding to use for newly created files.
 
void setDistanceUnit (Qgis::DistanceUnit unit)
 Sets the unit to use for distance calculations.
 
void setEllipsoid (const QString &ellipsoid)
 Sets a specified ellipsoid to use for distance and area calculations.
 
void setExpressionContext (const QgsExpressionContext &context)
 Sets the expression context.
 
void setFeedback (QgsProcessingFeedback *feedback)
 Sets an associated feedback object.
 
void setFlags (QgsProcessingContext::Flags flags)
 Sets flags for the context.
 
void setInvalidGeometryCallback (const std::function< void(const QgsFeature &) > &callback)
 Sets a callback function to use when encountering an invalid geometry and invalidGeometryCheck() is set to GeometryAbortOnInvalid.
 
void setInvalidGeometryCheck (Qgis::InvalidGeometryCheck check)
 Sets the behavior used for checking invalid geometries in input layers.
 
void setLayersToLoadOnCompletion (const QMap< QString, QgsProcessingContext::LayerDetails > &layers)
 Sets the map of layers (by ID or datasource) to LayerDetails, to load into the canvas upon completion of the algorithm or model.
 
void setLogLevel (Qgis::ProcessingLogLevel level)
 Sets the logging level for algorithms to use when pushing feedback messages to users.
 
void setMaximumThreads (int threads)
 Sets the (optional) number of threads to use when running algorithms.
 
void setModelInitialRunConfig (std::unique_ptr< QgsProcessingModelInitialRunConfig > config)
 Sets the model initial run configuration, used to run a model algorithm.
 
void setPreferredRasterFormat (const QString &format)
 Sets the preferred raster format to use for vector outputs.
 
void setPreferredVectorFormat (const QString &format)
 Sets the preferred vector format to use for vector outputs.
 
void setProject (QgsProject *project)
 Sets the project in which the algorithm will be executed.
 
void setTemporaryFolder (const QString &folder)
 Sets the (optional) temporary folder to use when running algorithms.
 
void setTransformContext (const QgsCoordinateTransformContext &context)
 Sets the coordinate transform context.
 
void setTransformErrorCallback (const std::function< void(const QgsFeature &) > &callback)
 Sets a callback function to use when encountering a transform error when iterating features.
 
std::unique_ptr< QgsProcessingModelInitialRunConfigtakeModelInitialRunConfig ()
 Takes the model initial run configuration from the context.
 
QgsMapLayertakeResultLayer (const QString &id)
 Takes the result map layer with matching id from the context and transfers ownership of it back to the caller.
 
void takeResultsFrom (QgsProcessingContext &context)
 Takes the results from another context and merges them with the results currently stored in this context.
 
QString temporaryFolder () const
 Returns the (optional) temporary folder to use when running algorithms.
 
QgsMapLayerStoretemporaryLayerStore ()
 Returns a reference to the layer store used for storing temporary layers during algorithm execution.
 
QThread * thread ()
 Returns the thread in which the context lives.
 
QgsCoordinateTransformContext transformContext () const
 Returns the coordinate transform context.
 
std::function< void(const QgsFeature &) > transformErrorCallback () const
 Returns the callback function to use when encountering a transform error when iterating features.
 
bool willLoadLayerOnCompletion (const QString &layer) const
 Returns true if the given layer (by ID or datasource) will be loaded into the current project upon completion of the algorithm or model.
 

Detailed Description

Contains information about the context in which a processing algorithm is executed.

Contextual information includes settings such as the associated project, and expression context.

Definition at line 44 of file qgsprocessingcontext.h.

Member Typedef Documentation

◆ Flags

typedef QFlags< Flag > QgsProcessingContext::Flags

Definition at line 54 of file qgsprocessingcontext.h.

◆ ProcessArgumentFlags

Definition at line 724 of file qgsprocessingcontext.h.

Member Enumeration Documentation

◆ Flag

Flags that affect how processing algorithms are run.

Enumerator
Unused 

Temporary unused entry.

Definition at line 49 of file qgsprocessingcontext.h.

◆ ProcessArgumentFlag

Flags controlling the results given by asQgisProcessArguments().

Since
QGIS 3.24
Enumerator
IncludeProjectPath 

Include the associated project path argument.

Definition at line 720 of file qgsprocessingcontext.h.

Constructor & Destructor Documentation

◆ QgsProcessingContext() [1/2]

QgsProcessingContext::QgsProcessingContext ( )

Definition at line 28 of file qgsprocessingcontext.cpp.

◆ QgsProcessingContext() [2/2]

QgsProcessingContext::QgsProcessingContext ( const QgsProcessingContext other)
delete

◆ ~QgsProcessingContext()

QgsProcessingContext::~QgsProcessingContext ( )

Definition at line 41 of file qgsprocessingcontext.cpp.

Member Function Documentation

◆ addLayerToLoadOnCompletion()

void QgsProcessingContext::addLayerToLoadOnCompletion ( const QString &  layer,
const QgsProcessingContext::LayerDetails details 
)

Adds a layer to load (by ID or datasource) into the canvas upon completion of the algorithm or model.

The details parameter dictates the LayerDetails.

See also
setLayersToLoadOnCompletion()
layersToLoadOnCompletion()
willLoadLayerOnCompletion()
layerToLoadOnCompletionDetails()

Definition at line 66 of file qgsprocessingcontext.cpp.

◆ areaUnit()

Qgis::AreaUnit QgsProcessingContext::areaUnit ( ) const

Returns the area unit to use for area calculations.

See also
setAreaUnit()
distanceUnit()
Since
QGIS 3.16

Definition at line 254 of file qgsprocessingcontext.cpp.

◆ asQgisProcessArguments()

QStringList QgsProcessingContext::asQgisProcessArguments ( QgsProcessingContext::ProcessArgumentFlags  flags = QgsProcessingContext::ProcessArgumentFlags()) const

Returns list of the equivalent qgis_process arguments representing the settings from the context.

Since
QGIS 3.24

Definition at line 190 of file qgsprocessingcontext.cpp.

◆ copyThreadSafeSettings()

void QgsProcessingContext::copyThreadSafeSettings ( const QgsProcessingContext other)
inline

Copies all settings which are safe for use across different threads from other to this context.

Definition at line 67 of file qgsprocessingcontext.h.

◆ currentTimeRange()

QgsDateTimeRange QgsProcessingContext::currentTimeRange ( ) const

Returns the current time range to use for temporal operations.

See also
setCurrentTimeRange()
Since
QGIS 3.18

Definition at line 224 of file qgsprocessingcontext.cpp.

◆ defaultEncoding()

QString QgsProcessingContext::defaultEncoding ( ) const
inline

Returns the default encoding to use for newly created files.

See also
setDefaultEncoding()

Definition at line 492 of file qgsprocessingcontext.h.

◆ defaultInvalidGeometryCallbackForCheck()

std::function< void(const QgsFeature &)> QgsProcessingContext::defaultInvalidGeometryCallbackForCheck ( Qgis::InvalidGeometryCheck  check,
QgsFeatureSource source = nullptr 
) const

Returns the default callback function to use for a particular invalid geometry check.

Note
not available in Python bindings
Since
QGIS 3.14

Definition at line 89 of file qgsprocessingcontext.cpp.

◆ distanceUnit()

Qgis::DistanceUnit QgsProcessingContext::distanceUnit ( ) const

Returns the distance unit to use for distance calculations.

See also
setDistanceUnit()
areaUnit()
Since
QGIS 3.16

Definition at line 244 of file qgsprocessingcontext.cpp.

◆ ellipsoid()

QString QgsProcessingContext::ellipsoid ( ) const

Returns the ellipsoid to use for distance and area calculations.

See also
setEllipsoid()
Since
QGIS 3.16

Definition at line 234 of file qgsprocessingcontext.cpp.

◆ exportToMap()

QVariantMap QgsProcessingContext::exportToMap ( ) const

Exports the context's settings to a variant map.

Since
QGIS 3.24

Definition at line 175 of file qgsprocessingcontext.cpp.

◆ expressionContext() [1/2]

QgsExpressionContext & QgsProcessingContext::expressionContext ( )
inline

Returns the expression context.

Definition at line 135 of file qgsprocessingcontext.h.

◆ expressionContext() [2/2]

const QgsExpressionContext & QgsProcessingContext::expressionContext ( ) const
inline

Returns the expression context.

Definition at line 140 of file qgsprocessingcontext.h.

◆ feedback()

QgsProcessingFeedback * QgsProcessingContext::feedback ( )
inline

Returns the associated feedback object.

See also
setFeedback()

Definition at line 504 of file qgsprocessingcontext.h.

◆ flags()

QgsProcessingContext::Flags QgsProcessingContext::flags ( ) const
inline

Returns any flags set in the context.

See also
setFlags()

Definition at line 95 of file qgsprocessingcontext.h.

◆ getMapLayer()

QgsMapLayer * QgsProcessingContext::getMapLayer ( const QString &  identifier)

Returns a map layer from the context with a matching identifier.

This method considers layer IDs, names and sources when matching the identifier (see QgsProcessingUtils::mapLayerFromString() for details).

Ownership is not transferred and remains with the context.

See also
takeResultLayer()

Definition at line 135 of file qgsprocessingcontext.cpp.

◆ invalidGeometryCallback()

std::function< void(const QgsFeature &)> QgsProcessingContext::invalidGeometryCallback ( QgsFeatureSource source = nullptr) const

Returns the callback function to use when encountering an invalid geometry and invalidGeometryCheck() is set to GeometryAbortOnInvalid.

Note
not available in Python bindings
See also
setInvalidGeometryCallback()

Definition at line 81 of file qgsprocessingcontext.cpp.

◆ invalidGeometryCheck()

Qgis::InvalidGeometryCheck QgsProcessingContext::invalidGeometryCheck ( ) const
inline

Returns the behavior used for checking invalid geometries in input layers.

See also
setInvalidGeometryCheck()

Definition at line 407 of file qgsprocessingcontext.h.

◆ layersToLoadOnCompletion()

QMap< QString, QgsProcessingContext::LayerDetails > QgsProcessingContext::layersToLoadOnCompletion ( ) const
inline

Returns a map of layers (by ID or datasource) to LayerDetails, to load into the canvas upon completion of the algorithm or model.

See also
setLayersToLoadOnCompletion()
addLayerToLoadOnCompletion()
willLoadLayerOnCompletion()
layerToLoadOnCompletionDetails()

Definition at line 347 of file qgsprocessingcontext.h.

◆ layerToLoadOnCompletionDetails()

QgsProcessingContext::LayerDetails & QgsProcessingContext::layerToLoadOnCompletionDetails ( const QString &  layer)
inline

Returns a reference to the details for a given layer which is loaded on completion of the algorithm or model.

Warning
First check willLoadLayerOnCompletion(), or calling this method will incorrectly add layer as a layer to load on completion.
See also
willLoadLayerOnCompletion()
addLayerToLoadOnCompletion()
setLayersToLoadOnCompletion()
layersToLoadOnCompletion()
Since
QGIS 3.2

Definition at line 398 of file qgsprocessingcontext.h.

◆ logLevel()

Qgis::ProcessingLogLevel QgsProcessingContext::logLevel ( ) const

Returns the logging level for algorithms to use when pushing feedback messages to users.

See also
setLogLevel()
Since
QGIS 3.20

Definition at line 145 of file qgsprocessingcontext.cpp.

◆ maximumThreads()

int QgsProcessingContext::maximumThreads ( ) const

Returns the (optional) number of threads to use when running algorithms.

Warning
Not all algorithms which support multithreaded execution will respect this setting, depending on the multi-threading framework in use. Multithreaded algorithms must check this value and adapt their thread handling accordingly – the setting will not be automatically applied.
See also
setMaximumThreads()
Since
QGIS 3.32

Definition at line 165 of file qgsprocessingcontext.cpp.

◆ modelInitialRunConfig()

QgsProcessingModelInitialRunConfig * QgsProcessingContext::modelInitialRunConfig ( )

Returns a reference to the model initial run configuration, used to run a model algorithm.

This may be nullptr, e.g. when the context is not being used to run a model.

Note
This configuration will only be used when running a "top-level" model algorithm, and will not be passed on to child models used within that initial top-level model.
Not available in Python bindings
See also
setModelInitialRunConfig()
takeModelInitialRunConfig()
Since
QGIS 3.38

Definition at line 314 of file qgsprocessingcontext.cpp.

◆ modelResult() [1/2]

QgsProcessingModelResult & QgsProcessingContext::modelResult ( )
inline

Returns a reference to the model results, populated when the context is used to run a model algorithm.

Note
Not available in Python bindings
Since
QGIS 3.38

Definition at line 795 of file qgsprocessingcontext.h.

◆ modelResult() [2/2]

QgsProcessingModelResult QgsProcessingContext::modelResult ( ) const
inline

Returns the model results, populated when the context is used to run a model algorithm.

Since
QGIS 3.38

Definition at line 785 of file qgsprocessingcontext.h.

◆ operator=()

QgsProcessingContext & QgsProcessingContext::operator= ( const QgsProcessingContext other)
delete

◆ preferredRasterFormat()

QString QgsProcessingContext::preferredRasterFormat ( ) const
inline

Returns the preferred raster format to use for vector outputs.

This method returns a file extension to use when creating raster outputs (e.g. "tif"). Generally, it is preferable to use the extension associated with a particular parameter, which can be retrieved through QgsProcessingDestinationParameter::defaultFileExtension(). However, in some cases, a specific parameter may not be available to call this method on (e.g. for an algorithm which has only an output folder parameter and which creates multiple output layers in that folder). In this case, the format returned by this function should be used when creating these outputs.

It is the algorithm's responsibility to check whether the returned format is acceptable for the algorithm, and to provide an appropriate fallback when the returned format is not usable.

See also
setPreferredRasterFormat()
preferredVectorFormat()
Since
QGIS 3.10

Definition at line 621 of file qgsprocessingcontext.h.

◆ preferredVectorFormat()

QString QgsProcessingContext::preferredVectorFormat ( ) const
inline

Returns the preferred vector format to use for vector outputs.

This method returns a file extension to use when creating vector outputs (e.g. "shp"). Generally, it is preferable to use the extension associated with a particular parameter, which can be retrieved through QgsProcessingDestinationParameter::defaultFileExtension(). However, in some cases, a specific parameter may not be available to call this method on (e.g. for an algorithm which has only an output folder parameter and which creates multiple output layers in that folder). In this case, the format returned by this function should be used when creating these outputs.

It is the algorithm's responsibility to check whether the returned format is acceptable for the algorithm, and to provide an appropriate fallback when the returned format is not usable.

See also
setPreferredVectorFormat()
preferredRasterFormat()
Since
QGIS 3.10

Definition at line 584 of file qgsprocessingcontext.h.

◆ project()

QgsProject * QgsProcessingContext::project ( ) const
inline

Returns the project in which the algorithm is being executed.

See also
setProject()

Definition at line 107 of file qgsprocessingcontext.h.

◆ pushToThread()

void QgsProcessingContext::pushToThread ( QThread *  thread)
inline

Pushes the thread affinity for the context (including all layers contained in the temporaryLayerStore()) into another thread.

This method is only safe to call when the current thread matches the existing thread affinity for the context (see thread()).

See also
thread()

Definition at line 528 of file qgsprocessingcontext.h.

◆ setAreaUnit()

void QgsProcessingContext::setAreaUnit ( Qgis::AreaUnit  areaUnit)

Sets the unit to use for area calculations.

If not explicitly set, the unit will default to the project()'s area unit setting.

See also
areaUnit()
setDistanceUnit()
Since
QGIS 3.16

Definition at line 259 of file qgsprocessingcontext.cpp.

◆ setCurrentTimeRange()

void QgsProcessingContext::setCurrentTimeRange ( const QgsDateTimeRange currentTimeRange)

Sets the current time range to use for temporal operations.

See also
currentTimeRange()
Since
QGIS 3.18

Definition at line 229 of file qgsprocessingcontext.cpp.

◆ setDefaultEncoding()

void QgsProcessingContext::setDefaultEncoding ( const QString &  encoding)
inline

Sets the default encoding to use for newly created files.

See also
defaultEncoding()

Definition at line 498 of file qgsprocessingcontext.h.

◆ setDistanceUnit()

void QgsProcessingContext::setDistanceUnit ( Qgis::DistanceUnit  unit)

Sets the unit to use for distance calculations.

If not explicitly set, the unit will default to the project()'s distance unit setting.

See also
distanceUnit()
setAreaUnit()
Since
QGIS 3.16

Definition at line 249 of file qgsprocessingcontext.cpp.

◆ setEllipsoid()

void QgsProcessingContext::setEllipsoid ( const QString &  ellipsoid)

Sets a specified ellipsoid to use for distance and area calculations.

If not explicitly set, the ellipsoid will default to the project()'s ellipsoid setting.

See also
ellipsoid()
Since
QGIS 3.16

Definition at line 239 of file qgsprocessingcontext.cpp.

◆ setExpressionContext()

void QgsProcessingContext::setExpressionContext ( const QgsExpressionContext context)

Sets the expression context.

Definition at line 49 of file qgsprocessingcontext.cpp.

◆ setFeedback()

void QgsProcessingContext::setFeedback ( QgsProcessingFeedback feedback)
inline

Sets an associated feedback object.

This allows context related functions to report feedback and errors to users and processing logs. While ideally this feedback object should outlive the context, only a weak pointer to feedback is stored and no errors will occur if feedback is deleted before the context. Ownership of feedback is not transferred.

See also
setFeedback()

Definition at line 514 of file qgsprocessingcontext.h.

◆ setFlags()

void QgsProcessingContext::setFlags ( QgsProcessingContext::Flags  flags)
inline

Sets flags for the context.

See also
flags()

Definition at line 101 of file qgsprocessingcontext.h.

◆ setInvalidGeometryCallback()

void QgsProcessingContext::setInvalidGeometryCallback ( const std::function< void(const QgsFeature &) > &  callback)
inline

Sets a callback function to use when encountering an invalid geometry and invalidGeometryCheck() is set to GeometryAbortOnInvalid.

This function will be called using the feature with invalid geometry as a parameter.

See also
invalidGeometryCallback()

Definition at line 424 of file qgsprocessingcontext.h.

◆ setInvalidGeometryCheck()

void QgsProcessingContext::setInvalidGeometryCheck ( Qgis::InvalidGeometryCheck  check)

Sets the behavior used for checking invalid geometries in input layers.

Settings this to anything but QgsFeatureRequest::GeometryNoCheck will also reset the invalidGeometryCallback() to a default implementation.

See also
invalidGeometryCheck()

Definition at line 74 of file qgsprocessingcontext.cpp.

◆ setLayersToLoadOnCompletion()

void QgsProcessingContext::setLayersToLoadOnCompletion ( const QMap< QString, QgsProcessingContext::LayerDetails > &  layers)

Sets the map of layers (by ID or datasource) to LayerDetails, to load into the canvas upon completion of the algorithm or model.

See also
addLayerToLoadOnCompletion()
layersToLoadOnCompletion()
willLoadLayerOnCompletion()
layerToLoadOnCompletionDetails()

Definition at line 56 of file qgsprocessingcontext.cpp.

◆ setLogLevel()

void QgsProcessingContext::setLogLevel ( Qgis::ProcessingLogLevel  level)

Sets the logging level for algorithms to use when pushing feedback messages to users.

See also
logLevel()
Since
QGIS 3.20

Definition at line 150 of file qgsprocessingcontext.cpp.

◆ setMaximumThreads()

void QgsProcessingContext::setMaximumThreads ( int  threads)

Sets the (optional) number of threads to use when running algorithms.

If set, this overrides the standard global Processing number of threads setting. Note that if algorithm implementation does not support multhreaded execution, this setting will be ignored.

Warning
Not all algorithms which support multithreaded execution will respect this setting, depending on the multi-threading framework in use. Multithreaded algorithms must check this value and adapt their thread handling accordingly – the setting will not be automatically applied.
See also
maximumThreads()
Since
QGIS 3.32

Definition at line 170 of file qgsprocessingcontext.cpp.

◆ setModelInitialRunConfig()

void QgsProcessingContext::setModelInitialRunConfig ( std::unique_ptr< QgsProcessingModelInitialRunConfig config)

Sets the model initial run configuration, used to run a model algorithm.

Note
This configuration will only be used when running a "top-level" model algorithm, and will not be passed on to child models used within that initial top-level model.
Not available in Python bindings
See also
modelInitialRunConfig()
takeModelInitialRunConfig()
Since
QGIS 3.38

Definition at line 319 of file qgsprocessingcontext.cpp.

◆ setPreferredRasterFormat()

void QgsProcessingContext::setPreferredRasterFormat ( const QString &  format)
inline

Sets the preferred raster format to use for vector outputs.

This method sets a file extension to use when creating raster outputs (e.g. "tif"). Generally, it is preferable to use the extension associated with a particular parameter, which can be retrieved through QgsProcessingDestinationParameter::defaultFileExtension(). However, in some cases, a specific parameter may not be available to call this method on (e.g. for an algorithm which has only an output folder parameter and which creates multiple output layers in that folder). In this case, the format set by this function will be used when creating these outputs.

See also
preferredRasterFormat()
setPreferredVectorFormat()
Since
QGIS 3.10

Definition at line 638 of file qgsprocessingcontext.h.

◆ setPreferredVectorFormat()

void QgsProcessingContext::setPreferredVectorFormat ( const QString &  format)
inline

Sets the preferred vector format to use for vector outputs.

This method sets a file extension to use when creating vector outputs (e.g. "shp"). Generally, it is preferable to use the extension associated with a particular parameter, which can be retrieved through QgsProcessingDestinationParameter::defaultFileExtension(). However, in some cases, a specific parameter may not be available to call this method on (e.g. for an algorithm which has only an output folder parameter and which creates multiple output layers in that folder). In this case, the format set by this function will be used when creating these outputs.

See also
preferredVectorFormat()
setPreferredRasterFormat()
Since
QGIS 3.10

Definition at line 601 of file qgsprocessingcontext.h.

◆ setProject()

void QgsProcessingContext::setProject ( QgsProject project)
inline

Sets the project in which the algorithm will be executed.

This also automatically sets the transformContext(), ellipsoid(), distanceUnit() and areaUnit() to match the project's settings.

See also
project()

Definition at line 117 of file qgsprocessingcontext.h.

◆ setTemporaryFolder()

void QgsProcessingContext::setTemporaryFolder ( const QString &  folder)

Sets the (optional) temporary folder to use when running algorithms.

If set, this overrides the standard global Processing temporary folder and should be used for all temporary files created during algorithm execution.

See also
temporaryFolder()
Since
QGIS 3.32

Definition at line 160 of file qgsprocessingcontext.cpp.

◆ setTransformContext()

void QgsProcessingContext::setTransformContext ( const QgsCoordinateTransformContext context)
inline

Sets the coordinate transform context.

Note that setting a project for the context will automatically set the coordinate transform context.

See also
transformContext()

Definition at line 161 of file qgsprocessingcontext.h.

◆ setTransformErrorCallback()

void QgsProcessingContext::setTransformErrorCallback ( const std::function< void(const QgsFeature &) > &  callback)
inline

Sets a callback function to use when encountering a transform error when iterating features.

This function will be called using the feature which encountered the transform error as a parameter.

See also
transformErrorCallback()

Definition at line 463 of file qgsprocessingcontext.h.

◆ takeModelInitialRunConfig()

std::unique_ptr< QgsProcessingModelInitialRunConfig > QgsProcessingContext::takeModelInitialRunConfig ( )

Takes the model initial run configuration from the context.

May return nullptr, e.g. when the context is not being used to run a model.

Note
Not available in Python bindings
See also
modelInitialRunConfig()
setModelInitialRunConfig()
Since
QGIS 3.38

Definition at line 324 of file qgsprocessingcontext.cpp.

◆ takeResultLayer()

QgsMapLayer * QgsProcessingContext::takeResultLayer ( const QString &  id)

Takes the result map layer with matching id from the context and transfers ownership of it back to the caller.

This method can be used to remove temporary layers which are not required for further processing from a context.

See also
getMapLayer()

Definition at line 140 of file qgsprocessingcontext.cpp.

◆ takeResultsFrom()

void QgsProcessingContext::takeResultsFrom ( QgsProcessingContext context)

Takes the results from another context and merges them with the results currently stored in this context.

This includes settings like any layers loaded in the temporaryLayerStore() and layersToLoadOnCompletion(). This is only safe to call when both this context and the other context share the same thread() affinity, and that thread is the current thread.

Definition at line 127 of file qgsprocessingcontext.cpp.

◆ temporaryFolder()

QString QgsProcessingContext::temporaryFolder ( ) const

Returns the (optional) temporary folder to use when running algorithms.

If set, this overrides the standard global Processing temporary folder and should be used for all temporary files created during algorithm execution.

See also
setTemporaryFolder()
Since
QGIS 3.32

Definition at line 155 of file qgsprocessingcontext.cpp.

◆ temporaryLayerStore()

QgsMapLayerStore * QgsProcessingContext::temporaryLayerStore ( )
inline

Returns a reference to the layer store used for storing temporary layers during algorithm execution.

Definition at line 241 of file qgsprocessingcontext.h.

◆ thread()

QThread * QgsProcessingContext::thread ( )
inline

Returns the thread in which the context lives.

See also
pushToThread()

Definition at line 520 of file qgsprocessingcontext.h.

◆ transformContext()

QgsCoordinateTransformContext QgsProcessingContext::transformContext ( ) const
inline

Returns the coordinate transform context.

See also
setTransformContext()

Definition at line 151 of file qgsprocessingcontext.h.

◆ transformErrorCallback()

std::function< void(const QgsFeature &) > QgsProcessingContext::transformErrorCallback ( ) const
inline

Returns the callback function to use when encountering a transform error when iterating features.

Note
not available in Python bindings
See also
setTransformErrorCallback()

Definition at line 486 of file qgsprocessingcontext.h.

◆ willLoadLayerOnCompletion()

bool QgsProcessingContext::willLoadLayerOnCompletion ( const QString &  layer) const
inline

Returns true if the given layer (by ID or datasource) will be loaded into the current project upon completion of the algorithm or model.

See also
layersToLoadOnCompletion()
setLayersToLoadOnCompletion()
addLayerToLoadOnCompletion()
layerToLoadOnCompletionDetails()
Since
QGIS 3.2

Definition at line 361 of file qgsprocessingcontext.h.


The documentation for this class was generated from the following files: