QGIS API Documentation
2.18.21-Las Palmas (9fba24a)
|
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 Types | |
enum | FilterType { FilterNone, FilterRect, FilterFid, FilterExpression, FilterFids } |
Types of filters. More... | |
enum | Flag { NoFlags = 0, NoGeometry = 1, SubsetOfAttributes = 2, ExactIntersect = 4 } |
Public Member Functions | |
QgsFeatureRequest () | |
construct a default request: for all features get attributes and geometries More... | |
QgsFeatureRequest (QgsFeatureId fid) | |
construct a request with feature ID filter More... | |
QgsFeatureRequest (const QgsRectangle &rect) | |
construct a request with rectangle filter More... | |
QgsFeatureRequest (const QgsExpression &expr, const QgsExpressionContext &context=QgsExpressionContext()) | |
construct a request with a filter expression More... | |
QgsFeatureRequest (const QgsFeatureRequest &rh) | |
copy constructor More... | |
~QgsFeatureRequest () | |
bool | acceptFeature (const QgsFeature &feature) |
Check if a feature is accepted by this requests filter. More... | |
QgsFeatureRequest & | addOrderBy (const QString &expression, bool ascending=true) |
Adds a new OrderByClause, appending it as the least important one. More... | |
QgsFeatureRequest & | addOrderBy (const QString &expression, bool ascending, bool nullsfirst) |
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... | |
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 |
Get the feature ID that should be fetched. More... | |
const QgsFeatureIds & | filterFids () const |
Get feature IDs that should be fetched. More... | |
const QgsRectangle & | filterRect () const |
Get the rectangle from which features will be taken. More... | |
FilterType | filterType () const |
Return the filter type which is currently set on this request. More... | |
const Flags & | flags () const |
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 |
Return a list of order by clauses specified for this feature request. 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) |
Set feature ID that should be fetched. More... | |
QgsFeatureRequest & | setFilterFids (const QgsFeatureIds &fids) |
Set feature IDs that should be fetched. More... | |
QgsFeatureRequest & | setFilterRect (const QgsRectangle &rect) |
Set rectangle from which features will be taken. More... | |
QgsFeatureRequest & | setFlags (const QgsFeatureRequest::Flags &flags) |
Set flags that affect how features will be fetched. More... | |
QgsFeatureRequest & | setLimit (long limit) |
Set the maximum number of features to request. More... | |
QgsFeatureRequest & | setOrderBy (const OrderBy &orderBy) |
Set a list of order by clauses. 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 QStringList &attrNames, const QgsFields &fields) |
Set a subset of attributes by names that will be fetched. More... | |
const QgsSimplifyMethod & | simplifyMethod () const |
Get simplification method for geometries that will be fetched. More... | |
QgsAttributeList | subsetOfAttributes () const |
Return the subset of attributes which at least need to be fetched. More... | |
Static Public Attributes | |
static const QString | AllAttributes = QString( "#!allattributes!#" ) |
A special attribute that if set matches all attributes. More... | |
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.: QgsFeatureRequest().setFilterRect(QgsRectangle(0,0,1,1)).setFlags(QgsFeatureRequest::ExactIntersect)
Examples:
Definition at line 63 of file qgsfeaturerequest.h.
Types of filters.
Enumerator | |
---|---|
FilterNone | No filter is applied. |
FilterRect | Obsolete, will be ignored. If a filterRect is set it will be used anyway. Filter using a rectangle, no need to set NoGeometry. Instead check for request.filterRect().isNull() |
FilterFid | Filter using feature ID. |
FilterExpression | Filter using expression. |
FilterFids | Filter using feature IDs. |
Definition at line 78 of file qgsfeaturerequest.h.
Definition at line 66 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 34 of file qgsfeaturerequest.cpp.
|
explicit |
construct a request with rectangle filter
Definition at line 43 of file qgsfeaturerequest.cpp.
|
explicit |
construct a request with a filter expression
Definition at line 53 of file qgsfeaturerequest.cpp.
QgsFeatureRequest::QgsFeatureRequest | ( | const QgsFeatureRequest & | rh | ) |
copy constructor
Definition at line 63 of file qgsfeaturerequest.cpp.
QgsFeatureRequest::~QgsFeatureRequest | ( | ) |
Definition at line 91 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 |
Definition at line 214 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 145 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 151 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 126 of file qgsfeaturerequest.cpp.
|
inline |
Disables filter conditions.
The spatial filter (filterRect) will be kept in place.
Definition at line 310 of file qgsfeaturerequest.h.
|
inline |
Returns the expression context used to evaluate filter expressions.
Definition at line 293 of file qgsfeaturerequest.h.
|
inline |
Returns the filter expression if set.
Definition at line 279 of file qgsfeaturerequest.h.
|
inline |
Get the feature ID that should be fetched.
Definition at line 261 of file qgsfeaturerequest.h.
|
inline |
Get feature IDs that should be fetched.
Definition at line 266 of file qgsfeaturerequest.h.
|
inline |
Get the rectangle from which features will be taken.
Definition at line 256 of file qgsfeaturerequest.h.
|
inline |
Return the filter type which is currently set on this request.
Definition at line 246 of file qgsfeaturerequest.h.
|
inline |
Definition at line 364 of file qgsfeaturerequest.h.
|
inline |
Returns the maximum number of features to request, or -1 if no limit set.
Definition at line 360 of file qgsfeaturerequest.h.
QgsFeatureRequest & QgsFeatureRequest::operator= | ( | const QgsFeatureRequest & | rh | ) |
Assignment operator.
Definition at line 68 of file qgsfeaturerequest.cpp.
QgsFeatureRequest::OrderBy QgsFeatureRequest::orderBy | ( | ) | const |
Return a list of order by clauses specified for this feature request.
Definition at line 157 of file qgsfeaturerequest.cpp.
QgsFeatureRequest & QgsFeatureRequest::setExpressionContext | ( | const QgsExpressionContext & | context | ) |
Sets the expression context used to evaluate filter expressions.
Definition at line 139 of file qgsfeaturerequest.cpp.
QgsFeatureRequest & QgsFeatureRequest::setFilterExpression | ( | const QString & | expression | ) |
Set the filter expression.
{
expression | expression string |
Definition at line 118 of file qgsfeaturerequest.cpp.
QgsFeatureRequest & QgsFeatureRequest::setFilterFid | ( | QgsFeatureId | fid | ) |
Set feature ID that should be fetched.
Definition at line 104 of file qgsfeaturerequest.cpp.
QgsFeatureRequest & QgsFeatureRequest::setFilterFids | ( | const QgsFeatureIds & | fids | ) |
Set feature IDs that should be fetched.
Definition at line 111 of file qgsfeaturerequest.cpp.
QgsFeatureRequest & QgsFeatureRequest::setFilterRect | ( | const QgsRectangle & | rect | ) |
Set rectangle from which features will be taken.
Empty rectangle removes the filter.
Definition at line 96 of file qgsfeaturerequest.cpp.
QgsFeatureRequest & QgsFeatureRequest::setFlags | ( | const QgsFeatureRequest::Flags & | flags | ) |
Set flags that affect how features will be fetched.
Definition at line 174 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 168 of file qgsfeaturerequest.cpp.
QgsFeatureRequest & QgsFeatureRequest::setOrderBy | ( | const OrderBy & | orderBy | ) |
Set a list of order by clauses.
Definition at line 162 of file qgsfeaturerequest.cpp.
QgsFeatureRequest & QgsFeatureRequest::setSimplifyMethod | ( | const QgsSimplifyMethod & | simplifyMethod | ) |
Set a simplification method for geometries that will be fetched.
Definition at line 208 of file qgsfeaturerequest.cpp.
QgsFeatureRequest & QgsFeatureRequest::setSubsetOfAttributes | ( | const QgsAttributeList & | attrs | ) |
Set a subset of attributes that will be fetched.
Empty list means that all attributes are used. To disable fetching attributes, reset the FetchAttributes flag (which is set by default)
Definition at line 180 of file qgsfeaturerequest.cpp.
QgsFeatureRequest & QgsFeatureRequest::setSubsetOfAttributes | ( | const QStringList & | attrNames, |
const QgsFields & | fields | ||
) |
Set a subset of attributes by names that will be fetched.
Definition at line 187 of file qgsfeaturerequest.cpp.
|
inline |
Get simplification method for geometries that will be fetched.
Definition at line 383 of file qgsfeaturerequest.h.
|
inline |
Return the subset of attributes which at least need to be fetched.
Definition at line 373 of file qgsfeaturerequest.h.
A special attribute that if set matches all attributes.
Definition at line 224 of file qgsfeaturerequest.h.
|
protected |
Definition at line 407 of file qgsfeaturerequest.h.
|
protected |
Definition at line 405 of file qgsfeaturerequest.h.
|
protected |
Definition at line 400 of file qgsfeaturerequest.h.
|
protected |
Definition at line 404 of file qgsfeaturerequest.h.
|
protected |
Definition at line 402 of file qgsfeaturerequest.h.
|
protected |
Definition at line 403 of file qgsfeaturerequest.h.
|
protected |
Definition at line 401 of file qgsfeaturerequest.h.
|
protected |
Definition at line 406 of file qgsfeaturerequest.h.
|
protected |
Definition at line 409 of file qgsfeaturerequest.h.
|
protected |
Definition at line 410 of file qgsfeaturerequest.h.
|
protected |
Definition at line 408 of file qgsfeaturerequest.h.