QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
#include <qgsfeaturerequest.h>
Classes | |
class | OrderBy |
class | OrderByClause |
Public Types | |
enum | FilterType { FilterNone, FilterFid, FilterExpression, FilterFids } |
Types of filters. More... | |
enum | Flag { NoFlags = 0, NoGeometry = 1, SubsetOfAttributes = 2, ExactIntersect = 4 } |
enum | InvalidGeometryCheck { GeometryNoCheck = 0, GeometrySkipInvalid = 1, GeometryAbortOnInvalid = 2 } |
Handling of features with invalid geometries. More... | |
Public Member Functions | |
QgsFeatureRequest () | |
construct a default request: for all features get attributes and geometries More... | |
QgsFeatureRequest (const QgsExpression &expr, const QgsExpressionContext &context=QgsExpressionContext()) | |
construct a request with a filter expression More... | |
QgsFeatureRequest (const QgsFeatureIds &fids) | |
construct a request with feature ID filter More... | |
QgsFeatureRequest (const QgsFeatureRequest &rh) | |
copy constructor More... | |
QgsFeatureRequest (const QgsRectangle &rectangle) | |
Construct a request with rectangle bounding box filter. More... | |
QgsFeatureRequest (QgsFeatureId fid) | |
construct a request with feature ID filter More... | |
bool | acceptFeature (const QgsFeature &feature) |
Check if a feature is accepted by this requests filter. More... | |
QgsFeatureRequest & | addOrderBy (const QString &expression, bool ascending, bool nullsfirst) |
Adds a new OrderByClause, appending it as the least important one. More... | |
QgsFeatureRequest & | addOrderBy (const QString &expression, bool ascending=true) |
Adds a new OrderByClause, appending it as the least important one. More... | |
QgsFeatureRequest & | combineFilterExpression (const QString &expression) |
Modifies the existing filter expression to add an additional expression filter. More... | |
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. More... | |
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. More... | |
QgsFeatureRequest & | disableFilter () |
Disables filter conditions. More... | |
QgsExpressionContext * | expressionContext () |
Returns the expression context used to evaluate filter expressions. More... | |
QgsExpression * | filterExpression () const |
Returns the filter expression if set. More... | |
QgsFeatureId | filterFid () const |
Gets the feature ID that should be fetched. More... | |
const QgsFeatureIds & | filterFids () const |
Gets feature IDs that should be fetched. More... | |
const QgsRectangle & | filterRect () const |
Returns the rectangle from which features will be taken. More... | |
FilterType | filterType () const |
Returns the filter type which is currently set on this request. More... | |
const Flags & | flags () const |
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. More... | |
InvalidGeometryCheck | invalidGeometryCheck () const |
Returns the invalid geometry checking behavior. More... | |
long | limit () const |
Returns the maximum number of features to request, or -1 if no limit set. More... | |
QgsFeatureRequest & | operator= (const QgsFeatureRequest &rh) |
Assignment operator. More... | |
OrderBy | orderBy () const |
Returns a list of order by clauses specified for this feature request. More... | |
bool | requestMayBeNested () const |
In case this request may be run nested within another already running iteration on the same connection, set this to true . More... | |
Q_DECL_DEPRECATED 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. More... | |
QgsFeatureRequest & | setDestinationCrs (const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context) |
Sets the destination crs for feature's geometries. More... | |
QgsFeatureRequest & | setExpressionContext (const QgsExpressionContext &context) |
Sets the expression context used to evaluate filter expressions. More... | |
QgsFeatureRequest & | setFilterExpression (const QString &expression) |
Set the filter expression. More... | |
QgsFeatureRequest & | setFilterFid (QgsFeatureId fid) |
Sets feature ID that should be fetched. More... | |
QgsFeatureRequest & | setFilterFids (const QgsFeatureIds &fids) |
Sets feature IDs that should be fetched. More... | |
QgsFeatureRequest & | setFilterRect (const QgsRectangle &rectangle) |
Sets the rectangle from which features will be taken. More... | |
QgsFeatureRequest & | setFlags (QgsFeatureRequest::Flags flags) |
Sets flags that affect how features will be fetched. More... | |
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. More... | |
QgsFeatureRequest & | setInvalidGeometryCheck (InvalidGeometryCheck check) |
Sets invalid geometry checking behavior. More... | |
QgsFeatureRequest & | setLimit (long limit) |
Set the maximum number of features to request. More... | |
QgsFeatureRequest & | setNoAttributes () |
Set that no attributes will be fetched. More... | |
QgsFeatureRequest & | setOrderBy (const OrderBy &orderBy) |
Set a list of order by clauses. More... | |
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 . More... | |
QgsFeatureRequest & | setSimplifyMethod (const QgsSimplifyMethod &simplifyMethod) |
Set a simplification method for geometries that will be fetched. More... | |
QgsFeatureRequest & | setSubsetOfAttributes (const QgsAttributeList &attrs) |
Set a subset of attributes that will be fetched. More... | |
QgsFeatureRequest & | setSubsetOfAttributes (const QSet< QString > &attrNames, const QgsFields &fields) |
Sets a subset of attributes by names that will be fetched. More... | |
QgsFeatureRequest & | setSubsetOfAttributes (const QStringList &attrNames, const QgsFields &fields) |
Sets a subset of attributes by names that will be fetched. More... | |
QgsFeatureRequest & | setTimeout (int timeout) |
Sets the timeout (in milliseconds) for the maximum time we should wait during feature requests before a feature is returned. More... | |
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. More... | |
const QgsSimplifyMethod & | simplifyMethod () const |
Gets simplification method for geometries that will be fetched. More... | |
QgsAttributeList | subsetOfAttributes () const |
Returns the subset of attributes which at least need to be fetched. More... | |
int | timeout () const |
Returns the timeout (in milliseconds) for the maximum time we should wait during feature requests before a feature is returned. More... | |
QgsCoordinateTransformContext | transformContext () const |
Returns the transform context, for use when a destinationCrs() has been set and reprojection is required. More... | |
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. More... | |
Static Public Attributes | |
static const QString | ALL_ATTRIBUTES = QStringLiteral( "#!allattributes!#" ) |
A special attribute that if set matches all attributes. More... | |
Protected Attributes | |
QgsAttributeList | mAttrs |
QgsCoordinateReferenceSystem | mCrs |
QgsExpressionContext | mExpressionContext |
FilterType | mFilter = FilterNone |
std::unique_ptr< QgsExpression > | mFilterExpression |
QgsFeatureId | mFilterFid = -1 |
QgsFeatureIds | mFilterFids |
QgsRectangle | mFilterRect |
Flags | mFlags |
std::function< void(const QgsFeature &) > | mInvalidGeometryCallback |
InvalidGeometryCheck | mInvalidGeometryFilter = GeometryNoCheck |
long | mLimit = -1 |
OrderBy | mOrderBy |
int | mRequestMayBeNested = false |
QgsSimplifyMethod | mSimplifyMethod |
int | mTimeout = -1 |
QgsCoordinateTransformContext | mTransformContext |
std::function< void(const QgsFeature &) > | mTransformErrorCallback |
This class wraps a request for features to a vector layer (or directly its vector data provider). The request may apply a filter to fetch only a particular subset of features. Currently supported filters:
Additionally a spatial rectangle can be set in combination: Only features that intersect given rectangle should 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.
For efficiency, it is also possible to tell provider that some data is not required:
The options may be chained, e.g.:
Examples:
Definition at line 75 of file qgsfeaturerequest.h.
Types of filters.
Enumerator | |
---|---|
FilterNone | No filter is applied. |
FilterFid | Filter using feature ID. |
FilterExpression | Filter using expression. |
FilterFids | Filter using feature IDs. |
Definition at line 103 of file qgsfeaturerequest.h.
Definition at line 91 of file qgsfeaturerequest.h.
Handling of features with invalid geometries.
Definition at line 112 of file qgsfeaturerequest.h.
QgsFeatureRequest::QgsFeatureRequest | ( | ) |
construct a default request: for all features get attributes and geometries
Definition at line 25 of file qgsfeaturerequest.cpp.
|
explicit |
construct a request with feature ID filter
Definition at line 30 of file qgsfeaturerequest.cpp.
|
explicit |
construct a request with feature ID filter
Definition at line 37 of file qgsfeaturerequest.cpp.
|
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.
|
explicit |
construct a request with a filter expression
Definition at line 51 of file qgsfeaturerequest.cpp.
QgsFeatureRequest::QgsFeatureRequest | ( | const QgsFeatureRequest & | rh | ) |
copy constructor
Definition at line 59 of file qgsfeaturerequest.cpp.
bool QgsFeatureRequest::acceptFeature | ( | const QgsFeature & | feature | ) |
Check if a feature is accepted by this requests filter.
feature | The feature which will be tested |
true
, if the filter accepts the featureDefinition at line 276 of file qgsfeaturerequest.cpp.
QgsFeatureRequest & QgsFeatureRequest::addOrderBy | ( | const QString & | expression, |
bool | ascending, | ||
bool | nullsfirst | ||
) |
Adds a new OrderByClause, appending it as the least important one.
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 |
Definition at line 161 of file qgsfeaturerequest.cpp.
QgsFeatureRequest & QgsFeatureRequest::addOrderBy | ( | const QString & | expression, |
bool | ascending = true |
||
) |
Adds a new OrderByClause, appending it as the least important one.
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 |
Definition at line 155 of file qgsfeaturerequest.cpp.
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.
Definition at line 136 of file qgsfeaturerequest.cpp.
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.
Definition at line 309 of file qgsfeaturerequest.cpp.
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.
Definition at line 253 of file qgsfeaturerequest.cpp.
|
inline |
Disables filter conditions.
The spatial filter (filterRect) will be kept in place.
Definition at line 459 of file qgsfeaturerequest.h.
|
inline |
Returns the expression context used to evaluate filter expressions.
Definition at line 441 of file qgsfeaturerequest.h.
|
inline |
Returns the filter expression if set.
Definition at line 425 of file qgsfeaturerequest.h.
|
inline |
Gets the feature ID that should be fetched.
Definition at line 353 of file qgsfeaturerequest.h.
|
inline |
Gets feature IDs that should be fetched.
Definition at line 358 of file qgsfeaturerequest.h.
|
inline |
Returns the rectangle from which features will be taken.
If the returned rectangle is null, then no filter rectangle is set.
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.
Definition at line 348 of file qgsfeaturerequest.h.
|
inline |
Returns the filter type which is currently set on this request.
Definition at line 325 of file qgsfeaturerequest.h.
|
inline |
Definition at line 516 of file qgsfeaturerequest.h.
|
inline |
Returns the callback function to use when encountering an invalid geometry and invalidGeometryCheck() is set to GeometryAbortOnInvalid or GeometrySkipInvalid.
Definition at line 410 of file qgsfeaturerequest.h.
|
inline |
Returns the invalid geometry checking behavior.
Definition at line 374 of file qgsfeaturerequest.h.
|
inline |
Returns the maximum number of features to request, or -1 if no limit set.
Definition at line 512 of file qgsfeaturerequest.h.
QgsFeatureRequest & QgsFeatureRequest::operator= | ( | const QgsFeatureRequest & | rh | ) |
Assignment operator.
Definition at line 64 of file qgsfeaturerequest.cpp.
QgsFeatureRequest::OrderBy QgsFeatureRequest::orderBy | ( | ) | const |
Returns a list of order by clauses specified for this feature request.
Definition at line 167 of file qgsfeaturerequest.cpp.
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.
Definition at line 331 of file qgsfeaturerequest.cpp.
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.
Definition at line 314 of file qgsfeaturerequest.cpp.
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() 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.
Definition at line 263 of file qgsfeaturerequest.cpp.
QgsFeatureRequest & QgsFeatureRequest::setExpressionContext | ( | const QgsExpressionContext & | context | ) |
Sets the expression context used to evaluate filter expressions.
Definition at line 149 of file qgsfeaturerequest.cpp.
QgsFeatureRequest & QgsFeatureRequest::setFilterExpression | ( | const QString & | expression | ) |
Set the filter expression.
{
expression | expression string |
Definition at line 129 of file qgsfeaturerequest.cpp.
QgsFeatureRequest & QgsFeatureRequest::setFilterFid | ( | QgsFeatureId | fid | ) |
Sets feature ID that should be fetched.
Definition at line 103 of file qgsfeaturerequest.cpp.
QgsFeatureRequest & QgsFeatureRequest::setFilterFids | ( | const QgsFeatureIds & | fids | ) |
Sets feature IDs that should be fetched.
Definition at line 110 of file qgsfeaturerequest.cpp.
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.
Definition at line 97 of file qgsfeaturerequest.cpp.
QgsFeatureRequest & QgsFeatureRequest::setFlags | ( | QgsFeatureRequest::Flags | flags | ) |
Sets flags that affect how features will be fetched.
Definition at line 184 of file qgsfeaturerequest.cpp.
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.
Definition at line 123 of file qgsfeaturerequest.cpp.
QgsFeatureRequest & QgsFeatureRequest::setInvalidGeometryCheck | ( | QgsFeatureRequest::InvalidGeometryCheck | check | ) |
Sets invalid geometry checking behavior.
Definition at line 117 of file qgsfeaturerequest.cpp.
QgsFeatureRequest & QgsFeatureRequest::setLimit | ( | long | limit | ) |
Set the maximum number of features to request.
limit | maximum number of features, or -1 to request all features. |
Definition at line 178 of file qgsfeaturerequest.cpp.
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.
Definition at line 197 of file qgsfeaturerequest.cpp.
QgsFeatureRequest & QgsFeatureRequest::setOrderBy | ( | const OrderBy & | orderBy | ) |
Set a list of order by clauses.
Definition at line 172 of file qgsfeaturerequest.cpp.
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.
Definition at line 336 of file qgsfeaturerequest.cpp.
QgsFeatureRequest & QgsFeatureRequest::setSimplifyMethod | ( | const QgsSimplifyMethod & | simplifyMethod | ) |
Set a simplification method for geometries that will be fetched.
Definition at line 246 of file qgsfeaturerequest.cpp.
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.
Definition at line 190 of file qgsfeaturerequest.cpp.
QgsFeatureRequest & QgsFeatureRequest::setSubsetOfAttributes | ( | const QSet< QString > & | attrNames, |
const QgsFields & | fields | ||
) |
Sets a subset of attributes by names that will be fetched.
Definition at line 224 of file qgsfeaturerequest.cpp.
QgsFeatureRequest & QgsFeatureRequest::setSubsetOfAttributes | ( | const QStringList & | attrNames, |
const QgsFields & | fields | ||
) |
Sets a subset of attributes by names that will be fetched.
Definition at line 202 of file qgsfeaturerequest.cpp.
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.
Definition at line 325 of file qgsfeaturerequest.cpp.
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.
Definition at line 270 of file qgsfeaturerequest.cpp.
|
inline |
Gets simplification method for geometries that will be fetched.
Definition at line 557 of file qgsfeaturerequest.h.
|
inline |
Returns the subset of attributes which at least need to be fetched.
Definition at line 539 of file qgsfeaturerequest.h.
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.
Definition at line 320 of file qgsfeaturerequest.cpp.
QgsCoordinateTransformContext QgsFeatureRequest::transformContext | ( | ) | const |
Returns the transform context, for use when a destinationCrs() has been set and reprojection is required.
Definition at line 258 of file qgsfeaturerequest.cpp.
|
inline |
Returns the callback function to use when encountering a transform error when iterating features and a destinationCrs() is set.
Definition at line 639 of file qgsfeaturerequest.h.
|
static |
A special attribute that if set matches all attributes.
Definition at line 295 of file qgsfeaturerequest.h.
|
protected |
Definition at line 731 of file qgsfeaturerequest.h.
|
protected |
Definition at line 738 of file qgsfeaturerequest.h.
|
protected |
Definition at line 729 of file qgsfeaturerequest.h.
|
protected |
Definition at line 724 of file qgsfeaturerequest.h.
|
protected |
Definition at line 728 of file qgsfeaturerequest.h.
|
protected |
Definition at line 726 of file qgsfeaturerequest.h.
|
protected |
Definition at line 727 of file qgsfeaturerequest.h.
|
protected |
Definition at line 725 of file qgsfeaturerequest.h.
|
protected |
Definition at line 730 of file qgsfeaturerequest.h.
|
protected |
Definition at line 736 of file qgsfeaturerequest.h.
|
protected |
Definition at line 735 of file qgsfeaturerequest.h.
|
protected |
Definition at line 733 of file qgsfeaturerequest.h.
|
protected |
Definition at line 734 of file qgsfeaturerequest.h.
|
protected |
Definition at line 741 of file qgsfeaturerequest.h.
|
protected |
Definition at line 732 of file qgsfeaturerequest.h.
|
protected |
Definition at line 740 of file qgsfeaturerequest.h.
|
protected |
Definition at line 739 of file qgsfeaturerequest.h.
|
protected |
Definition at line 737 of file qgsfeaturerequest.h.