Class: QgsVectorLayerCache¶
- class qgis.core.QgsVectorLayerCache¶
Bases:
PyQt5.QtCore.QObject
This class caches features of a given
QgsVectorLayer
.The cached features can be indexed by
QgsAbstractCacheIndex
.Proper indexing for a given use-case may speed up performance substantially.
Methods
Adds a
QgsAbstractCacheIndex
to this cache.Returns
True
if the cache will fetch and cache feature geometries.Returns the maximum number of features this cache will hold.
Returns the list (possibly a subset) of cached attributes.
Returns the set of feature IDs for features which are cached.
Checks if the information required to complete the request is cached.
Gets the feature at the given feature id.
Gets the feature at the given feature id with all attributes, if the cached feature already contains all attributes, calling this function has the same effect as calling
featureAtId()
.Returns the number of features contained in the source, or -1 if the feature count is unknown.
Gets called, whenever a feature has been removed.
Returns the fields associated with features in the cache.
Query the layer for the feature with the given id.
Query this VectorLayerCache for features.
Returns
True
if the cache is complete, ie it contains all features.Check if a certain feature id is cached.
Returns the layer to which this cache belongs
Removes the feature identified by fid from the cache if present.
Gets called, whenever the full list of feature ids for a certain request is known.
If this is enabled, the subset of cached attributes will automatically be extended to also include newly added attributes.
Enable or disable the caching of geometries
Sets the maximum number of features to keep in the cache.
Set the list (possibly a subset) of attributes to be cached.
This enables or disables full caching.
Returns the coordinate reference system for features in the cache.
Returns the geometry type for features in the cache.
Signals
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
- addCacheIndex(self, cacheIndex: QgsAbstractCacheIndex)¶
Adds a
QgsAbstractCacheIndex
to this cache. Cache indices know about features present in this cache and decide, if enough information is present in the cache to respond to aQgsFeatureRequest
. The layer cache will take ownership of the index.- Parameters:
cacheIndex (QgsAbstractCacheIndex) – The cache index to add.
- attributeValueChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- cacheGeometry(self) bool ¶
Returns
True
if the cache will fetch and cache feature geometries.See also
- Return type:
bool
- cacheSize(self) int ¶
Returns the maximum number of features this cache will hold. In case full caching is enabled, this number can change, as new features get added.
- Return type:
int
- Returns:
int
- cacheSubsetOfAttributes(self) List[int] ¶
Returns the list (possibly a subset) of cached attributes.
Note
By default the cache will store all layer’s attributes.
See also
New in version 3.32.
- Return type:
List[int]
- cachedFeatureIds(self) object ¶
Returns the set of feature IDs for features which are cached.
See also
- Return type:
object
- cachedLayerDeleted¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- checkInformationCovered(self, featureRequest: QgsFeatureRequest) bool ¶
Checks if the information required to complete the request is cached. i.e. If all attributes required and the geometry is held in the cache. Please note, that this does not check, if the requested features are cached.
- Parameters:
featureRequest (QgsFeatureRequest) – The
QgsFeatureRequest
to be answered- Return type:
bool
- Returns:
True
if the information is being cached,False
if not
- childEvent(self, QChildEvent)¶
- connectNotify(self, QMetaMethod)¶
- customEvent(self, QEvent)¶
- disconnectNotify(self, QMetaMethod)¶
- featureAdded¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- featureAtId(self, featureId: int, feature: QgsFeature, skipCache: bool = False) bool ¶
Gets the feature at the given feature id. Considers the changed, added, deleted and permanent features
- Parameters:
featureId (int) – The id of the feature to query
feature (QgsFeature) – The result of the operation will be written to this feature
skipCache (bool = False) – Will query the layer regardless if the feature is in the cache already
- Return type:
bool
- Returns:
True
in case of success
- featureAtIdWithAllAttributes(self, featureId: int, feature: QgsFeature, skipCache: bool = False) bool ¶
Gets the feature at the given feature id with all attributes, if the cached feature already contains all attributes, calling this function has the same effect as calling
featureAtId()
.Considers the changed, added, deleted and permanent features
- Parameters:
featureId (int) – The id of the feature to query
feature (QgsFeature) – The result of the operation will be written to this feature
skipCache (bool = False) – Will query the layer regardless if the feature is in the cache already
- Return type:
bool
- Returns:
True
in case of success
See also
New in version 3.32.
- featureCount(self) int ¶
Returns the number of features contained in the source, or -1 if the feature count is unknown.
- Return type:
int
- featureRemoved(self, fid: int)¶
Gets called, whenever a feature has been removed. Broadcasts this information to indices, so they can invalidate their cache if required.
- Parameters:
fid (int) – The feature id of the removed feature.
- finished¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- getFeature(self, fid: int) QgsFeature ¶
Query the layer for the feature with the given id. If there is no such feature, the returned feature will be invalid.
- Parameters:
fid (int) –
- Return type:
- getFeatures(self, featureRequest: QgsFeatureRequest = QgsFeatureRequest()) QgsFeatureIterator ¶
Query this VectorLayerCache for features. If the VectorLayerCache (and moreover any of its indices) is able to satisfy the request, the returned
QgsFeatureIterator
will iterate over cached features. If it’s not possible to fully satisfy the request from the cache, part or all of the features will be requested from the data provider.- Parameters:
featureRequest (
QgsFeatureRequest
= QgsFeatureRequest()) – The request specifying filter and required data.- Return type:
- Returns:
An iterator over the requested data.
getFeatures(self, expression: str) -> QgsFeatureIterator Query the layer for features matching a given expression.
getFeatures(self, fids: object) -> QgsFeatureIterator Query the layer for the features with the given ids.
getFeatures(self, rectangle:
QgsRectangle
) -> QgsFeatureIterator Query the layer for the features which intersect the specified rectangle.
- hasFullCache(self) bool ¶
Returns
True
if the cache is complete, ie it contains all features. This may happen as a result of a call tosetFullCache()
or by through a feature request which resulted in all available features being cached.See also
- Return type:
bool
- invalidated¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- isFidCached(self, fid: int) bool ¶
Check if a certain feature id is cached.
- Parameters:
fid (int) – The feature id to look for
- Return type:
bool
- Returns:
True
if this id is in the cache
See also
- isSignalConnected(self, QMetaMethod) bool ¶
- layer(self) QgsVectorLayer ¶
Returns the layer to which this cache belongs
- Return type:
- receivers(self, PYQT_SIGNAL) int ¶
- removeCachedFeature(self, fid: int) bool ¶
Removes the feature identified by fid from the cache if present.
- Parameters:
fid (int) – The id of the feature to delete
- Return type:
bool
- Returns:
True
if the feature was removed,False
if the feature id was not found in the cache
- requestCompleted(self, featureRequest: QgsFeatureRequest, fids: object)¶
Gets called, whenever the full list of feature ids for a certain request is known. Broadcasts this information to indices, so they can update their tables.
- Parameters:
featureRequest (QgsFeatureRequest) – The feature request that was answered
fids (object) – The feature ids that have been returned
- sender(self) QObject ¶
- senderSignalIndex(self) int ¶
- setCacheAddedAttributes(self, cacheAddedAttributes: bool)¶
If this is enabled, the subset of cached attributes will automatically be extended to also include newly added attributes.
- Parameters:
cacheAddedAttributes (bool) – Automatically cache new attributes
- setCacheGeometry(self, cacheGeometry: bool)¶
Enable or disable the caching of geometries
- Parameters:
cacheGeometry (bool) – Enable or disable the caching of geometries
See also
- setCacheSize(self, cacheSize: int)¶
Sets the maximum number of features to keep in the cache. Some features will be removed from the cache if the number is smaller than the previous size of the cache.
- Parameters:
cacheSize (int) – indicates the maximum number of features to keep in the cache
- setCacheSubsetOfAttributes(self, attributes: Iterable[int])¶
Set the list (possibly a subset) of attributes to be cached.
Note
By default the cache will store all layer’s attributes.
- Parameters:
attributes (Iterable[int]) – The attributes to be cached
- setFullCache(self, fullCache: bool)¶
This enables or disables full caching. If enabled, all features will be held in the cache. The cache size will incrementally be increased to offer space for all features. When enabled, all features will be read into cache. As this feature will most likely be used for slow data sources, be aware, that the call to this method might take a long time.
- Parameters:
fullCache (bool) –
True
: enable full caching,False
: disable full caching
Note
when a cache is
invalidated()
(e.g. by adding an attribute to a layer) this setting is reset. A full cache rebuild must be performed by calling setFullCache(True
) again.See also
- sourceCrs(self) QgsCoordinateReferenceSystem ¶
Returns the coordinate reference system for features in the cache.
- Return type:
- timerEvent(self, QTimerEvent)¶
- wkbType(self) Qgis.WkbType ¶
Returns the geometry type for features in the cache.
- Return type: