Class: QgsProcessingContext¶
-
class
qgis.core.
QgsProcessingContext
¶ Bases:
sip.wrapper
Constructor for QgsProcessingContext.
Contains information about the context in which a processing algorithm is executed.
Contextual information includes settings such as the associated project, and expression context.
New in version 3.0: Enums
Methods
Adds a
layer
to load (by ID or datasource) into the canvas upon completion of the algorithm or model.Copies all settings which are safe for use across different threads from
other
to this context.Returns the default encoding to use for newly created files.
Returns the expression context.
Returns the associated feedback object.
Returns any flags set in the context.
Returns a map layer from the context with a matching
identifier
.Returns the behavior used for checking invalid geometries in input layers.
Returns a reference to the details for a given
layer
which is loaded on completion of the algorithm or model.Returns a map of layers (by ID or datasource) to LayerDetails, to load into the canvas upon completion of the algorithm or model.
Returns the project in which the algorithm is being executed.
Pushes the thread affinity for the context (including all layers contained in the temporaryLayerStore()) into another
thread
.Sets the default
encoding
to use for newly created files.Sets the expression
context
.Sets an associated
feedback
object.Sets
flags
for the context.Sets a callback function to use when encountering an invalid geometry and invalidGeometryCheck() is set to GeometryAbortOnInvalid.
Sets the behavior used for checking invalid geometries in input layers.
Sets the map of
layers
(by ID or datasource) to LayerDetails, to load into the canvas upon completion of the algorithm or model.Sets the
project
in which the algorithm will be executed.Sets the coordinate transform
context
.Sets a callback function to use when encountering a transform error when iterating features.
Takes the result map layer with matching
id
from the context and transfers ownership of it back to the caller.Takes the results from another
context
and merges them with the results currently stored in this context.Returns a reference to the layer store used for storing temporary layers during algorithm execution.
Returns the thread in which the context lives.
Returns the coordinate transform context.
Returns
True
if the givenlayer
(by ID or datasource) will be loaded into the current project upon completion of the algorithm or model.Signals
Attributes
-
class
Flag
¶ Bases:
int
-
class
Flags
¶ Bases:
sip.wrapper
QgsProcessingContext.Flags(Union[QgsProcessingContext.Flags, QgsProcessingContext.Flag]) QgsProcessingContext.Flags(QgsProcessingContext.Flags)
-
class
LayerDetails
(name: str, project: QgsProject, outputName: str = '', layerTypeHint: QgsProcessingUtils.LayerHint = QgsProcessingUtils.LayerHint.UnknownType)¶ Bases:
sip.wrapper
Constructor for LayerDetails.
QgsProcessingContext.LayerDetails() Default constructor
QgsProcessingContext.LayerDetails(QgsProcessingContext.LayerDetails)
Details for layers to load into projects.
New in version 3.0.
-
layerTypeHint
¶
-
name
¶
-
outputName
¶
-
postProcessor
(self) → QgsProcessingLayerPostProcessorInterface¶ Layer post-processor. May be
None
if no post-processing is required.See also
New in version 3.2.
-
project
¶
-
setPostProcessor
(self, processor: QgsProcessingLayerPostProcessorInterface)¶ Sets the layer post-processor. May be
None
if no post-processing is required.Ownership of
processor
is transferred.See also
New in version 3.2.
-
-
addLayerToLoadOnCompletion
(self, layer: str, details: QgsProcessingContext.LayerDetails)¶ Adds a
layer
to load (by ID or datasource) into the canvas upon completion of the algorithm or model. Thedetails
parameter dictates the LayerDetails.See also
See also
See also
See also
-
copyThreadSafeSettings
(self, other: QgsProcessingContext)¶ Copies all settings which are safe for use across different threads from
other
to this context.
-
defaultEncoding
(self) → str¶ Returns the default encoding to use for newly created files.
See also
-
expressionContext
(self) → QgsExpressionContext¶ Returns the expression context.
-
feedback
(self) → QgsProcessingFeedback¶ Returns the associated feedback object.
See also
-
flags
(self) → QgsProcessingContext.Flags¶ Returns any flags set in the context.
See also
-
getMapLayer
(self, identifier: str) → QgsMapLayer¶ Returns a map layer from the context with a matching
identifier
. This method considers layer IDs, names and sources when matching theidentifier
(seeQgsProcessingUtils.mapLayerFromString()
for details).Ownership is not transferred and remains with the context.
See also
-
invalidGeometryCheck
(self) → QgsFeatureRequest.InvalidGeometryCheck¶ Returns the behavior used for checking invalid geometries in input layers.
See also
-
layerToLoadOnCompletionDetails
(self, layer: str) → QgsProcessingContext.LayerDetails¶ 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
See also
See also
See also
New in version 3.2.
-
layersToLoadOnCompletion
(self) → Dict[str, QgsProcessingContext.LayerDetails]¶ 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
See also
See also
See also
-
project
(self) → QgsProject¶ Returns the project in which the algorithm is being executed.
See also
-
pushToThread
(self, thread: QThread)¶ 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
-
setDefaultEncoding
(self, encoding: str)¶ Sets the default
encoding
to use for newly created files.See also
-
setExpressionContext
(self, context: QgsExpressionContext)¶ Sets the expression
context
.
-
setFeedback
(self, feedback: QgsProcessingFeedback)¶ 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 tofeedback
is stored and no errors will occur if feedback is deleted before the context. Ownership offeedback
is not transferred.See also
-
setFlags
(self, flags: Union[QgsProcessingContext.Flags, QgsProcessingContext.Flag])¶ Sets
flags
for the context.See also
-
setInvalidGeometryCallback
(self, Callable[..., None])¶ 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()
New in version 3.0.
-
setInvalidGeometryCheck
(self, check: QgsFeatureRequest.InvalidGeometryCheck)¶ 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
-
setLayersToLoadOnCompletion
(self, layers: Dict[str, QgsProcessingContext.LayerDetails])¶ 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
See also
See also
See also
-
setProject
(self, project: QgsProject)¶ Sets the
project
in which the algorithm will be executed.This also automatically sets the transformContext() to match the project’s transform context.
See also
-
setTransformContext
(self, context: QgsCoordinateTransformContext)¶ Sets the coordinate transform
context
.Note that setting a project for the context will automatically set the coordinate transform context.
See also
-
setTransformErrorCallback
(self, Callable[..., None])¶ 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()
New in version 3.0.
-
takeResultLayer
(self, id: str) → QgsMapLayer¶ 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
-
takeResultsFrom
(self, context: QgsProcessingContext)¶ 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 othercontext
share the same thread() affinity, and that thread is the current thread.
-
temporaryLayerStore
(self) → QgsMapLayerStore¶ Returns a reference to the layer store used for storing temporary layers during algorithm execution.
-
thread
(self) → QThread¶ Returns the thread in which the context lives.
See also
-
transformContext
(self) → QgsCoordinateTransformContext¶ Returns the coordinate transform context.
See also
-
willLoadLayerOnCompletion
(self, layer: str) → bool¶ Returns
True
if the givenlayer
(by ID or datasource) will be loaded into the current project upon completion of the algorithm or model.See also
See also
See also
See also
New in version 3.2.
-
class