Class: QgsVectorLayerFeatureCounter

Counts the features in a QgsVectorLayer in task.

You should most likely not use this directly and instead call QgsVectorLayer.countSymbolFeatures() and connect to the signal QgsVectorLayer.symbolFeatureCountMapChanged().

Class Hierarchy

Inheritance diagram of qgis.core.QgsVectorLayerFeatureCounter

Base classes

QgsTask

Abstract base class for long running background tasks.

QObject

Abstract Methods

run

Calculates the feature count and Ids per symbol

Methods

featureCount

Returns the feature count for a particular legendKey.

featureIds

Returns the feature Ids for a particular legendKey.

Signals

symbolsCounted

Emitted when the symbols have been counted.

class qgis.core.QgsVectorLayerFeatureCounter[source]

Bases: QgsTask

__init__(layer: QgsVectorLayer | None, context: QgsExpressionContext = QgsExpressionContext(), storeSymbolFids: bool = False)

Create a new feature counter for layer.

Parameters:
  • layer (Optional[QgsVectorLayer]) – Target QgsVectorLayer to perform counting on.

  • context (QgsExpressionContext = QgsExpressionContext()) – Specific QgsExpressionContext to use during the rendering step.

  • storeSymbolFids (bool = False) – If True will store the feature ids (fids), otherwise will only count the number of features per symbol. Default False.

featureCount(self, legendKey: str | None) int

Returns the feature count for a particular legendKey. If the key has not been found, -1 will be returned.

Parameters:

legendKey (Optional[str])

Return type:

int

featureIds(self, symbolkey: str | None) Any[source]

Returns the feature Ids for a particular legendKey. If the key has not been found an empty QSet will be returned.

Added in version 3.10.

Parameters:

symbolkey (Optional[str])

Return type:

Any

abstract run(self) bool[source]

Calculates the feature count and Ids per symbol

Return type:

bool

signal symbolsCounted[source]

Emitted when the symbols have been counted.