Class: QgsAbstractFeatureIterator

Internal feature iterator to be implemented within data providers.

Note

This is an abstract class, with methods which must be implemented by a subclass.

The following methods must be implemented: close(), fetchFeature(), rewind()

Class Hierarchy

Inheritance diagram of qgis.core.QgsAbstractFeatureIterator

Subclasses

QgsAbstractFeatureIteratorFromSourceQgsVectorLayerFeatureSourceBase

Helper template that cares of two things: 1. automatic deletion of source if owned by iterator, 2. notification of open/closed iterator.

QgsCachedFeatureIterator

Delivers features from the cache.

QgsCachedFeatureWriterIterator

Uses another iterator as backend and writes features to the cache.

Enums

RequestToSourceCrsResult

Possible results from the updateRequestToSourceCrs() method.

Abstract Methods

close

Call to end the iteration.

fetchFeature

If you write a feature iterator for your provider, this is the method you need to implement!!

rewind

Resets the iterator to the starting position.

Methods

compileFailed

Indicator if there was an error when sending the compiled query to the server.

compileStatus

Returns the status of expression compilation for filter expression requests.

deref

Remove reference, delete if refs == 0

filterRectToSourceCrs

Returns a rectangle representing the original request's QgsFeatureRequest.filterRect().

geometryToDestinationCrs

Transforms feature's geometry according to the specified coordinate transform.

ref

Add reference

updateRequestToSourceCrs

Update a QgsFeatureRequest so that spatial filters are transformed to the source's coordinate reference system.

Virtual Methods

In PyQGIS, only methods marked as virtual can be safely overridden in a Python subclass of QgsAbstractFeatureIterator. See the FAQ for more details.

isValid

Returns if this iterator is valid.

nextFeature

Fetch next feature and stores in f, returns True on success.

nextFeatureFilterExpression

By default, the iterator will fetch all features and check if the feature matches the expression.

nextFeatureFilterFids

By default, the iterator will fetch all features and check if the id is in the request.

prepareSimplification

Setup the simplification of geometries to fetch using the specified simplify method

Attributes

Compiled

NoCompilation

PartiallyCompiled

class qgis.core.QgsAbstractFeatureIterator[source]

Bases: object

__init__(request: QgsFeatureRequest)

base class constructor - stores the iteration parameters

Parameters:

request (QgsFeatureRequest)

__init__(a0: QgsAbstractFeatureIterator)
Parameters:

a0 (QgsAbstractFeatureIterator)

class CompileStatus

Bases: int

Compiled = 2
NoCompilation = 0
PartiallyCompiled = 1
class RequestToSourceCrsResult(*values)

Bases: IntEnum

Possible results from the updateRequestToSourceCrs() method.

Added in version 3.22.

  • Success: Request was successfully updated to the source CRS, or no changes were required

  • DistanceWithinMustBeCheckedManually: The distance within request cannot be losslessly updated to the source CRS, and callers will need to take appropriate steps to handle the distance within requirement manually during feature iteration

DistanceWithinMustBeCheckedManually = 1
Success = 0
abstract close(self) bool[source]

Call to end the iteration. This frees any resources used by the iterator.

Return type:

bool

compileFailed(self) bool[source]

Indicator if there was an error when sending the compiled query to the server. This indicates that there is something wrong with the expression compiler.

Added in version 3.2.

Return type:

bool

compileStatus(self) QgsAbstractFeatureIterator.CompileStatus[source]

Returns the status of expression compilation for filter expression requests.

Return type:

QgsAbstractFeatureIterator.CompileStatus

deref(self)[source]

Remove reference, delete if refs == 0

abstract fetchFeature(self, f: QgsFeature) bool[source]

If you write a feature iterator for your provider, this is the method you need to implement!!

Parameters:

f (QgsFeature) – The feature to write to

Return type:

bool

Returns:

True if a feature was written to f

filterRectToSourceCrs(self, transform: QgsCoordinateTransform) QgsRectangle[source]

Returns a rectangle representing the original request’s QgsFeatureRequest.filterRect(). If transform is a valid coordinate transform, the return rectangle will represent the requested filterRect() transformed to the source’s coordinate reference system. Iterators should call this method and use the returned rectangle for filtering features to ensure that any QgsFeatureRequest.destinationCrs() set on the request is respected. Will throw a QgsCsException if the rect cannot be transformed from the destination CRS.

Parameters:

transform (QgsCoordinateTransform)

Return type:

QgsRectangle

geometryToDestinationCrs(self, feature: QgsFeature, transform: QgsCoordinateTransform)[source]

Transforms feature’s geometry according to the specified coordinate transform. If feature has no geometry or transform is invalid then calling this method has no effect and will be shortcut. Iterators should call this method before returning features to ensure that any QgsFeatureRequest.destinationCrs() set on the request is respected.

Parameters:
virtual isValid(self) bool[source]

Returns if this iterator is valid. An invalid feature iterator is not able to provide a reliable source for data. If an iterator is invalid, either give up or try to send the request again (preferably after a timeout to give the system some time to stay responsive).

If you want to check if the iterator successfully completed, better use QgsFeatureIterator.isClosed().

Return type:

bool

virtual nextFeature(self, f: QgsFeature) bool[source]

Fetch next feature and stores in f, returns True on success.

Parameters:

f (QgsFeature)

Return type:

bool

virtual nextFeatureFilterExpression(self, f: QgsFeature) bool[source]

By default, the iterator will fetch all features and check if the feature matches the expression. If you have a more sophisticated metodology (SQL request for the features…) and you check for the expression in your fetchFeature method, you can just redirect this call to fetchFeature so the default check will be omitted.

Parameters:

f (QgsFeature) – The feature to write to

Return type:

bool

Returns:

True if a feature was written to f

virtual nextFeatureFilterFids(self, f: QgsFeature) bool[source]

By default, the iterator will fetch all features and check if the id is in the request. If you have a more sophisticated metodology (SQL request for the features…) and you are sure, that any feature you return from fetchFeature will match if the request was FilterFids you can just redirect this call to fetchFeature so the default check will be omitted.

Parameters:

f (QgsFeature) – The feature to write to

Return type:

bool

Returns:

True if a feature was written to f

virtual prepareSimplification(self, simplifyMethod: QgsSimplifyMethod) bool[source]

Setup the simplification of geometries to fetch using the specified simplify method

Parameters:

simplifyMethod (QgsSimplifyMethod)

Return type:

bool

ref(self)[source]

Add reference

abstract rewind(self) bool[source]

Resets the iterator to the starting position.

Return type:

bool

updateRequestToSourceCrs(self, request: QgsFeatureRequest, transform: QgsCoordinateTransform) QgsAbstractFeatureIterator.RequestToSourceCrsResult[source]

Update a QgsFeatureRequest so that spatial filters are transformed to the source’s coordinate reference system. Iterators should call this method against the request used for filtering features to ensure that any QgsFeatureRequest.destinationCrs() set on the request is respected.

Return type:

QgsAbstractFeatureIterator.RequestToSourceCrsResult

Returns:

result of operation. See QgsAbstractFeatureIterator.RequestToSourceCrsResult for interpretation.

Raises:

QgsCsException – if the rect cannot be transformed from the destination CRS.

Added in version 3.22.

Parameters: