QGIS API Documentation  3.4.15-Madeira (e83d02e274)
Public Types | Public Member Functions | List of all members
QgsFeatureSource Class Referenceabstract

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

#include <qgsfeaturesource.h>

Inheritance diagram for QgsFeatureSource:
Inheritance graph
[legend]

Public Types

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

Public Member Functions

virtual ~QgsFeatureSource ()=default
 
virtual QgsFeatureIds allFeatureIds () const
 Returns a list of all feature IDs for features present in the source. More...
 
virtual long featureCount () const =0
 Returns the number of features contained in the source, or -1 if the feature count is unknown. More...
 
virtual QgsFields fields () const =0
 Returns the fields associated with features in the source. More...
 
virtual QgsFeatureIterator getFeatures (const QgsFeatureRequest &request=QgsFeatureRequest()) const =0
 Returns an iterator for the features in the source. More...
 
virtual FeatureAvailability hasFeatures () const
 Determines if there are any features available in the source. More...
 
QgsVectorLayermaterialize (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. More...
 
virtual QVariant maximumValue (int fieldIndex) const
 Returns the maximum value for an attribute column or an invalid variant in case of error. More...
 
virtual QVariant minimumValue (int fieldIndex) const
 Returns the minimum value for an attribute column or an invalid variant in case of error. More...
 
virtual QgsCoordinateReferenceSystem sourceCrs () const =0
 Returns the coordinate reference system for features in the source. More...
 
virtual QgsRectangle sourceExtent () const
 Returns the extent of all geometries from the source. More...
 
virtual QString sourceName () const =0
 Returns a friendly display name for the source. More...
 
virtual QSet< QVariant > uniqueValues (int fieldIndex, int limit=-1) const
 Returns the set of unique values contained within the specified fieldIndex from this source. More...
 
virtual QgsWkbTypes::Type wkbType () const =0
 Returns the geometry type for features returned by this source. More...
 

Detailed Description

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

Since
QGIS 3.0

Definition at line 37 of file qgsfeaturesource.h.

Member Enumeration Documentation

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.

Since
QGIS 3.4
Enumerator
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.

Definition at line 50 of file qgsfeaturesource.h.

Constructor & Destructor Documentation

virtual QgsFeatureSource::~QgsFeatureSource ( )
virtualdefault

Member Function Documentation

QgsFeatureIds QgsFeatureSource::allFeatureIds ( ) const
virtual

Returns a list of all feature IDs for features present in the source.

Reimplemented in QgsProcessingFeatureSource.

Definition at line 115 of file qgsfeaturesource.cpp.

virtual long QgsFeatureSource::featureCount ( ) const
pure virtual

Returns the number of features contained in the source, or -1 if the feature count is unknown.

Implemented in QgsVectorLayer, QgsProcessingFeatureSource, QgsVectorLayerSelectedFeatureSource, and QgsVectorDataProvider.

virtual QgsFields QgsFeatureSource::fields ( ) const
pure virtual

Returns the fields associated with features in the source.

Implemented in QgsVectorLayer, QgsProcessingFeatureSource, QgsVectorLayerSelectedFeatureSource, and QgsVectorDataProvider.

virtual 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.

Implemented in QgsVectorLayer, QgsProcessingFeatureSource, QgsVectorLayerSelectedFeatureSource, and QgsVectorDataProvider.

QgsFeatureSource::FeatureAvailability QgsFeatureSource::hasFeatures ( ) const
virtual

Determines if there are any features available in the source.

Since
QGIS 3.2

Reimplemented in QgsVectorLayer, QgsProcessingFeatureSource, and QgsVectorDataProvider.

Definition at line 26 of file qgsfeaturesource.cpp.

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.

Since
QGIS 3.0

Definition at line 132 of file qgsfeaturesource.cpp.

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.

See also
minimumValue()
uniqueValues()

Reimplemented in QgsVectorLayer, QgsProcessingFeatureSource, and QgsVectorDataProvider.

Definition at line 75 of file qgsfeaturesource.cpp.

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.

See also
maximumValue()
uniqueValues()

Reimplemented in QgsVectorLayer, QgsProcessingFeatureSource, and QgsVectorDataProvider.

Definition at line 52 of file qgsfeaturesource.cpp.

virtual QgsCoordinateReferenceSystem QgsFeatureSource::sourceCrs ( ) const
pure virtual

Returns the coordinate reference system for features in the source.

Implemented in QgsVectorLayer, QgsProcessingFeatureSource, QgsVectorLayerSelectedFeatureSource, and QgsVectorDataProvider.

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.

Reimplemented in QgsVectorLayer, QgsProcessingFeatureSource, and QgsVectorDataProvider.

Definition at line 98 of file qgsfeaturesource.cpp.

virtual QString QgsFeatureSource::sourceName ( ) const
pure virtual

Returns a friendly display name for the source.

The returned value can be an empty string.

Implemented in QgsVectorLayer, QgsProcessingFeatureSource, QgsVectorLayerSelectedFeatureSource, and QgsVectorDataProvider.

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.

See also
minimumValue()
maximumValue()

Reimplemented in QgsVectorLayer, and QgsProcessingFeatureSource.

Definition at line 31 of file qgsfeaturesource.cpp.

virtual QgsWkbTypes::Type QgsFeatureSource::wkbType ( ) const
pure virtual

Returns the geometry type for features returned by this source.

Implemented in QgsVectorLayer, QgsProcessingFeatureSource, QgsVectorLayerSelectedFeatureSource, and QgsVectorDataProvider.


The documentation for this class was generated from the following files: