Class: QgsFeatureSource¶
- class qgis.core.QgsFeatureSource¶
Bases:
sip.wrapper
An interface for objects which provide features via a getFeatures method.
Enums
Bases:
enum.IntEnum
Bases:
enum.IntEnum
Methods
Returns a list of all feature IDs for features present in the source.
Returns the number of features contained in the source, or -1 if the feature count is unknown.
Returns the fields associated with features in the source.
Returns an iterator for the features in the source.
Determines if there are any features available in the source.
Returns an enum value representing the presence of a valid spatial index on the source, if it can be determined.
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.Returns the maximum value for an attribute column or an invalid variant in case of error.
Returns the minimum value for an attribute column or an invalid variant in case of error.
Returns the coordinate reference system for features in the source.
Returns the extent of all geometries from the source.
Returns the 3D extent of all geometries from the source.
Returns a friendly display name for the source.
Returns the set of unique values contained within the specified
fieldIndex
from this source.Returns the geometry type for features returned by this source.
- class FeatureAvailability(value)¶
Bases:
enum.IntEnum
Possible return value for
QgsFeatureSource.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.
Note
Prior to QGIS 3.36 this was available as
QgsFeatureSource
.FeatureAvailabilityNew in version 3.36.
NoFeaturesAvailable
: There are certainly no features available in this sourceFeaturesAvailable
: There is at least one feature available in this sourceFeaturesMaybeAvailable
: There may be features available in this source
- class SpatialIndexPresence(value)¶
Bases:
enum.IntEnum
Enumeration of spatial index presence states.
Note
Prior to QGIS 3.36 this was available as
QgsFeatureSource
.SpatialIndexPresenceNew in version 3.36.
SpatialIndexUnknown
: Spatial index presence cannot be determined, index may or may not existSpatialIndexNotPresent
: No spatial index exists for the sourceSpatialIndexPresent
: A valid spatial index exists for the source
- allFeatureIds(self) object ¶
Returns a list of all feature IDs for features present in the source.
- Return type:
object
- featureCount(self) int ¶
Returns the number of features contained in the source, or -1 if the feature count is unknown.
- Return type:
int
- 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.- Parameters:
request (
QgsFeatureRequest
= QgsFeatureRequest()) –- Return type:
- hasFeatures(self) Qgis.FeatureAvailability ¶
Determines if there are any features available in the source.
New in version 3.2.
- Return type:
- hasSpatialIndex(self) Qgis.SpatialIndexPresence ¶
Returns an enum value representing the presence of a valid spatial index on the source, if it can be determined.
If QgsFeatureSource.SpatialIndexUnknown is returned then the presence of an index cannot be determined.
New in version 3.10.1.
- Return type:
- 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 featurerequest
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 validQgsCoordinateReferenceSystem
. In this case the output layer will match theQgsFeatureRequest.destinationCrs()
CRS.The returned layer WKB type will match
wkbType()
, unless theQgsFeatureRequest
.NoGeometry flag is set on therequest
. 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.
- Parameters:
request (QgsFeatureRequest) –
feedback (
QgsFeedback
= None) –
- Return type:
- 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
See also
- Parameters:
fieldIndex (int) –
- Return type:
Any
- 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
See also
- Parameters:
fieldIndex (int) –
- Return type:
Any
- sourceCrs(self) QgsCoordinateReferenceSystem ¶
Returns the coordinate reference system for features in the source.
- Return type:
- 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.
- Return type:
- sourceExtent3D(self) QgsBox3D ¶
Returns the 3D extent of all geometries from the source. The base class implementation uses a non-optimised approach of looping through all features in the source.
New in version 3.36.
- Return type:
- sourceName(self) str ¶
Returns a friendly display name for the source. The returned value can be an empty string.
- Return type:
str
- uniqueValues(self, fieldIndex: int, limit: int = -1) Set[Any] ¶
Returns the set of unique values contained within the specified
fieldIndex
from this source. If specified, thelimit
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
See also
- Parameters:
fieldIndex (int) –
limit (int = -1) –
- Return type:
Set[Any]
- wkbType(self) Qgis.WkbType ¶
Returns the geometry type for features returned by this source.
- Return type: