QGIS API Documentation  2.12.0-Lyon
Public Types | 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>

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...
 
QgsFeatureRequestdisableFilter ()
 Disables filter conditions. More...
 
QgsExpressionContextexpressionContext ()
 Returns the expression context used to evaluate filter expressions. More...
 
QgsExpressionfilterExpression () const
 Returns the filter expression if set. More...
 
const QgsFeatureIdfilterFid () const
 Get the feature ID that should be fetched. More...
 
const QgsFeatureIdsfilterFids () const
 Get feature IDs that should be fetched. More...
 
const QgsRectanglefilterRect () 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
 
QgsFeatureRequestoperator= (const QgsFeatureRequest &rh)
 Assignment operator. More...
 
QgsFeatureRequestsetExpressionContext (const QgsExpressionContext &context)
 Sets the expression context used to evaluate filter expressions. More...
 
QgsFeatureRequestsetFilterExpression (const QString &expression)
 Set the filter expression. More...
 
QgsFeatureRequestsetFilterFid (QgsFeatureId fid)
 Set feature ID that should be fetched. More...
 
QgsFeatureRequestsetFilterFids (const QgsFeatureIds &fids)
 Set feature IDs that should be fetched. More...
 
QgsFeatureRequestsetFilterRect (const QgsRectangle &rect)
 Set rectangle from which features will be taken. More...
 
QgsFeatureRequestsetFlags (const QgsFeatureRequest::Flags &flags)
 Set flags that affect how features will be fetched. More...
 
QgsFeatureRequestsetSimplifyMethod (const QgsSimplifyMethod &simplifyMethod)
 Set a simplification method for geometries that will be fetched. More...
 
QgsFeatureRequestsetSubsetOfAttributes (const QgsAttributeList &attrs)
 Set a subset of attributes that will be fetched. More...
 
QgsFeatureRequestsetSubsetOfAttributes (const QStringList &attrNames, const QgsFields &fields)
 Set a subset of attributes by names that will be fetched. More...
 
const QgsSimplifyMethodsimplifyMethod () const
 Get simplification method for geometries that will be fetched. More...
 
const QgsAttributeListsubsetOfAttributes () 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...
 

Protected Attributes

QgsAttributeList mAttrs
 
QgsExpressionContext mExpressionContext
 
FilterType mFilter
 
QgsExpressionmFilterExpression
 
QgsFeatureId mFilterFid
 
QgsFeatureIds mFilterFids
 
QgsRectangle mFilterRect
 
Flags mFlags
 
QgsSimplifyMethod mSimplifyMethod
 

Detailed Description

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.

Member Enumeration Documentation

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.

Enumerator
NoFlags 
NoGeometry 

Geometry is not required. It may still be returned if e.g. required for a filter condition.

SubsetOfAttributes 

Fetch only a subset of attributes (setSubsetOfAttributes sets this flag)

ExactIntersect 

Use exact geometry intersection (slower) instead of bounding boxes.

Definition at line 66 of file qgsfeaturerequest.h.

Constructor & Destructor Documentation

QgsFeatureRequest::QgsFeatureRequest ( )

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

Definition at line 25 of file qgsfeaturerequest.cpp.

QgsFeatureRequest::QgsFeatureRequest ( QgsFeatureId  fid)
explicit

construct a request with feature ID filter

Definition at line 33 of file qgsfeaturerequest.cpp.

QgsFeatureRequest::QgsFeatureRequest ( const QgsRectangle rect)
explicit

construct a request with rectangle filter

Definition at line 41 of file qgsfeaturerequest.cpp.

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

construct a request with a filter expression

Definition at line 50 of file qgsfeaturerequest.cpp.

QgsFeatureRequest::QgsFeatureRequest ( const QgsFeatureRequest rh)

copy constructor

Definition at line 59 of file qgsfeaturerequest.cpp.

QgsFeatureRequest::~QgsFeatureRequest ( )

Definition at line 85 of file qgsfeaturerequest.cpp.

Member Function Documentation

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
Note
added in 2.1

Definition at line 166 of file qgsfeaturerequest.cpp.

QgsFeatureRequest& QgsFeatureRequest::disableFilter ( )
inline

Disables filter conditions.

The spatial filter (filterRect) will be kept in place.

Returns
The object the method is called on for chaining
Note
Added in 2.12

Definition at line 169 of file qgsfeaturerequest.h.

QgsExpressionContext* QgsFeatureRequest::expressionContext ( )
inline

Returns the expression context used to evaluate filter expressions.

Note
added in QGIS 2.12
See also
setExpressionContext
filterExpression

Definition at line 152 of file qgsfeaturerequest.h.

QgsExpression* QgsFeatureRequest::filterExpression ( ) const
inline

Returns the filter expression if set.

See also
setFilterExpression
expressionContext

Definition at line 145 of file qgsfeaturerequest.h.

const QgsFeatureId& QgsFeatureRequest::filterFid ( ) const
inline

Get the feature ID that should be fetched.

Definition at line 127 of file qgsfeaturerequest.h.

const QgsFeatureIds& QgsFeatureRequest::filterFids ( ) const
inline

Get feature IDs that should be fetched.

Definition at line 132 of file qgsfeaturerequest.h.

const QgsRectangle& QgsFeatureRequest::filterRect ( ) const
inline

Get the rectangle from which features will be taken.

Definition at line 122 of file qgsfeaturerequest.h.

FilterType QgsFeatureRequest::filterType ( ) const
inline

Return the filter type which is currently set on this request.

Returns
Filter type

Definition at line 112 of file qgsfeaturerequest.h.

const Flags& QgsFeatureRequest::flags ( ) const
inline

Definition at line 173 of file qgsfeaturerequest.h.

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

Assignment operator.

Definition at line 64 of file qgsfeaturerequest.cpp.

QgsFeatureRequest & QgsFeatureRequest::setExpressionContext ( const QgsExpressionContext context)

Sets the expression context used to evaluate filter expressions.

Note
added in QGIS 2.12
See also
expressionContext
setFilterExpression

Definition at line 120 of file qgsfeaturerequest.cpp.

QgsFeatureRequest & QgsFeatureRequest::setFilterExpression ( const QString expression)

Set the filter expression.

{

See also
QgsExpression}
Parameters
expressionexpression string
See also
filterExpression
setExpressionContext

Definition at line 112 of file qgsfeaturerequest.cpp.

QgsFeatureRequest & QgsFeatureRequest::setFilterFid ( QgsFeatureId  fid)

Set feature ID that should be fetched.

Definition at line 98 of file qgsfeaturerequest.cpp.

QgsFeatureRequest & QgsFeatureRequest::setFilterFids ( const QgsFeatureIds fids)

Set feature IDs that should be fetched.

Definition at line 105 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 90 of file qgsfeaturerequest.cpp.

QgsFeatureRequest & QgsFeatureRequest::setFlags ( const QgsFeatureRequest::Flags &  flags)

Set flags that affect how features will be fetched.

Definition at line 126 of file qgsfeaturerequest.cpp.

QgsFeatureRequest & QgsFeatureRequest::setSimplifyMethod ( const QgsSimplifyMethod simplifyMethod)

Set a simplification method for geometries that will be fetched.

Note
added in 2.2

Definition at line 160 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 132 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 139 of file qgsfeaturerequest.cpp.

const QgsSimplifyMethod& QgsFeatureRequest::simplifyMethod ( ) const
inline

Get simplification method for geometries that will be fetched.

Note
added in 2.2

Definition at line 192 of file qgsfeaturerequest.h.

const QgsAttributeList& QgsFeatureRequest::subsetOfAttributes ( ) const
inline

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

Returns
A list of attributes to be fetched

Definition at line 182 of file qgsfeaturerequest.h.

Member Data Documentation

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

A special attribute that if set matches all attributes.

Definition at line 90 of file qgsfeaturerequest.h.

QgsAttributeList QgsFeatureRequest::mAttrs
protected

Definition at line 217 of file qgsfeaturerequest.h.

QgsExpressionContext QgsFeatureRequest::mExpressionContext
protected

Definition at line 215 of file qgsfeaturerequest.h.

FilterType QgsFeatureRequest::mFilter
protected

Definition at line 210 of file qgsfeaturerequest.h.

QgsExpression* QgsFeatureRequest::mFilterExpression
protected

Definition at line 214 of file qgsfeaturerequest.h.

QgsFeatureId QgsFeatureRequest::mFilterFid
protected

Definition at line 212 of file qgsfeaturerequest.h.

QgsFeatureIds QgsFeatureRequest::mFilterFids
protected

Definition at line 213 of file qgsfeaturerequest.h.

QgsRectangle QgsFeatureRequest::mFilterRect
protected

Definition at line 211 of file qgsfeaturerequest.h.

Flags QgsFeatureRequest::mFlags
protected

Definition at line 216 of file qgsfeaturerequest.h.

QgsSimplifyMethod QgsFeatureRequest::mSimplifyMethod
protected

Definition at line 218 of file qgsfeaturerequest.h.


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