QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
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 |
Flags that affect how processing algorithms are run. More... | |
Public Member Functions | |
QgsProcessingContext () | |
Constructor for QgsProcessingContext. More... | |
QgsProcessingContext (const QgsProcessingContext &other)=delete | |
QgsProcessingContext cannot be copied. More... | |
~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. More... | |
QgsUnitTypes::AreaUnit | areaUnit () const |
Returns the area unit to use for area calculations. More... | |
void | copyThreadSafeSettings (const QgsProcessingContext &other) |
Copies all settings which are safe for use across different threads from other to this context. More... | |
QString | defaultEncoding () const |
Returns the default encoding to use for newly created files. More... | |
std::function< void(const QgsFeature &) > | defaultInvalidGeometryCallbackForCheck (QgsFeatureRequest::InvalidGeometryCheck check, QgsFeatureSource *source=nullptr) const |
Returns the default callback function to use for a particular invalid geometry check. More... | |
QgsUnitTypes::DistanceUnit | distanceUnit () const |
Returns the distance unit to use for distance calculations. More... | |
QString | ellipsoid () const |
Returns the ellipsoid to use for distance and area calculations. More... | |
QgsExpressionContext & | expressionContext () |
Returns the expression context. More... | |
const QgsExpressionContext & | expressionContext () const |
Returns the expression context. More... | |
QgsProcessingFeedback * | feedback () |
Returns the associated feedback object. More... | |
QgsProcessingContext::Flags | flags () const |
Returns any flags set in the context. More... | |
QgsMapLayer * | getMapLayer (const QString &identifier) |
Returns a map layer from the context with a matching identifier. More... | |
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. More... | |
QgsFeatureRequest::InvalidGeometryCheck | invalidGeometryCheck () const |
Returns the behavior used for checking invalid geometries in input layers. More... | |
QMap< QString, QgsProcessingContext::LayerDetails > | layersToLoadOnCompletion () const |
Returns a map of layers (by ID or datasource) to LayerDetails, to load into the canvas upon completion of the algorithm or model. More... | |
QgsProcessingContext::LayerDetails & | layerToLoadOnCompletionDetails (const QString &layer) |
Returns a reference to the details for a given layer which is loaded on completion of the algorithm or model. More... | |
QgsProcessingContext & | operator= (const QgsProcessingContext &other)=delete |
QgsProcessingContext cannot be copied. More... | |
QString | preferredRasterFormat () const |
Returns the preferred raster format to use for vector outputs. More... | |
QString | preferredVectorFormat () const |
Returns the preferred vector format to use for vector outputs. More... | |
QgsProject * | project () const |
Returns the project in which the algorithm is being executed. More... | |
void | pushToThread (QThread *thread) |
Pushes the thread affinity for the context (including all layers contained in the temporaryLayerStore()) into another thread. More... | |
void | setAreaUnit (QgsUnitTypes::AreaUnit areaUnit) |
Sets the unit to use for area calculations. More... | |
void | setDefaultEncoding (const QString &encoding) |
Sets the default encoding to use for newly created files. More... | |
void | setDistanceUnit (QgsUnitTypes::DistanceUnit unit) |
Sets the unit to use for distance calculations. More... | |
void | setEllipsoid (const QString &ellipsoid) |
Sets a specified ellipsoid to use for distance and area calculations. More... | |
void | setExpressionContext (const QgsExpressionContext &context) |
Sets the expression context. More... | |
void | setFeedback (QgsProcessingFeedback *feedback) |
Sets an associated feedback object. More... | |
void | setFlags (QgsProcessingContext::Flags flags) |
Sets flags for the context. More... | |
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. More... | |
void | setInvalidGeometryCheck (QgsFeatureRequest::InvalidGeometryCheck check) |
Sets the behavior used for checking invalid geometries in input layers. More... | |
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. More... | |
void | setPreferredRasterFormat (const QString &format) |
Sets the preferred raster format to use for vector outputs. More... | |
void | setPreferredVectorFormat (const QString &format) |
Sets the preferred vector format to use for vector outputs. More... | |
void | setProject (QgsProject *project) |
Sets the project in which the algorithm will be executed. More... | |
void | setTransformContext (const QgsCoordinateTransformContext &context) |
Sets the coordinate transform context. More... | |
void | setTransformErrorCallback (const std::function< void(const QgsFeature &) > &callback) |
Sets a callback function to use when encountering a transform error when iterating features. More... | |
QgsMapLayer * | takeResultLayer (const QString &id) |
Takes the result map layer with matching id from the context and transfers ownership of it back to the caller. More... | |
void | takeResultsFrom (QgsProcessingContext &context) |
Takes the results from another context and merges them with the results currently stored in this context. More... | |
QgsMapLayerStore * | temporaryLayerStore () |
Returns a reference to the layer store used for storing temporary layers during algorithm execution. More... | |
QThread * | thread () |
Returns the thread in which the context lives. More... | |
QgsCoordinateTransformContext | transformContext () const |
Returns the coordinate transform context. More... | |
std::function< void(const QgsFeature &) > | transformErrorCallback () const |
Returns the callback function to use when encountering a transform error when iterating features. More... | |
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. More... | |
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 43 of file qgsprocessingcontext.h.
Flags that affect how processing algorithms are run.
Definition at line 48 of file qgsprocessingcontext.h.
QgsProcessingContext::QgsProcessingContext | ( | ) |
Constructor for QgsProcessingContext.
Definition at line 23 of file qgsprocessingcontext.cpp.
|
delete |
QgsProcessingContext cannot be copied.
QgsProcessingContext::~QgsProcessingContext | ( | ) |
Definition at line 35 of file qgsprocessingcontext.cpp.
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.
Definition at line 53 of file qgsprocessingcontext.cpp.
QgsUnitTypes::AreaUnit QgsProcessingContext::areaUnit | ( | ) | const |
Returns the area unit to use for area calculations.
Definition at line 151 of file qgsprocessingcontext.cpp.
|
inline |
Copies all settings which are safe for use across different threads from other to this context.
Definition at line 70 of file qgsprocessingcontext.h.
|
inline |
Returns the default encoding to use for newly created files.
Definition at line 464 of file qgsprocessingcontext.h.
std::function< void(const QgsFeature &)> QgsProcessingContext::defaultInvalidGeometryCallbackForCheck | ( | QgsFeatureRequest::InvalidGeometryCheck | check, |
QgsFeatureSource * | source = nullptr |
||
) | const |
Returns the default callback function to use for a particular invalid geometry check.
Definition at line 76 of file qgsprocessingcontext.cpp.
QgsUnitTypes::DistanceUnit QgsProcessingContext::distanceUnit | ( | ) | const |
Returns the distance unit to use for distance calculations.
Definition at line 141 of file qgsprocessingcontext.cpp.
QString QgsProcessingContext::ellipsoid | ( | ) | const |
Returns the ellipsoid to use for distance and area calculations.
Definition at line 131 of file qgsprocessingcontext.cpp.
|
inline |
Returns the expression context.
Definition at line 133 of file qgsprocessingcontext.h.
|
inline |
Returns the expression context.
Definition at line 138 of file qgsprocessingcontext.h.
|
inline |
Returns the associated feedback object.
Definition at line 476 of file qgsprocessingcontext.h.
|
inline |
Returns any flags set in the context.
Definition at line 93 of file qgsprocessingcontext.h.
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.
Definition at line 121 of file qgsprocessingcontext.cpp.
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.
Definition at line 68 of file qgsprocessingcontext.cpp.
|
inline |
Returns the behavior used for checking invalid geometries in input layers.
Definition at line 375 of file qgsprocessingcontext.h.
|
inline |
Returns a map of layers (by ID or datasource) to LayerDetails, to load into the canvas upon completion of the algorithm or model.
Definition at line 315 of file qgsprocessingcontext.h.
|
inline |
Returns a reference to the details for a given layer which is loaded on completion of the algorithm or model.
Definition at line 366 of file qgsprocessingcontext.h.
|
delete |
QgsProcessingContext cannot be copied.
|
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.
Definition at line 593 of file qgsprocessingcontext.h.
|
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.
Definition at line 556 of file qgsprocessingcontext.h.
|
inline |
Returns the project in which the algorithm is being executed.
Definition at line 105 of file qgsprocessingcontext.h.
|
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()).
Definition at line 500 of file qgsprocessingcontext.h.
void QgsProcessingContext::setAreaUnit | ( | QgsUnitTypes::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.
Definition at line 156 of file qgsprocessingcontext.cpp.
|
inline |
Sets the default encoding to use for newly created files.
Definition at line 470 of file qgsprocessingcontext.h.
void QgsProcessingContext::setDistanceUnit | ( | QgsUnitTypes::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.
Definition at line 146 of file qgsprocessingcontext.cpp.
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.
Definition at line 136 of file qgsprocessingcontext.cpp.
|
inline |
Sets the expression context.
Definition at line 143 of file qgsprocessingcontext.h.
|
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.
Definition at line 486 of file qgsprocessingcontext.h.
|
inline |
|
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.
Definition at line 393 of file qgsprocessingcontext.h.
void QgsProcessingContext::setInvalidGeometryCheck | ( | QgsFeatureRequest::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.
Definition at line 61 of file qgsprocessingcontext.cpp.
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.
Definition at line 43 of file qgsprocessingcontext.cpp.
|
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.
Definition at line 610 of file qgsprocessingcontext.h.
|
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.
Definition at line 573 of file qgsprocessingcontext.h.
|
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.
Definition at line 115 of file qgsprocessingcontext.h.
|
inline |
Sets the coordinate transform context.
Note that setting a project for the context will automatically set the coordinate transform context.
Definition at line 159 of file qgsprocessingcontext.h.
|
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.
Definition at line 434 of file qgsprocessingcontext.h.
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.
Definition at line 126 of file qgsprocessingcontext.cpp.
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 114 of file qgsprocessingcontext.cpp.
|
inline |
Returns a reference to the layer store used for storing temporary layers during algorithm execution.
Definition at line 223 of file qgsprocessingcontext.h.
|
inline |
Returns the thread in which the context lives.
Definition at line 492 of file qgsprocessingcontext.h.
|
inline |
Returns the coordinate transform context.
Definition at line 149 of file qgsprocessingcontext.h.
|
inline |
Returns the callback function to use when encountering a transform error when iterating features.
Definition at line 458 of file qgsprocessingcontext.h.
|
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.
Definition at line 329 of file qgsprocessingcontext.h.