Class: QgsFeatureRequest

class qgis.core.QgsFeatureRequest

Bases: sip.wrapper

This class wraps a request for features to a vector layer (or directly its vector data provider).

The request may apply an attribute/ID filter to fetch only a particular subset of features. Currently supported filters:

  • no filter - all features are returned

  • feature id - only feature that matches given feature id is returned

  • feature ids - only features that match any of the given feature ids are returned

  • filter expression - only features that match the given filter expression are returned

Additionally a spatial filter can be set in combination with the attribute/ID filter. Supported spatial filters are:

  • Qgis.SpatialFilterType.BoundingBox: Only features that intersect a given rectangle will be fetched. For the sake of speed, the intersection is often done only using feature’s bounding box. There is a flag ExactIntersect that makes sure that only intersecting features will be returned.

  • Qgis.SpatialFilterType.DistanceWithin: Only features within a specified distance of a reference geometry will be fetched.

For efficiency, it is also possible to tell provider that some data is not required:

  • NoGeometry flag

  • SubsetOfAttributes flag

  • SimplifyMethod for geometries to fetch

The options may be chained, e.g.:

QgsFeatureRequest().setFilterRect(QgsRectangle(0,0,1,1)).setFlags(QgsFeatureRequest.ExactIntersect)

Examples:

# fetch all features:
QgsFeatureRequest()
# fetch all features, only one attribute
QgsFeatureRequest().setSubsetOfAttributes(['myfield'], layer.fields())
# fetch all features, without geometries
QgsFeatureRequest().setFlags(QgsFeatureRequest.NoGeometry)
# fetch only features from particular extent
QgsFeatureRequest().setFilterRect(QgsRectangle(0,0,1,1))
# fetch only features from particular extent, where the 'type' attribute is equal to 'road':
QgsFeatureRequest().setFilterRect(QgsRectangle(0,0,1,1)).setFilterExpression('"type"=\'road\'')
# fetch only one feature
QgsFeatureRequest().setFilterFid(45)
# fetch features within 50 map units of a linestring geometry
QgsFeatureRequest().setDistanceWithin(QgsGeometry.fromWkt('LineString(0 0, 10 0, 12 1)'), 50)

QgsFeatureRequest() construct a default request: for all features get attributes and geometries

QgsFeatureRequest(fid: int) construct a request with feature ID filter

QgsFeatureRequest(fids: object) construct a request with feature ID filter

QgsFeatureRequest(rectangle: QgsRectangle) Construct a request with rectangle bounding box filter.

When a destination CRS is set using setDestinationCrs(), rectangle is expected to be in the same CRS as the destinationCrs(). Otherwise, rectangle should use the same CRS as the source layer/provider.

QgsFeatureRequest(expr: QgsExpression, context: QgsExpressionContext = QgsExpressionContext()) construct a request with a filter expression

QgsFeatureRequest(rh: QgsFeatureRequest) copy constructor

Enums

FilterType

alias of FeatureRequestFilterType

Flag

alias of FeatureRequestFlag

InvalidGeometryCheck

Bases: enum.IntEnum

Methods

acceptFeature

Check if a feature is accepted by this requests filter

addOrderBy

Adds a new OrderByClause, appending it as the least important one.

combineFilterExpression

Modifies the existing filter expression to add an additional expression filter.

connectionTimeout

Returns the timeout (in milliseconds) for how long we should wait for a connection if none is available from the pool at this moment.

destinationCrs

Returns the destination coordinate reference system for feature's geometries, or an invalid QgsCoordinateReferenceSystem if no reprojection will be done and all features will be left with their original geometry.

disableFilter

Disables any attribute/ID filtering.

distanceWithin

Returns the maximum distance from the referenceGeometry() of fetched features, if spatialFilterType() is Qgis.SpatialFilterType.DistanceWithin.

expressionContext

Returns the expression context used to evaluate filter expressions.

feedback

Returns the feedback object that can be queried regularly by the iterator to check if it should be canceled, if set.

filterExpression

Returns the filter expression (if set).

filterFid

Returns the feature ID that should be fetched.

filterFids

Returns the feature IDs that should be fetched.

filterRect

Returns the rectangle from which features will be taken.

filterType

Returns the attribute/ID filter type which is currently set on this request.

flags

Returns the flags which affect how features are fetched.

invalidGeometryCheck

Returns the invalid geometry checking behavior.

limit

Returns the maximum number of features to request, or -1 if no limit set.

orderBy

Returns a list of order by clauses specified for this feature request.

referenceGeometry

Returns the reference geometry used for spatial filtering of features.

requestMayBeNested

In case this request may be run nested within another already running iteration on the same connection, set this to True.

setConnectionTimeout

Sets the timeout (in milliseconds) for how long we should wait for a connection if none is available from the pool at this moment.

setDestinationCrs

Sets the destination crs for feature's geometries.

setDistanceWithin

Sets a reference geometry and a maximum distance from this geometry to retrieve features within.

setExpressionContext

Sets the expression context used to evaluate filter expressions.

setFeedback

Attach a feedback object that can be queried regularly by the iterator to check if it should be canceled.

setFilterExpression

Set the filter expression.

setFilterFid

Sets the feature ID that should be fetched.

setFilterFids

Sets the feature IDs that should be fetched.

setFilterRect

Sets the rectangle from which features will be taken.

setFlags

Sets flags that affect how features will be fetched.

setInvalidGeometryCallback

Sets a callback function to use when encountering an invalid geometry and invalidGeometryCheck() is set to GeometryAbortOnInvalid or GeometrySkipInvalid.

setInvalidGeometryCheck

Sets invalid geometry checking behavior.

setLimit

Set the maximum number of features to request.

setNoAttributes

Set that no attributes will be fetched.

setOrderBy

Set a list of order by clauses.

setRequestMayBeNested

In case this request may be run nested within another already running iteration on the same connection, set this to True.

setSimplifyMethod

Set a simplification method for geometries that will be fetched.

setSubsetOfAttributes

Set a subset of attributes that will be fetched.

setTimeout

Sets the timeout (in milliseconds) for the maximum time we should wait during feature requests before a feature is returned.

setTransformErrorCallback

Sets a callback function to use when encountering a transform error when iterating features and a destinationCrs() is set.

simplifyMethod

Returns the simplification method for geometries that will be fetched.

spatialFilterType

Returns the spatial filter type which is currently set on this request.

subsetOfAttributes

Returns the subset of attributes which at least need to be fetched.

timeout

Returns the timeout (in milliseconds) for the maximum time we should wait during feature requests before a feature is returned.

transformContext

Returns the transform context, for use when a destinationCrs() has been set and reprojection is required

Attributes

ALL_ATTRIBUTES

ALL_ATTRIBUTES = '#!allattributes!#'
FilterType

alias of FeatureRequestFilterType

Flag

alias of FeatureRequestFlag

Flags

alias of FeatureRequestFlags

class InvalidGeometryCheck(value)

Bases: enum.IntEnum

Methods for handling of features with invalid geometries

Note

Prior to QGIS 3.36 this was available as QgsFeatureRequest.InvalidGeometryCheck

New in version 3.36.

  • GeometryNoCheck: No invalid geometry checking

  • GeometrySkipInvalid: Skip any features with invalid geometry. This requires a slow geometry validity check for every feature.

  • GeometryAbortOnInvalid: Close iterator on encountering any features with invalid geometry. This requires a slow geometry validity check for every feature.

baseClass

alias of Qgis

class OrderBy

Bases: sip.wrapper

Represents a list of OrderByClauses, with the most important first and the least important last.

QgsFeatureRequest.OrderBy() Create a new empty order by

QgsFeatureRequest.OrderBy(other: Iterable[QgsFeatureRequest.OrderByClause]) Create a new order by from a list of clauses

QgsFeatureRequest.OrderBy(QgsFeatureRequest.OrderBy)

dump(self) str

Dumps the content to an SQL equivalent syntax

Return type:

str

list(self) List[QgsFeatureRequest.OrderByClause]

Gets a copy as a list of OrderByClauses

This is only required in Python where the inheritance is not properly propagated and this makes it usable.

Return type:

List[QgsFeatureRequest.OrderByClause]

load(self, elem: QDomElement)

Deserialize from XML

Parameters:

elem (QDomElement) –

save(self, elem: QDomElement)

Serialize to XML

Parameters:

elem (QDomElement) –

usedAttributeIndices(self, fields: QgsFields) object

Returns a set of used, validated attribute indices

New in version 3.8.

Parameters:

fields (QgsFields) –

Return type:

object

usedAttributes(self) Set[str]

Returns a set of used attributes

Note

The returned attributes names are NOT guaranteed to be valid.

Return type:

Set[str]

class OrderByClause

Bases: sip.wrapper

The OrderByClause class represents an order by clause for a QgsFeatureRequest.

It can be a simple field or an expression. Multiple order by clauses can be added to a QgsFeatureRequest to fine tune the behavior if a single field or expression is not enough to completely specify the required behavior.

If expression compilation is activated in the settings and the expression can be translated for the provider in question, it will be evaluated on provider side. If one of these two premises does not apply, the ordering will take place locally which results in increased memory and CPU usage.

If the ordering is done on strings, the order depends on the system’s locale if the local fallback implementation is used. The order depends on the server system’s locale and implementation if ordering is done on the server.

In case the fallback code needs to be used, a limit set on the request will be respected for the features returned by the iterator but internally all features will be requested from the provider.

QgsFeatureRequest.OrderByClause(expression: str, ascending: bool = True) Creates a new OrderByClause for a QgsFeatureRequest

Parameters:
  • expression – The expression to use for ordering

  • ascending – If the order should be ascending (1,2,3) or descending (3,2,1) If the order is ascending, by default nulls are last If the order is descending, by default nulls are first

QgsFeatureRequest.OrderByClause(expression: str, ascending: bool, nullsfirst: bool) Creates a new OrderByClause for a QgsFeatureRequest

Parameters:
  • expression – The expression to use for ordering

  • ascending – If the order should be ascending (1,2,3) or descending (3,2,1)

  • nullsfirst – If True, NULLS are at the beginning, if False, NULLS are at the end

QgsFeatureRequest.OrderByClause(expression: QgsExpression, ascending: bool = True) Creates a new OrderByClause for a QgsFeatureRequest

Parameters:
  • expression – The expression to use for ordering

  • ascending – If the order should be ascending (1,2,3) or descending (3,2,1) If the order is ascending, by default nulls are last If the order is descending, by default nulls are first

QgsFeatureRequest.OrderByClause(expression: QgsExpression, ascending: bool, nullsfirst: bool) Creates a new OrderByClause for a QgsFeatureRequest

Parameters:
  • expression – The expression to use for ordering

  • ascending – If the order should be ascending (1,2,3) or descending (3,2,1)

  • nullsfirst – If True, NULLS are at the beginning, if False, NULLS are at the end

QgsFeatureRequest.OrderByClause(QgsFeatureRequest.OrderByClause)

ascending(self) bool

Order ascending

Return type:

bool

Returns:

If ascending order is requested

dump(self) str

Dumps the content to an SQL equivalent

Return type:

str

expression(self) QgsExpression

The expression

Return type:

QgsExpression

Returns:

the expression

nullsFirst(self) bool

Set if NULLS should be returned first

Return type:

bool

Returns:

if NULLS should be returned first

prepare(self, context: QgsExpressionContext) bool

Prepare the expression with the given context.

Parameters:

context (QgsExpressionContext) –

Return type:

bool

setAscending(self, ascending: bool)

Set if ascending order is requested

Parameters:

ascending (bool) –

setNullsFirst(self, nullsFirst: bool)

Set if NULLS should be returned first

Parameters:

nullsFirst (bool) –

acceptFeature(self, feature: QgsFeature) bool

Check if a feature is accepted by this requests filter

Parameters:

feature (QgsFeature) – The feature which will be tested

Return type:

bool

Returns:

True, if the filter accepts the feature

addOrderBy(self, expression: str, ascending: bool = True) QgsFeatureRequest

Adds a new OrderByClause, appending it as the least important one.

Parameters:
  • expression (str) – The expression to use for ordering

  • ascending (bool = True) – If the order should be ascending (1,2,3) or descending (3,2,1) If the order is ascending, by default nulls are last If the order is descending, by default nulls are first

addOrderBy(self, expression: str, ascending: bool, nullsfirst: bool) -> QgsFeatureRequest Adds a new OrderByClause, appending it as the least important one.

Parameters:
  • expression – The expression to use for ordering

  • ascending – If the order should be ascending (1,2,3) or descending (3,2,1)

  • nullsfirst – If True, NULLS are at the beginning, if False, NULLS are at the end

Return type:

QgsFeatureRequest

combineFilterExpression(self, expression: str) QgsFeatureRequest

Modifies the existing filter expression to add an additional expression filter. The filter expressions are combined using AND, so only features matching both the existing expression and the additional expression will be returned.

Calling this method will automatically set filterType() to QgsFeatureRequest.FilterExpression.

Parameters:

expression (str) –

Return type:

QgsFeatureRequest

connectionTimeout(self) int

Returns the timeout (in milliseconds) for how long we should wait for a connection if none is available from the pool at this moment. A negative value (which is set by default) will wait forever.

Note

Only works if the provider supports this option.

Deprecated since version Use: timeout() instead.

Return type:

int

destinationCrs(self) QgsCoordinateReferenceSystem

Returns the destination coordinate reference system for feature’s geometries, or an invalid QgsCoordinateReferenceSystem if no reprojection will be done and all features will be left with their original geometry.

Return type:

QgsCoordinateReferenceSystem

disableFilter(self) QgsFeatureRequest

Disables any attribute/ID filtering.

Calling this method will automatically set filterType() to QgsFeatureRequest.FilterNone.

Note

Spatial filters will be left in place.

Return type:

QgsFeatureRequest

Returns:

The object the method is called on for chaining

distanceWithin(self) float

Returns the maximum distance from the referenceGeometry() of fetched features, if spatialFilterType() is Qgis.SpatialFilterType.DistanceWithin.

When a destination CRS is set using setDestinationCrs(), the distance will be in the spatial units of destinationCrs(). Otherwise, the distance will use the same units as the CRS of the source layer/provider.

New in version 3.22.

Return type:

float

expressionContext(self) QgsExpressionContext

Returns the expression context used to evaluate filter expressions.

Return type:

QgsExpressionContext

feedback(self) QgsFeedback

Returns the feedback object that can be queried regularly by the iterator to check if it should be canceled, if set.

See also

setFeedback()

New in version 3.20.

Return type:

QgsFeedback

filterExpression(self) QgsExpression

Returns the filter expression (if set).

Return type:

QgsExpression

filterFid(self) int

Returns the feature ID that should be fetched.

See also

setFilterFid()

See also

filterFids()

Return type:

int

filterFids(self) object

Returns the feature IDs that should be fetched.

See also

setFilterFids()

See also

filterFid()

Return type:

object

filterRect(self) QgsRectangle

Returns the rectangle from which features will be taken. If the returned rectangle is null, then no filter rectangle is set.

If spatialFilterType() is Qgis.SpatialFilterType.BoundingBox then only features from within this bounding box will be fetched. If spatialFilterType() is Qgis.SpatialFilterType.DistanceWithin then the returned rectangle represents the bounding box of the referenceGeometry() extended by distanceWithin().

When a destination CRS is set using setDestinationCrs(), the rectangle will be in the same CRS as the destinationCrs(). Otherwise, the rectangle will use the same CRS as the source layer/provider.

See also

setFilterRect()

Return type:

QgsRectangle

filterType(self) Qgis.FeatureRequestFilterType

Returns the attribute/ID filter type which is currently set on this request.

This type will automatically be set to the appropriate value whenever setFilterFid(), setFilterFids(), setFilterExpression() or disableFilter() are called.

Note

A feature request may have both an attribute/ID filter AND a spatial filter set. See spatialFilterType() to retrieve the spatial filter.

Return type:

Qgis.FeatureRequestFilterType

flags(self) Qgis.FeatureRequestFlags

Returns the flags which affect how features are fetched.

See also

setFlags()

Return type:

Qgis.FeatureRequestFlags

invalidGeometryCheck(self) Qgis.InvalidGeometryCheck

Returns the invalid geometry checking behavior.

Return type:

Qgis.InvalidGeometryCheck

limit(self) int

Returns the maximum number of features to request, or -1 if no limit set.

See also

setLimit()

Return type:

int

orderBy(self) QgsFeatureRequest.OrderBy

Returns a list of order by clauses specified for this feature request.

Return type:

QgsFeatureRequest.OrderBy

referenceGeometry(self) QgsGeometry

Returns the reference geometry used for spatial filtering of features.

When spatialFilterType() is Qgis.SpatialFilterType.DistanceWithin then only features within distanceWithin() units of the reference geometry will be fetched.

When a destination CRS is set using setDestinationCrs(), the geometry will be in the same CRS as the destinationCrs(). Otherwise, the geometry will use the same CRS as the source layer/provider.

New in version 3.22.

Return type:

QgsGeometry

requestMayBeNested(self) bool

In case this request may be run nested within another already running iteration on the same connection, set this to True.

If this flag is True, this request will be able to make use of “spare” connections to avoid deadlocks.

For example, this should be set on requests that are issued from an expression function.

New in version 3.4.

Return type:

bool

setConnectionTimeout(self, connectionTimeout: int) QgsFeatureRequest

Sets the timeout (in milliseconds) for how long we should wait for a connection if none is available from the pool at this moment. A negative value (which is set by default) will wait forever.

Note

Only works if the provider supports this option.

Deprecated since version Use: setTimeout() instead.

Parameters:

connectionTimeout (int) –

Return type:

QgsFeatureRequest

setDestinationCrs(self, crs: QgsCoordinateReferenceSystem, context: QgsCoordinateTransformContext) QgsFeatureRequest

Sets the destination crs for feature’s geometries. If set, all geometries will be reprojected from their original coordinate reference system to this desired reference system. If crs is an invalid QgsCoordinateReferenceSystem then no reprojection will be done and all features will be left with their original geometry.

When a crs is set using setDestinationCrs(), then any filterRect() or referenceGeometry() set on the request is expected to be in the same CRS as the destination CRS.

The feature geometry transformation to the destination CRS is performed after all filter expressions are tested and any virtual fields are calculated. Accordingly, any geometric expressions used in filterExpression() will be performed in the original source CRS. This ensures consistent results are returned regardless of the destination CRS. Similarly, virtual field values will be calculated using the original geometry in the source CRS, so these values are not affected by any destination CRS transform present in the feature request.

See also

destinationCrs()

Parameters:
Return type:

QgsFeatureRequest

setDistanceWithin(self, geometry: QgsGeometry, distance: float) QgsFeatureRequest

Sets a reference geometry and a maximum distance from this geometry to retrieve features within.

When a destination CRS is set using setDestinationCrs(), geometry is expected to be in the same CRS as the destinationCrs() and distance is in the spatial units of the destinationCrs(). Otherwise, geometry should use the same CRS as the source layer/provider and distance should use the spatial units as this same CRS.

Calling this method will automatically set spatialFilterType() to Qgis.SpatialFilterType.DistanceWithin.

See also

filterRect()

New in version 3.22.

Parameters:
Return type:

QgsFeatureRequest

setExpressionContext(self, context: QgsExpressionContext) QgsFeatureRequest

Sets the expression context used to evaluate filter expressions.

Parameters:

context (QgsExpressionContext) –

Return type:

QgsFeatureRequest

setFeedback(self, feedback: QgsFeedback)

Attach a feedback object that can be queried regularly by the iterator to check if it should be canceled.

Ownership of feedback is NOT transferred, and the caller must take care that it exists for the lifetime of the feature request and feature iterators.

See also

feedback()

New in version 3.20.

Parameters:

feedback (QgsFeedback) –

setFilterExpression(self, expression: str) QgsFeatureRequest

Set the filter expression. {QgsExpression}

Parameters:

expression (str) – expression string

Calling this method will automatically set filterType() to QgsFeatureRequest.FilterExpression.

Return type:

QgsFeatureRequest

setFilterFid(self, fid: int) QgsFeatureRequest

Sets the feature ID that should be fetched.

Calling this method will automatically set filterType() to QgsFeatureRequest.FilterFid.

See also

filterFid()

See also

setFilterFids()

Parameters:

fid (int) –

Return type:

QgsFeatureRequest

setFilterFids(self, fids: object) QgsFeatureRequest

Sets the feature IDs that should be fetched.

Calling this method will automatically set filterType() to QgsFeatureRequest.FilterFids.

See also

filterFids()

See also

setFilterFid()

Parameters:

fids (object) –

Return type:

QgsFeatureRequest

setFilterRect(self, rectangle: QgsRectangle) QgsFeatureRequest

Sets the rectangle from which features will be taken. An empty rectangle removes the filter.

When a destination CRS is set using setDestinationCrs(), rectangle is expected to be in the same CRS as the destinationCrs(). Otherwise, rectangle should use the same CRS as the source layer/provider.

Calling this method will automatically set spatialFilterType() to Qgis.SpatialFilterType.BoundingBox. If rectangle is a null rectangle then spatialFilterType() will be reset to Qgis.SpatialFilterType.NoFilter.

See also

filterRect()

Parameters:

rectangle (QgsRectangle) –

Return type:

QgsFeatureRequest

setFlags(self, flags: Qgis.FeatureRequestFlags | Qgis.FeatureRequestFlag) QgsFeatureRequest

Sets flags that affect how features will be fetched.

See also

flags()

Parameters:

flags (Union[Qgis.FeatureRequestFlags) –

Return type:

QgsFeatureRequest

setInvalidGeometryCallback(self, Callable[..., None]) QgsFeatureRequest

Sets a callback function to use when encountering an invalid geometry and invalidGeometryCheck() is set to GeometryAbortOnInvalid or GeometrySkipInvalid. This function will be called using the feature with invalid geometry as a parameter.

See also

invalidGeometryCallback()

Return type:

QgsFeatureRequest

setInvalidGeometryCheck(self, check: Qgis.InvalidGeometryCheck) QgsFeatureRequest

Sets invalid geometry checking behavior.

Note

Invalid geometry checking is not performed when retrieving features directly from a QgsVectorDataProvider.

Parameters:

check (Qgis.InvalidGeometryCheck) –

Return type:

QgsFeatureRequest

setLimit(self, limit: int) QgsFeatureRequest

Set the maximum number of features to request.

Parameters:

limit (int) – maximum number of features, or -1 to request all features.

See also

limit()

Return type:

QgsFeatureRequest

setNoAttributes(self) QgsFeatureRequest

Set that no attributes will be fetched.

To revert a call to setNoAttributes and fetch all or some available attributes, the SubsetOfAttributes flag should be removed from the request.

Note

This is intended as hint to data providers for optimising feature retrieval. Depending on the provider, it may be trivial for the provider to always return all attributes instead of removing them. In these cases the provider may ignore this hint and return all attributes regardless of whether this method has been called.

New in version 3.4.

Return type:

QgsFeatureRequest

setOrderBy(self, orderBy: QgsFeatureRequest.OrderBy) QgsFeatureRequest

Set a list of order by clauses.

Parameters:

orderBy (QgsFeatureRequest.OrderBy) –

Return type:

QgsFeatureRequest

setRequestMayBeNested(self, requestMayBeNested: bool) QgsFeatureRequest

In case this request may be run nested within another already running iteration on the same connection, set this to True.

If this flag is True, this request will be able to make use of “spare” connections to avoid deadlocks.

For example, this should be set on requests that are issued from an expression function.

New in version 3.4.

Parameters:

requestMayBeNested (bool) –

Return type:

QgsFeatureRequest

setSimplifyMethod(self, simplifyMethod: QgsSimplifyMethod) QgsFeatureRequest

Set a simplification method for geometries that will be fetched.

See also

simplifyMethod()

Parameters:

simplifyMethod (QgsSimplifyMethod) –

Return type:

QgsFeatureRequest

setSubsetOfAttributes(self, attrs: Iterable[int]) QgsFeatureRequest

Set a subset of attributes that will be fetched.

An empty attributes list indicates that no attributes will be fetched. To revert a call to setSubsetOfAttributes and fetch all available attributes, the SubsetOfAttributes flag should be removed from the request.

Note

This is intended as hint to data providers for optimising feature retrieval. Depending on the provider, it may be trivial for the provider to always return all attributes instead of the requested subset, or actually result in slower retrieval when the attributes are filtered out. In these cases the provider may ignore this hint and return all attributes regardless of the requested attributes.

setSubsetOfAttributes(self, attrNames: Iterable[str], fields: QgsFields) -> QgsFeatureRequest Sets a subset of attributes by names that will be fetched.

Note

This is intended as hint to data providers for optimising feature retrieval. Depending on the provider, it may be trivial for the provider to always return all attributes instead of the requested subset, or actually result in slower retrieval when the attributes are filtered out. In these cases the provider may ignore this hint and return all attributes regardless of the requested attributes.

setSubsetOfAttributes(self, attrNames: Iterable[str], fields: QgsFields) -> QgsFeatureRequest Sets a subset of attributes by names that will be fetched.

Note

This is intended as hint to data providers for optimising feature retrieval. Depending on the provider, it may be trivial for the provider to always return all attributes instead of the requested subset, or actually result in slower retrieval when the attributes are filtered out. In these cases the provider may ignore this hint and return all attributes regardless of the requested attributes.

Parameters:

attrs (Iterable[int]) –

Return type:

QgsFeatureRequest

setTimeout(self, timeout: int) QgsFeatureRequest

Sets the timeout (in milliseconds) for the maximum time we should wait during feature requests before a feature is returned. A negative value (which is set by default) will wait forever.

Note

Only works if the provider supports this option.

See also

timeout()

New in version 3.4.

Parameters:

timeout (int) –

Return type:

QgsFeatureRequest

setTransformErrorCallback(self, Callable[..., None]) QgsFeatureRequest

Sets a callback function to use when encountering a transform error when iterating features and a destinationCrs() is set. This function will be called using the feature which encountered the transform error as a parameter.

See also

transformErrorCallback()

Return type:

QgsFeatureRequest

simplifyMethod(self) QgsSimplifyMethod

Returns the simplification method for geometries that will be fetched.

Return type:

QgsSimplifyMethod

spatialFilterType(self) Qgis.SpatialFilterType

Returns the spatial filter type which is currently set on this request.

This type will automatically be set to the appropriate value whenever setFilterRect(), or setDistanceWithin() are called.

Note

A feature request may have both an attribute/ID filter AND a spatial filter set. See filterType() to retrieve the attribute/ID filter.

See also

filterType()

New in version 3.22.

Return type:

Qgis.SpatialFilterType

subsetOfAttributes(self) List[int]

Returns the subset of attributes which at least need to be fetched.

Return type:

List[int]

Returns:

A list of attributes to be fetched

Note

This is intended as hint to data providers for optimising feature retrieval. Depending on the provider, it may be trivial for the provider to always return all attributes instead of the requested subset, or actually result in slower retrieval when the attributes are filtered out. In these cases the provider may ignore this hint and return all attributes regardless of the requested attributes.

timeout(self) int

Returns the timeout (in milliseconds) for the maximum time we should wait during feature requests before a feature is returned. A negative value (which is set by default) will wait forever.

Note

Only works if the provider supports this option.

See also

setTimeout()

New in version 3.4.

Return type:

int

transformContext(self) QgsCoordinateTransformContext

Returns the transform context, for use when a destinationCrs() has been set and reprojection is required

See also

destinationCrs()

Return type:

QgsCoordinateTransformContext