QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
QgsFeatureRequest Class Reference

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

#include <qgsfeaturerequest.h>

Classes

class  OrderBy
 Represents a list of OrderByClauses, with the most important first and the least important last. More...
 
class  OrderByClause
 The OrderByClause class represents an order by clause for a QgsFeatureRequest. More...
 

Public Member Functions

 QgsFeatureRequest ()
 construct a default request: for all features get attributes and geometries
 
 QgsFeatureRequest (const QgsExpression &expr, const QgsExpressionContext &context=QgsExpressionContext())
 construct a request with a filter expression
 
 QgsFeatureRequest (const QgsFeatureIds &fids)
 construct a request with feature ID filter
 
 QgsFeatureRequest (const QgsFeatureRequest &rh)
 
 QgsFeatureRequest (const QgsRectangle &rectangle)
 Construct a request with rectangle bounding box filter.
 
 QgsFeatureRequest (QgsFeatureId fid)
 construct a request with feature ID filter
 
 ~QgsFeatureRequest ()
 
bool acceptFeature (const QgsFeature &feature)
 Check if a feature is accepted by this requests filter.
 
QgsFeatureRequestaddOrderBy (const QString &expression, bool ascending, bool nullsfirst)
 Adds a new OrderByClause, appending it as the least important one.
 
QgsFeatureRequestaddOrderBy (const QString &expression, bool ascending=true)
 Adds a new OrderByClause, appending it as the least important one.
 
QgsCoordinateTransform calculateTransform (const QgsCoordinateReferenceSystem &sourceCrs) const
 Calculates the coordinate transform to use to transform geometries when they are originally in sourceCrs.
 
QgsFeatureRequestcombineFilterExpression (const QString &expression)
 Modifies the existing filter expression to add an additional expression filter.
 
bool compare (const QgsFeatureRequest &other) const
 Compare two requests for equality, ignoring Expression Context, Transform Error Callback, Feedback and Invalid Geometry Callback.
 
Q_DECL_DEPRECATED int connectionTimeout () const
 Returns the timeout (in milliseconds) for how long we should wait for a connection if none is available from the pool at this moment.
 
QgsCoordinateTransform coordinateTransform () const
 Returns the coordinate transform which will be used to transform the feature's geometries.
 
QgsCoordinateReferenceSystem destinationCrs () const
 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.
 
QgsFeatureRequestdisableFilter ()
 Disables any attribute/ID filtering.
 
double distanceWithin () const
 Returns the maximum distance from the referenceGeometry() of fetched features, if spatialFilterType() is Qgis::SpatialFilterType::DistanceWithin.
 
QgsExpressionContextexpressionContext ()
 Returns the expression context used to evaluate filter expressions.
 
QgsFeedbackfeedback () const
 Returns the feedback object that can be queried regularly by the iterator to check if it should be canceled, if set.
 
QgsExpressionfilterExpression () const
 Returns the filter expression (if set).
 
QgsFeatureId filterFid () const
 Returns the feature ID that should be fetched.
 
const QgsFeatureIdsfilterFids () const
 Returns the feature IDs that should be fetched.
 
QgsRectangle filterRect () const
 Returns the rectangle from which features will be taken.
 
Qgis::FeatureRequestFilterType filterType () const
 Returns the attribute/ID filter type which is currently set on this request.
 
Qgis::FeatureRequestFlags flags () const
 Returns the flags which affect how features are fetched.
 
std::function< void(const QgsFeature &) > invalidGeometryCallback () const
 Returns the callback function to use when encountering an invalid geometry and invalidGeometryCheck() is set to GeometryAbortOnInvalid or GeometrySkipInvalid.
 
Qgis::InvalidGeometryCheck invalidGeometryCheck () const
 Returns the invalid geometry checking behavior.
 
long long limit () const
 Returns the maximum number of features to request, or -1 if no limit set.
 
QgsFeatureRequestoperator= (const QgsFeatureRequest &rh)
 
OrderBy orderBy () const
 Returns a list of order by clauses specified for this feature request.
 
QgsGeometry referenceGeometry () const
 Returns the reference geometry used for spatial filtering of features.
 
std::shared_ptr< QgsGeometryEnginereferenceGeometryEngine () const
 Returns the reference geometry engine used for spatial filtering of features.
 
bool requestMayBeNested () const
 In case this request may be run nested within another already running iteration on the same connection, set this to true.
 
Q_DECL_DEPRECATED QgsFeatureRequestsetConnectionTimeout (int connectionTimeout)
 Sets the timeout (in milliseconds) for how long we should wait for a connection if none is available from the pool at this moment.
 
QgsFeatureRequestsetCoordinateTransform (const QgsCoordinateTransform &transform)
 Sets the coordinate transform which will be used to transform the feature's geometries.
 
QgsFeatureRequestsetDestinationCrs (const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
 Sets the destination crs for feature's geometries.
 
QgsFeatureRequestsetDistanceWithin (const QgsGeometry &geometry, double distance)
 Sets a reference geometry and a maximum distance from this geometry to retrieve features within.
 
QgsFeatureRequestsetExpressionContext (const QgsExpressionContext &context)
 Sets the expression context used to evaluate filter expressions.
 
void setFeedback (QgsFeedback *feedback)
 Attach a feedback object that can be queried regularly by the iterator to check if it should be canceled.
 
QgsFeatureRequestsetFilterExpression (const QString &expression)
 Set the filter expression.
 
QgsFeatureRequestsetFilterFid (QgsFeatureId fid)
 Sets the feature ID that should be fetched.
 
QgsFeatureRequestsetFilterFids (const QgsFeatureIds &fids)
 Sets the feature IDs that should be fetched.
 
QgsFeatureRequestsetFilterRect (const QgsRectangle &rectangle)
 Sets the rectangle from which features will be taken.
 
QgsFeatureRequestsetFlags (Qgis::FeatureRequestFlags flags)
 Sets flags that affect how features will be fetched.
 
QgsFeatureRequestsetInvalidGeometryCallback (const std::function< void(const QgsFeature &)> &callback)
 Sets a callback function to use when encountering an invalid geometry and invalidGeometryCheck() is set to GeometryAbortOnInvalid or GeometrySkipInvalid.
 
QgsFeatureRequestsetInvalidGeometryCheck (Qgis::InvalidGeometryCheck check)
 Sets invalid geometry checking behavior.
 
QgsFeatureRequestsetLimit (long long limit)
 Set the maximum number of features to request.
 
QgsFeatureRequestsetNoAttributes ()
 Set that no attributes will be fetched.
 
QgsFeatureRequestsetOrderBy (const OrderBy &orderBy)
 Set a list of order by clauses.
 
QgsFeatureRequestsetRequestMayBeNested (bool requestMayBeNested)
 In case this request may be run nested within another already running iteration on the same connection, set this to true.
 
QgsFeatureRequestsetSimplifyMethod (const QgsSimplifyMethod &simplifyMethod)
 Set a simplification method for geometries that will be fetched.
 
QgsFeatureRequestsetSubsetOfAttributes (const QgsAttributeList &attrs)
 Set a subset of attributes that will be fetched.
 
QgsFeatureRequestsetSubsetOfAttributes (const QSet< QString > &attrNames, const QgsFields &fields)
 Sets a subset of attributes by names that will be fetched.
 
QgsFeatureRequestsetSubsetOfAttributes (const QStringList &attrNames, const QgsFields &fields)
 Sets a subset of attributes by names that will be fetched.
 
QgsFeatureRequestsetTimeout (int timeout)
 Sets the timeout (in milliseconds) for the maximum time we should wait during feature requests before a feature is returned.
 
QgsFeatureRequestsetTransformErrorCallback (const std::function< void(const QgsFeature &)> &callback)
 Sets a callback function to use when encountering a transform error when iterating features and a destinationCrs() is set.
 
const QgsSimplifyMethodsimplifyMethod () const
 Returns the simplification method for geometries that will be fetched.
 
Qgis::SpatialFilterType spatialFilterType () const
 Returns the spatial filter type which is currently set on this request.
 
QgsAttributeList subsetOfAttributes () const
 Returns the subset of attributes which at least need to be fetched.
 
int timeout () const
 Returns the timeout (in milliseconds) for the maximum time we should wait during feature requests before a feature is returned.
 
QgsCoordinateTransformContext transformContext () const
 Returns the transform context, for use when a destinationCrs() has been set and reprojection is required.
 
std::function< void(const QgsFeature &) > transformErrorCallback () const
 Returns the callback function to use when encountering a transform error when iterating features and a destinationCrs() is set.
 

Static Public Attributes

static const QString ALL_ATTRIBUTES = QStringLiteral( "#!allattributes!#" )
 A special attribute that if set matches all attributes.
 

Protected Attributes

QgsAttributeList mAttrs
 
QgsCoordinateReferenceSystem mCrs
 
double mDistanceWithin = 0
 Maximum distance from reference geometry.
 
QgsExpressionContext mExpressionContext
 
QgsFeedbackmFeedback = nullptr
 
Qgis::FeatureRequestFilterType mFilter = Qgis::FeatureRequestFilterType::NoFilter
 Attribute/ID filter type.
 
std::unique_ptr< QgsExpressionmFilterExpression
 
QgsFeatureId mFilterFid = -1
 
QgsFeatureIds mFilterFids
 
QgsRectangle mFilterRect
 Bounding box for spatial filtering.
 
Qgis::FeatureRequestFlags mFlags
 
std::function< void(const QgsFeature &) > mInvalidGeometryCallback
 
Qgis::InvalidGeometryCheck mInvalidGeometryFilter = Qgis::InvalidGeometryCheck::NoCheck
 
long long mLimit = -1
 
OrderBy mOrderBy
 
QgsGeometry mReferenceGeometry
 Reference geometry for Qgis::RequestSpatialFilter::DistanceWithin filtering.
 
std::shared_ptr< QgsGeometryEnginemReferenceGeometryEngine
 Prepared geometry engine for mReferenceGeometry.
 
int mRequestMayBeNested = false
 
QgsSimplifyMethod mSimplifyMethod
 
Qgis::SpatialFilterType mSpatialFilter = Qgis::SpatialFilterType::NoFilter
 Spatial filter type.
 
int mTimeout = -1
 
QgsCoordinateTransform mTransform
 
QgsCoordinateTransformContext mTransformContext
 
std::function< void(const QgsFeature &) > mTransformErrorCallback
 

Detailed Description

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:

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

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

The options may be chained, e.g.:

QgsFeatureRequest().setFilterRect(QgsRectangle(0,0,1,1)).setFlags(QgsFeatureRequest.ExactIntersect)
This class wraps a request for features to a vector layer (or directly its vector data provider).
A rectangle specified with double values.

Examples:

# fetch all features:
# 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)
static Q_INVOKABLE QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.

Definition at line 83 of file qgsfeaturerequest.h.

Constructor & Destructor Documentation

◆ QgsFeatureRequest() [1/6]

QgsFeatureRequest::QgsFeatureRequest ( )

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

Definition at line 26 of file qgsfeaturerequest.cpp.

◆ QgsFeatureRequest() [2/6]

QgsFeatureRequest::QgsFeatureRequest ( QgsFeatureId  fid)
explicit

construct a request with feature ID filter

Definition at line 32 of file qgsfeaturerequest.cpp.

◆ QgsFeatureRequest() [3/6]

QgsFeatureRequest::QgsFeatureRequest ( const QgsFeatureIds fids)
explicit

construct a request with feature ID filter

Definition at line 38 of file qgsfeaturerequest.cpp.

◆ QgsFeatureRequest() [4/6]

QgsFeatureRequest::QgsFeatureRequest ( const QgsRectangle rectangle)
explicit

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.

Definition at line 45 of file qgsfeaturerequest.cpp.

◆ QgsFeatureRequest() [5/6]

QgsFeatureRequest::QgsFeatureRequest ( const QgsExpression expr,
const QgsExpressionContext context = QgsExpressionContext() 
)
explicit

construct a request with a filter expression

Definition at line 51 of file qgsfeaturerequest.cpp.

◆ QgsFeatureRequest() [6/6]

QgsFeatureRequest::QgsFeatureRequest ( const QgsFeatureRequest rh)

Definition at line 58 of file qgsfeaturerequest.cpp.

◆ ~QgsFeatureRequest()

QgsFeatureRequest::~QgsFeatureRequest ( )
default

Member Function Documentation

◆ acceptFeature()

bool QgsFeatureRequest::acceptFeature ( const QgsFeature feature)

Check if a feature is accepted by this requests filter.

Parameters
featureThe feature which will be tested
Returns
true, if the filter accepts the feature

Definition at line 366 of file qgsfeaturerequest.cpp.

◆ addOrderBy() [1/2]

QgsFeatureRequest & QgsFeatureRequest::addOrderBy ( const QString &  expression,
bool  ascending,
bool  nullsfirst 
)

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

Parameters
expressionThe expression to use for ordering
ascendingIf the order should be ascending (1,2,3) or descending (3,2,1)
nullsfirstIf true, NULLS are at the beginning, if false, NULLS are at the end

Definition at line 228 of file qgsfeaturerequest.cpp.

◆ addOrderBy() [2/2]

QgsFeatureRequest & QgsFeatureRequest::addOrderBy ( const QString &  expression,
bool  ascending = true 
)

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

Parameters
expressionThe expression to use for ordering
ascendingIf 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

Definition at line 222 of file qgsfeaturerequest.cpp.

◆ calculateTransform()

QgsCoordinateTransform QgsFeatureRequest::calculateTransform ( const QgsCoordinateReferenceSystem sourceCrs) const

Calculates the coordinate transform to use to transform geometries when they are originally in sourceCrs.

This method will return coordinateTransform() if it is set (ignoring sourceCrs), otherwise it will calculate an appriopriate transform from sourceCrs to destinationCrs().

Since
QGIS 3.40

Definition at line 334 of file qgsfeaturerequest.cpp.

◆ combineFilterExpression()

QgsFeatureRequest & QgsFeatureRequest::combineFilterExpression ( const QString &  expression)

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.

Definition at line 203 of file qgsfeaturerequest.cpp.

◆ compare()

bool QgsFeatureRequest::compare ( const QgsFeatureRequest other) const

Compare two requests for equality, ignoring Expression Context, Transform Error Callback, Feedback and Invalid Geometry Callback.

Parameters
otherthe other request
Returns
true if the requests are equal in all respects but without checking for Expression Context, Transform Error, Feedback and Invalid Geometry Callback
Since
QGIS 3.38

Definition at line 103 of file qgsfeaturerequest.cpp.

◆ connectionTimeout()

int QgsFeatureRequest::connectionTimeout ( ) const

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:
QGIS 3.40. Use timeout() instead.

Definition at line 421 of file qgsfeaturerequest.cpp.

◆ coordinateTransform()

QgsCoordinateTransform QgsFeatureRequest::coordinateTransform ( ) const

Returns the coordinate transform which will be used to transform the feature's geometries.

If this transform is valid then it will always be used to transform features, regardless of the destinationCrs() setting or the underlying feature source's actual CRS.

See also
setCoordinateTransform()
Since
QGIS 3.40

Definition at line 319 of file qgsfeaturerequest.cpp.

◆ destinationCrs()

QgsCoordinateReferenceSystem QgsFeatureRequest::destinationCrs ( ) const

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.

Warning
if coordinateTransform() returns a valid transform then the destinationCrs() will have no effect, and the coordinateTransform() will always be used to transform features.
See also
calculateTransform()
setDestinationCrs()
transformContext()

Definition at line 324 of file qgsfeaturerequest.cpp.

◆ disableFilter()

QgsFeatureRequest & QgsFeatureRequest::disableFilter ( )
inline

Disables any attribute/ID filtering.

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

Note
Spatial filters will be left in place.
Returns
The object the method is called on for chaining

Definition at line 567 of file qgsfeaturerequest.h.

◆ distanceWithin()

double QgsFeatureRequest::distanceWithin ( ) const
inline

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.

See also
setDistanceWithin()
Since
QGIS 3.22

Definition at line 429 of file qgsfeaturerequest.h.

◆ expressionContext()

QgsExpressionContext * QgsFeatureRequest::expressionContext ( )
inline

Returns the expression context used to evaluate filter expressions.

See also
setExpressionContext
filterExpression

Definition at line 548 of file qgsfeaturerequest.h.

◆ feedback()

QgsFeedback * QgsFeatureRequest::feedback ( ) const

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

See also
setFeedback()
Since
QGIS 3.20

Definition at line 459 of file qgsfeaturerequest.cpp.

◆ filterExpression()

QgsExpression * QgsFeatureRequest::filterExpression ( ) const
inline

Returns the filter expression (if set).

See also
setFilterExpression()
expressionContext()

Definition at line 531 of file qgsfeaturerequest.h.

◆ filterFid()

QgsFeatureId QgsFeatureRequest::filterFid ( ) const
inline

Returns the feature ID that should be fetched.

See also
setFilterFid()
filterFids()

Definition at line 447 of file qgsfeaturerequest.h.

◆ filterFids()

const QgsFeatureIds & QgsFeatureRequest::filterFids ( ) const
inline

Returns the feature IDs that should be fetched.

See also
setFilterFids()
filterFid()

Definition at line 465 of file qgsfeaturerequest.h.

◆ filterRect()

QgsRectangle QgsFeatureRequest::filterRect ( ) const

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

Definition at line 146 of file qgsfeaturerequest.cpp.

◆ filterType()

Qgis::FeatureRequestFilterType QgsFeatureRequest::filterType ( ) const
inline

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.
See also
spatialFilterType()

Definition at line 328 of file qgsfeaturerequest.h.

◆ flags()

Qgis::FeatureRequestFlags QgsFeatureRequest::flags ( ) const
inline

Returns the flags which affect how features are fetched.

See also
setFlags()

Definition at line 632 of file qgsfeaturerequest.h.

◆ invalidGeometryCallback()

std::function< void(const QgsFeature &) > QgsFeatureRequest::invalidGeometryCallback ( ) const
inline

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

Note
not available in Python bindings
See also
setInvalidGeometryCallback()

Definition at line 513 of file qgsfeaturerequest.h.

◆ invalidGeometryCheck()

Qgis::InvalidGeometryCheck QgsFeatureRequest::invalidGeometryCheck ( ) const
inline

Returns the invalid geometry checking behavior.

See also
setInvalidGeometryCheck()

Definition at line 479 of file qgsfeaturerequest.h.

◆ limit()

long long QgsFeatureRequest::limit ( ) const
inline

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

See also
setLimit

Definition at line 615 of file qgsfeaturerequest.h.

◆ operator=()

QgsFeatureRequest & QgsFeatureRequest::operator= ( const QgsFeatureRequest rh)

Definition at line 63 of file qgsfeaturerequest.cpp.

◆ orderBy()

QgsFeatureRequest::OrderBy QgsFeatureRequest::orderBy ( ) const

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

Definition at line 234 of file qgsfeaturerequest.cpp.

◆ referenceGeometry()

QgsGeometry QgsFeatureRequest::referenceGeometry ( ) const
inline

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.

See also
setDistanceWithin()
Since
QGIS 3.22

Definition at line 406 of file qgsfeaturerequest.h.

◆ referenceGeometryEngine()

std::shared_ptr< QgsGeometryEngine > QgsFeatureRequest::referenceGeometryEngine ( ) const
inline

Returns the reference geometry engine used for spatial filtering of features.

This is to avoid re-creating the engine.

See also
referenceGeometry()
Since
QGIS 3.22

Definition at line 416 of file qgsfeaturerequest.h.

◆ requestMayBeNested()

bool QgsFeatureRequest::requestMayBeNested ( ) const

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.

See also
setRequestMayBeNested()
Since
QGIS 3.4

Definition at line 443 of file qgsfeaturerequest.cpp.

◆ setConnectionTimeout()

QgsFeatureRequest & QgsFeatureRequest::setConnectionTimeout ( int  connectionTimeout)

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:
QGIS 3.40. Use setTimeout() instead.

Definition at line 426 of file qgsfeaturerequest.cpp.

◆ setCoordinateTransform()

QgsFeatureRequest & QgsFeatureRequest::setCoordinateTransform ( const QgsCoordinateTransform transform)

Sets the coordinate transform which will be used to transform the feature's geometries.

If this transform is valid then it will always be used to transform features, regardless of the destinationCrs() setting or the underlying feature source's actual CRS.

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

The feature geometry transformation 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.

Warning
This method should be used with caution, and it is recommended to use the high-level setDestinationCrs() method instead. Setting a specific transform should only be done when there is a requirement to use a particular transform.
See also
coordinateTransform()
Since
QGIS 3.40

Definition at line 347 of file qgsfeaturerequest.cpp.

◆ setDestinationCrs()

QgsFeatureRequest & QgsFeatureRequest::setDestinationCrs ( const QgsCoordinateReferenceSystem crs,
const QgsCoordinateTransformContext context 
)

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.

Warning
if coordinateTransform() returns a valid transform then the destinationCrs() will have no effect, and the coordinateTransform() will always be used to transform features.
See also
destinationCrs()

Definition at line 353 of file qgsfeaturerequest.cpp.

◆ setDistanceWithin()

QgsFeatureRequest & QgsFeatureRequest::setDistanceWithin ( const QgsGeometry geometry,
double  distance 
)

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()
Since
QGIS 3.22

Definition at line 151 of file qgsfeaturerequest.cpp.

◆ setExpressionContext()

QgsFeatureRequest & QgsFeatureRequest::setExpressionContext ( const QgsExpressionContext context)

Sets the expression context used to evaluate filter expressions.

See also
expressionContext
setFilterExpression

Definition at line 216 of file qgsfeaturerequest.cpp.

◆ setFeedback()

void QgsFeatureRequest::setFeedback ( QgsFeedback feedback)

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()
Since
QGIS 3.20

Definition at line 454 of file qgsfeaturerequest.cpp.

◆ setFilterExpression()

QgsFeatureRequest & QgsFeatureRequest::setFilterExpression ( const QString &  expression)

Set the filter expression.

{

See also
QgsExpression}
Parameters
expressionexpression string

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

See also
filterExpression()
setExpressionContext()

Definition at line 196 of file qgsfeaturerequest.cpp.

◆ setFilterFid()

QgsFeatureRequest & QgsFeatureRequest::setFilterFid ( QgsFeatureId  fid)

Sets the feature ID that should be fetched.

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

See also
filterFid()
setFilterFids()

Definition at line 170 of file qgsfeaturerequest.cpp.

◆ setFilterFids()

QgsFeatureRequest & QgsFeatureRequest::setFilterFids ( const QgsFeatureIds fids)

Sets the feature IDs that should be fetched.

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

See also
filterFids()
setFilterFid()

Definition at line 177 of file qgsfeaturerequest.cpp.

◆ setFilterRect()

QgsFeatureRequest & QgsFeatureRequest::setFilterRect ( const QgsRectangle rectangle)

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

Definition at line 130 of file qgsfeaturerequest.cpp.

◆ setFlags()

QgsFeatureRequest & QgsFeatureRequest::setFlags ( Qgis::FeatureRequestFlags  flags)

Sets flags that affect how features will be fetched.

See also
flags()

Definition at line 251 of file qgsfeaturerequest.cpp.

◆ setInvalidGeometryCallback()

QgsFeatureRequest & QgsFeatureRequest::setInvalidGeometryCallback ( const std::function< void(const QgsFeature &)> &  callback)

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

Definition at line 190 of file qgsfeaturerequest.cpp.

◆ setInvalidGeometryCheck()

QgsFeatureRequest & QgsFeatureRequest::setInvalidGeometryCheck ( Qgis::InvalidGeometryCheck  check)

Sets invalid geometry checking behavior.

Note
Invalid geometry checking is not performed when retrieving features directly from a QgsVectorDataProvider.
See also
invalidGeometryCheck()

Definition at line 184 of file qgsfeaturerequest.cpp.

◆ setLimit()

QgsFeatureRequest & QgsFeatureRequest::setLimit ( long long  limit)

Set the maximum number of features to request.

Parameters
limitmaximum number of features, or -1 to request all features.
See also
limit()

Definition at line 245 of file qgsfeaturerequest.cpp.

◆ setNoAttributes()

QgsFeatureRequest & QgsFeatureRequest::setNoAttributes ( )

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.
See also
setSubsetOfAttributes()
Since
QGIS 3.4

Definition at line 264 of file qgsfeaturerequest.cpp.

◆ setOrderBy()

QgsFeatureRequest & QgsFeatureRequest::setOrderBy ( const OrderBy orderBy)

Set a list of order by clauses.

Definition at line 239 of file qgsfeaturerequest.cpp.

◆ setRequestMayBeNested()

QgsFeatureRequest & QgsFeatureRequest::setRequestMayBeNested ( bool  requestMayBeNested)

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.

See also
requestMayBeNested()
Since
QGIS 3.4

Definition at line 448 of file qgsfeaturerequest.cpp.

◆ setSimplifyMethod()

QgsFeatureRequest & QgsFeatureRequest::setSimplifyMethod ( const QgsSimplifyMethod simplifyMethod)

Set a simplification method for geometries that will be fetched.

See also
simplifyMethod()

Definition at line 313 of file qgsfeaturerequest.cpp.

◆ setSubsetOfAttributes() [1/3]

QgsFeatureRequest & QgsFeatureRequest::setSubsetOfAttributes ( const QgsAttributeList attrs)

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.
See also
subsetOfAttributes()
setNoAttributes()

Definition at line 257 of file qgsfeaturerequest.cpp.

◆ setSubsetOfAttributes() [2/3]

QgsFeatureRequest & QgsFeatureRequest::setSubsetOfAttributes ( const QSet< QString > &  attrNames,
const QgsFields fields 
)

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.
See also
subsetOfAttributes()

Definition at line 291 of file qgsfeaturerequest.cpp.

◆ setSubsetOfAttributes() [3/3]

QgsFeatureRequest & QgsFeatureRequest::setSubsetOfAttributes ( const QStringList &  attrNames,
const QgsFields fields 
)

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.
See also
subsetOfAttributes()

Definition at line 269 of file qgsfeaturerequest.cpp.

◆ setTimeout()

QgsFeatureRequest & QgsFeatureRequest::setTimeout ( int  timeout)

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()
Since
QGIS 3.4

Definition at line 437 of file qgsfeaturerequest.cpp.

◆ setTransformErrorCallback()

QgsFeatureRequest & QgsFeatureRequest::setTransformErrorCallback ( const std::function< void(const QgsFeature &)> &  callback)

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

Definition at line 360 of file qgsfeaturerequest.cpp.

◆ simplifyMethod()

const QgsSimplifyMethod & QgsFeatureRequest::simplifyMethod ( ) const
inline

Returns the simplification method for geometries that will be fetched.

See also
setSimplifyMethod()

Definition at line 722 of file qgsfeaturerequest.h.

◆ spatialFilterType()

Qgis::SpatialFilterType QgsFeatureRequest::spatialFilterType ( ) const
inline

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()
Since
QGIS 3.22

Definition at line 342 of file qgsfeaturerequest.h.

◆ subsetOfAttributes()

QgsAttributeList QgsFeatureRequest::subsetOfAttributes ( ) const
inline

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

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.
See also
setSubsetOfAttributes()
setNoAttributes()

Definition at line 682 of file qgsfeaturerequest.h.

◆ timeout()

int QgsFeatureRequest::timeout ( ) const

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()
Since
QGIS 3.4

Definition at line 432 of file qgsfeaturerequest.cpp.

◆ transformContext()

QgsCoordinateTransformContext QgsFeatureRequest::transformContext ( ) const

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

See also
setDestinationCrs()
destinationCrs()

Definition at line 329 of file qgsfeaturerequest.cpp.

◆ transformErrorCallback()

std::function< void(const QgsFeature &) > QgsFeatureRequest::transformErrorCallback ( ) const
inline

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

Note
not available in Python bindings
See also
setTransformErrorCallback()
destinationCrs()

Definition at line 866 of file qgsfeaturerequest.h.

Member Data Documentation

◆ ALL_ATTRIBUTES

const QString QgsFeatureRequest::ALL_ATTRIBUTES = QStringLiteral( "#!allattributes!#" )
static

A special attribute that if set matches all attributes.

Definition at line 284 of file qgsfeaturerequest.h.

◆ mAttrs

QgsAttributeList QgsFeatureRequest::mAttrs
protected

Definition at line 1013 of file qgsfeaturerequest.h.

◆ mCrs

QgsCoordinateReferenceSystem QgsFeatureRequest::mCrs
protected

Definition at line 1021 of file qgsfeaturerequest.h.

◆ mDistanceWithin

double QgsFeatureRequest::mDistanceWithin = 0
protected

Maximum distance from reference geometry.

Definition at line 1006 of file qgsfeaturerequest.h.

◆ mExpressionContext

QgsExpressionContext QgsFeatureRequest::mExpressionContext
protected

Definition at line 1011 of file qgsfeaturerequest.h.

◆ mFeedback

QgsFeedback* QgsFeatureRequest::mFeedback = nullptr
protected

Definition at line 1025 of file qgsfeaturerequest.h.

◆ mFilter

Attribute/ID filter type.

Definition at line 979 of file qgsfeaturerequest.h.

◆ mFilterExpression

std::unique_ptr< QgsExpression > QgsFeatureRequest::mFilterExpression
protected

Definition at line 1010 of file qgsfeaturerequest.h.

◆ mFilterFid

QgsFeatureId QgsFeatureRequest::mFilterFid = -1
protected

Definition at line 1008 of file qgsfeaturerequest.h.

◆ mFilterFids

QgsFeatureIds QgsFeatureRequest::mFilterFids
protected

Definition at line 1009 of file qgsfeaturerequest.h.

◆ mFilterRect

QgsRectangle QgsFeatureRequest::mFilterRect
protected

Bounding box for spatial filtering.

Definition at line 991 of file qgsfeaturerequest.h.

◆ mFlags

Qgis::FeatureRequestFlags QgsFeatureRequest::mFlags
protected

Definition at line 1012 of file qgsfeaturerequest.h.

◆ mInvalidGeometryCallback

std::function< void( const QgsFeature & ) > QgsFeatureRequest::mInvalidGeometryCallback
protected

Definition at line 1018 of file qgsfeaturerequest.h.

◆ mInvalidGeometryFilter

Qgis::InvalidGeometryCheck QgsFeatureRequest::mInvalidGeometryFilter = Qgis::InvalidGeometryCheck::NoCheck
protected

Definition at line 1017 of file qgsfeaturerequest.h.

◆ mLimit

long long QgsFeatureRequest::mLimit = -1
protected

Definition at line 1015 of file qgsfeaturerequest.h.

◆ mOrderBy

OrderBy QgsFeatureRequest::mOrderBy
protected

Definition at line 1016 of file qgsfeaturerequest.h.

◆ mReferenceGeometry

QgsGeometry QgsFeatureRequest::mReferenceGeometry
protected

Reference geometry for Qgis::RequestSpatialFilter::DistanceWithin filtering.

Definition at line 996 of file qgsfeaturerequest.h.

◆ mReferenceGeometryEngine

std::shared_ptr< QgsGeometryEngine > QgsFeatureRequest::mReferenceGeometryEngine
protected

Prepared geometry engine for mReferenceGeometry.

Definition at line 1001 of file qgsfeaturerequest.h.

◆ mRequestMayBeNested

int QgsFeatureRequest::mRequestMayBeNested = false
protected

Definition at line 1024 of file qgsfeaturerequest.h.

◆ mSimplifyMethod

QgsSimplifyMethod QgsFeatureRequest::mSimplifyMethod
protected

Definition at line 1014 of file qgsfeaturerequest.h.

◆ mSpatialFilter

Qgis::SpatialFilterType QgsFeatureRequest::mSpatialFilter = Qgis::SpatialFilterType::NoFilter
protected

Spatial filter type.

Since
QGIS 3.22

Definition at line 986 of file qgsfeaturerequest.h.

◆ mTimeout

int QgsFeatureRequest::mTimeout = -1
protected

Definition at line 1023 of file qgsfeaturerequest.h.

◆ mTransform

QgsCoordinateTransform QgsFeatureRequest::mTransform
protected

Definition at line 1020 of file qgsfeaturerequest.h.

◆ mTransformContext

QgsCoordinateTransformContext QgsFeatureRequest::mTransformContext
protected

Definition at line 1022 of file qgsfeaturerequest.h.

◆ mTransformErrorCallback

std::function< void( const QgsFeature & ) > QgsFeatureRequest::mTransformErrorCallback
protected

Definition at line 1019 of file qgsfeaturerequest.h.


The documentation for this class was generated from the following files: