Subgroup: Feature

Class: QgsFeatureSource

class qgis.core.QgsFeatureSource

Bases: sip.wrapper

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

New in version 3.0: Methods

allFeatureIds Returns a list of all feature IDs for features present in the source.
featureCount Returns the number of features contained in the source, or -1 if the feature count is unknown.
fields Returns the fields associated with features in the source.
getFeatures Returns an iterator for the features in the source.
materialize 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.
maximumValue Returns the maximum value for an attribute column or an invalid variant in case of error.
minimumValue Returns the minimum value for an attribute column or an invalid variant in case of error.
sourceCrs Returns the coordinate reference system for features in the source.
sourceExtent Returns the extent of all geometries from the source.
sourceName Returns a friendly display name for the source.
uniqueValues Returns the set of unique values contained within the specified fieldIndex from this source.
wkbType Returns the geometry type for features returned by this source.

Signals

Attributes

allFeatureIds(self) → object

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

featureCount(self) → int

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

fields(self) → QgsFields

Returns the fields associated with features in the source.

getFeatures(self, request: QgsFeatureRequest = QgsFeatureRequest()) → QgsFeatureIterator

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.

materialize(self, request: QgsFeatureRequest, feedback: QgsFeedback = None) → 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. 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.

New in version 3.0.

maximumValue(self, fieldIndex: int) → Any

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()

See also

uniqueValues()

minimumValue(self, fieldIndex: int) → Any

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()

See also

uniqueValues()

sourceCrs(self) → QgsCoordinateReferenceSystem

Returns the coordinate reference system for features in the source.

sourceExtent(self) → QgsRectangle

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.

sourceName(self) → str

Returns a friendly display name for the source. The returned value can be an empty string.

uniqueValues(self, fieldIndex: int, limit: int = -1) → object

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()

See also

maximumValue()

wkbType(self) → QgsWkbTypes.Type

Returns the geometry type for features returned by this source.