Class: QgsAbstractFeatureIterator¶
- class qgis.core.QgsAbstractFeatureIterator¶
Bases:
sip.wrapper
Internal feature iterator to be implemented within data providers
QgsAbstractFeatureIterator(request:
QgsFeatureRequest
) base class constructor - stores the iteration parametersQgsAbstractFeatureIterator(
QgsAbstractFeatureIterator
)Enums
Bases:
enum.IntEnum
Methods
end of iterating: free the resources / lock
Indicator if there was an error when sending the compiled query to the server.
Returns the status of expression compilation for filter expression requests.
Remove reference, delete if refs == 0
If you write a feature iterator for your provider, this is the method you need to implement!!
Returns a rectangle representing the original request's
QgsFeatureRequest.filterRect()
.Transforms
feature
's geometry according to the specified coordinatetransform
.Returns if this iterator is valid.
fetch next feature, return
True
on successBy default, the iterator will fetch all features and check if the feature matches the expression.
By default, the iterator will fetch all features and check if the id is in the request.
Setup the simplification of geometries to fetch using the specified simplify method
Add reference
reset the iterator to the starting position
Update a
QgsFeatureRequest
so that spatial filters are transformed to the source's coordinate reference system.Attributes
- class CompileStatus¶
Bases:
int
- Compiled = 2¶
- NoCompilation = 0¶
- PartiallyCompiled = 1¶
- class RequestToSourceCrsResult(value)¶
Bases:
enum.IntEnum
Possible results from the
updateRequestToSourceCrs()
method.New in version 3.22.
Success
: Request was successfully updated to the source CRS, or no changes were requiredDistanceWithinMustBeCheckedManually
: 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¶
- close(self) bool ¶
end of iterating: free the resources / lock
- Return type:
bool
- compileFailed(self) bool ¶
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.
New in version 3.2.
- Return type:
bool
- compileStatus(self) QgsAbstractFeatureIterator.CompileStatus ¶
Returns the status of expression compilation for filter expression requests.
New in version 2.16.
- Return type:
- deref(self)¶
Remove reference, delete if refs == 0
- fetchFeature(self, f: QgsFeature) bool ¶
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 ¶
Returns a rectangle representing the original request’s
QgsFeatureRequest.filterRect()
. Iftransform
is a valid coordinate transform, the return rectangle will represent the requestedfilterRect()
transformed to the source’s coordinate reference system. Iterators should call this method and use the returned rectangle for filtering features to ensure that anyQgsFeatureRequest.destinationCrs()
set on the request is respected. Will throw aQgsCsException
if the rect cannot be transformed from the destination CRS.New in version 3.0.
- Parameters:
transform (QgsCoordinateTransform) –
- Return type:
- geometryToDestinationCrs(self, feature: QgsFeature, transform: QgsCoordinateTransform)¶
Transforms
feature
’s geometry according to the specified coordinatetransform
. Iffeature
has no geometry ortransform
is invalid then calling this method has no effect and will be shortcut. Iterators should call this method before returning features to ensure that anyQgsFeatureRequest.destinationCrs()
set on the request is respected.New in version 3.0.
- Parameters:
feature (QgsFeature) –
transform (QgsCoordinateTransform) –
- isValid(self) bool ¶
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()
.New in version 3.0.
- Return type:
bool
- nextFeature(self, f: QgsFeature) bool ¶
fetch next feature, return
True
on success- Parameters:
f (QgsFeature) –
- Return type:
bool
- nextFeatureFilterExpression(self, f: QgsFeature) bool ¶
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
- nextFeatureFilterFids(self, f: QgsFeature) bool ¶
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
- prepareSimplification(self, simplifyMethod: QgsSimplifyMethod) bool ¶
Setup the simplification of geometries to fetch using the specified simplify method
- Parameters:
simplifyMethod (QgsSimplifyMethod) –
- Return type:
bool
- ref(self)¶
Add reference
- rewind(self) bool ¶
reset the iterator to the starting position
- Return type:
bool
- updateRequestToSourceCrs(self, request: QgsFeatureRequest, transform: QgsCoordinateTransform) QgsAbstractFeatureIterator.RequestToSourceCrsResult ¶
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 anyQgsFeatureRequest.destinationCrs()
set on the request is respected.- Return type:
- Returns:
result of operation. See QgsAbstractFeatureIterator.RequestToSourceCrsResult for interpretation.
- Raises:
QgsCsException – if the rect cannot be transformed from the destination CRS.
New in version 3.22.
- Parameters:
request (QgsFeatureRequest) –
transform (QgsCoordinateTransform) –