QgsFeatureSource class

An interface for objects which provide features via a getFeatures method.

Derived classes

class QgsProcessingFeatureSource
QgsFeatureSource subclass which proxies methods to an underlying QgsFeatureSource, modifying results according to the settings in a QgsProcessingContext.
class QgsVectorDataProvider
This is the base class for vector data providers.
class QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
class QgsVectorLayerSelectedFeatureSource
QgsFeatureSource subclass for the selected features from a QgsVectorLayer.

Public types

enum FeatureAvailability { NoFeaturesAvailable, FeaturesAvailable, FeaturesMaybeAvailable }
Possible return value for hasFeatures() to determine if a source is empty.

Public functions

auto allFeatureIds() const -> QgsFeatureIds virtual
Returns a list of all feature IDs for features present in the source.
auto featureCount() const -> long pure virtual
Returns the number of features contained in the source, or -1 if the feature count is unknown.
auto fields() const -> QgsFields pure virtual
Returns the fields associated with features in the source.
auto getFeatures(const QgsFeatureRequest& request = QgsFeatureRequest()) const -> QgsFeatureIterator pure virtual
Returns an iterator for the features in the source.
auto hasFeatures() const -> FeatureAvailability virtual
Determines if there are any features available in the source.
auto materialize(const QgsFeatureRequest& request, QgsFeedback* feedback = nullptr) -> QgsVectorLayer*
Materializes a request (query) made against this feature source, by running it over the source and returning a new memory based vector layer containing the result.
auto maximumValue(int fieldIndex) const -> QVariant virtual
Returns the maximum value for an attribute column or an invalid variant in case of error.
auto minimumValue(int fieldIndex) const -> QVariant virtual
Returns the minimum value for an attribute column or an invalid variant in case of error.
auto sourceCrs() const -> QgsCoordinateReferenceSystem pure virtual
Returns the coordinate reference system for features in the source.
auto sourceExtent() const -> QgsRectangle virtual
Returns the extent of all geometries from the source.
auto sourceName() const -> QString pure virtual
Returns a friendly display name for the source.
auto uniqueValues(int fieldIndex, int limit = -1) const -> QSet<QVariant> virtual
Returns the set of unique values contained within the specified fieldIndex from this source.
auto wkbType() const -> QgsWkbTypes::Type pure virtual
Returns the geometry type for features returned by this source.

Enum documentation

enum QgsFeatureSource::FeatureAvailability

Possible return value for hasFeatures() to determine if a source is empty.

It is implemented as a three-value logic, so it can return if there are features available for sure, if there are no features available for sure or if there might be features available but there is no guarantee for this.

Enumerators
NoFeaturesAvailable

There are certainly no features available in this source.

FeaturesAvailable

There is at least one feature available in this source.

FeaturesMaybeAvailable

There may be features available in this source.

Function documentation

QgsFeatureIterator QgsFeatureSource::getFeatures(const QgsFeatureRequest& request = QgsFeatureRequest()) const pure virtual

Returns an iterator for the features in the source.

An optional request can be used to optimise the returned iterator, eg by restricting the returned attributes or geometry.

FeatureAvailability QgsFeatureSource::hasFeatures() const virtual

Determines if there are any features available in the source.

QgsVectorLayer* QgsFeatureSource::materialize(const QgsFeatureRequest& request, QgsFeedback* feedback = nullptr)

Materializes a request (query) made against this feature source, by running it over the source and returning a new memory based vector layer containing the result.

All settings from feature request will be honored.

If a subset of attributes has been set for the request, then only those selected fields will be present in the output layer.

The CRS for the output layer will match the input layer, unless QgsFeatureRequest::setDestinationCrs() has been called with a valid QgsCoordinateReferenceSystem. In this case the output layer will match the QgsFeatureRequest::destinationCrs() CRS.

The returned layer WKB type will match wkbType(), unless the QgsFeatureRequest::NoGeometry flag is set on the request. In that case the returned layer will not be a spatial layer.

An optional feedback argument can be used to cancel the materialization before it has fully completed.

The returned value is a new instance and the caller takes responsibility for its ownership.

QVariant QgsFeatureSource::maximumValue(int fieldIndex) const virtual

Returns the maximum value for an attribute column or an invalid variant in case of error.

The base class implementation uses a non-optimised approach of looping through all features in the source.

QVariant QgsFeatureSource::minimumValue(int fieldIndex) const virtual

Returns the minimum value for an attribute column or an invalid variant in case of error.

The base class implementation uses a non-optimised approach of looping through all features in the source.

QgsRectangle QgsFeatureSource::sourceExtent() const virtual

Returns the extent of all geometries from the source.

The base class implementation uses a non-optimised approach of looping through all features in the source.

QString QgsFeatureSource::sourceName() const pure virtual

Returns a friendly display name for the source.

The returned value can be an empty string.

QSet<QVariant> QgsFeatureSource::uniqueValues(int fieldIndex, int limit = -1) const virtual

Returns the set of unique values contained within the specified fieldIndex from this source.

If specified, the limit option can be used to limit the number of returned values. The base class implementation uses a non-optimised approach of looping through all features in the source.