Class: QgsFeaturePool

A feature pool is based on a vector layer and caches features.

Note

This class is a technology preview and unstable API.

Added in version 3.4.

Note

This is an abstract class, with methods which must be implemented by a subclass.

The following methods must be implemented: QgsFeatureSink.addFeatures(), deleteFeature(), updateFeature()

Class Hierarchy

Inheritance diagram of qgis.analysis.QgsFeaturePool

Base classes

QgsFeatureSink

An interface for objects which accept features via addFeature(s) methods.

Abstract Methods

deleteFeature

Removes a feature from this pool.

updateFeature

Updates a feature in this pool.

Methods

crs

The coordinate reference system of this layer.

geometryType

The geometry type of this layer.

getFeature

Retrieves the feature with the specified id into feature.

layer

Gets a pointer to the underlying layer.

layerId

The layer id of the layer.

layerName

Returns the name of the layer.

class qgis.analysis.QgsFeaturePool[source]

Bases: QgsFeatureSink

__init__(layer: QgsVectorLayer | None)

Creates a new feature pool for layer.

Must be created on the same thread as layer.

Parameters:

layer (Optional[QgsVectorLayer])

crs(self) QgsCoordinateReferenceSystem[source]

The coordinate reference system of this layer.

Return type:

QgsCoordinateReferenceSystem

abstract deleteFeature(self, fid: int)[source]

Removes a feature from this pool. Implementations will remove the feature from the layer or from the data provider.

Warning

This method can safely be called from a different thread vs the object’s creation thread or the original layer’s thread. The update will be delegated to run in the main thread, and care must be taken to avoid deadlocks if the main thread is busy.

Parameters:

fid (int)

geometryType(self) Qgis.GeometryType[source]

The geometry type of this layer.

Return type:

Qgis.GeometryType

getFeature(self, id: int, feature: QgsFeature) bool[source]

Retrieves the feature with the specified id into feature. It will be retrieved from the cache or from the underlying feature source if unavailable. If the feature is neither available from the cache nor from the source it will return False.

Note

This method can safely be called from a different thread vs the object’s creation thread or the original layer’s thread.

Parameters:
Return type:

bool

layer(self) QgsVectorLayer | None[source]

Gets a pointer to the underlying layer. May return a ``None`` if the layer has been deleted.

Warning

This must be called from the same thread as the vector layer belongs to.

Return type:

Optional[QgsVectorLayer]

layerId(self) str[source]

The layer id of the layer.

Return type:

str

layerName(self) str[source]

Returns the name of the layer.

Should be preferred over layer().name() because it can directly be run on the background thread.

Return type:

str

abstract updateFeature(self, feature: QgsFeature)[source]

Updates a feature in this pool. Implementations will update the feature on the layer or on the data provider.

Warning

This method can safely be called from a different thread vs the object’s creation thread or the original layer’s thread. The update will be delegated to run in the main thread, and care must be taken to avoid deadlocks if the main thread is busy.

Parameters:

feature (QgsFeature)