QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  Flag { NoFlags = 0, NoGeometry = 1, SubsetOfAttributes = 2, ExactIntersect = 4 }
 
enum  FilterType {
  FilterNone, FilterRect, FilterFid, FilterExpression,
  FilterFids
}
 

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)
 construct a request with a filter expression More...
 
 QgsFeatureRequest (const QgsFeatureRequest &rh)
 copy constructor More...
 
QgsFeatureRequestoperator= (const QgsFeatureRequest &rh)
 
 ~QgsFeatureRequest ()
 
FilterType filterType () const
 
QgsFeatureRequestsetFilterRect (const QgsRectangle &rect)
 Set rectangle from which features will be taken. More...
 
const QgsRectanglefilterRect () const
 
QgsFeatureRequestsetFilterFid (QgsFeatureId fid)
 Set feature ID that should be fetched. More...
 
const QgsFeatureIdfilterFid () const
 
QgsFeatureRequestsetFilterFids (QgsFeatureIds fids)
 Set feature ID that should be fetched. More...
 
const QgsFeatureIdsfilterFids () const
 
QgsFeatureRequestsetFilterExpression (const QString &expression)
 Set filter expression. {. More...
 
QgsExpressionfilterExpression () const
 
QgsFeatureRequestsetFlags (Flags flags)
 Set flags that affect how features will be fetched. More...
 
const Flags & flags () const
 
QgsFeatureRequestsetSubsetOfAttributes (const QgsAttributeList &attrs)
 Set a subset of attributes that will be fetched. More...
 
const QgsAttributeListsubsetOfAttributes () const
 
QgsFeatureRequestsetSubsetOfAttributes (const QStringList &attrNames, const QgsFields &fields)
 Set a subset of attributes by names that will be fetched. More...
 
QgsFeatureRequestsetSimplifyMethod (const QgsSimplifyMethod &simplifyMethod)
 Set a simplification method for geometries that will be fetched. More...
 
const QgsSimplifyMethodsimplifyMethod () const
 Get simplification method for geometries that will be fetched. More...
 
bool acceptFeature (const QgsFeature &feature)
 Check if a feature is accepted by this requests filter. More...
 

Static Public Attributes

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

Protected Attributes

FilterType mFilter
 
QgsRectangle mFilterRect
 
QgsFeatureId mFilterFid
 
QgsFeatureIds mFilterFids
 
QgsExpressionmFilterExpression
 
Flags mFlags
 
QgsAttributeList mAttrs
 
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:

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:

Member Enumeration Documentation

Enumerator
FilterNone 

No filter is applied.

FilterRect 

Filter using a rectangle, no need to set NoGeometry.

FilterFid 

Filter using feature ID.

FilterExpression 

Filter using expression.

FilterFids 

Filter using feature IDs.

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.

Constructor & Destructor Documentation

QgsFeatureRequest::QgsFeatureRequest ( )

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

QgsFeatureRequest::QgsFeatureRequest ( QgsFeatureId  fid)
explicit

construct a request with feature ID filter

QgsFeatureRequest::QgsFeatureRequest ( const QgsRectangle rect)
explicit

construct a request with rectangle filter

QgsFeatureRequest::QgsFeatureRequest ( const QgsExpression expr)
explicit

construct a request with a filter expression

QgsFeatureRequest::QgsFeatureRequest ( const QgsFeatureRequest rh)

copy constructor

QgsFeatureRequest::~QgsFeatureRequest ( )

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
QgsExpression* QgsFeatureRequest::filterExpression ( ) const
inline
const QgsFeatureId& QgsFeatureRequest::filterFid ( ) const
inline
const QgsFeatureIds& QgsFeatureRequest::filterFids ( ) const
inline
const QgsRectangle& QgsFeatureRequest::filterRect ( ) const
inline
FilterType QgsFeatureRequest::filterType ( ) const
inline
const Flags& QgsFeatureRequest::flags ( ) const
inline
QgsFeatureRequest & QgsFeatureRequest::operator= ( const QgsFeatureRequest rh)
QgsFeatureRequest & QgsFeatureRequest::setFilterExpression ( const QString &  expression)

Set filter expression. {.

See also
QgsExpression}
QgsFeatureRequest & QgsFeatureRequest::setFilterFid ( QgsFeatureId  fid)

Set feature ID that should be fetched.

QgsFeatureRequest & QgsFeatureRequest::setFilterFids ( QgsFeatureIds  fids)

Set feature ID that should be fetched.

QgsFeatureRequest & QgsFeatureRequest::setFilterRect ( const QgsRectangle rect)

Set rectangle from which features will be taken.

Empty rectangle removes the filter.

QgsFeatureRequest & QgsFeatureRequest::setFlags ( Flags  flags)

Set flags that affect how features will be fetched.

QgsFeatureRequest & QgsFeatureRequest::setSimplifyMethod ( const QgsSimplifyMethod simplifyMethod)

Set a simplification method for geometries that will be fetched.

Note
added in 2.2
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)

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

Set a subset of attributes by names that will be fetched.

const QgsSimplifyMethod& QgsFeatureRequest::simplifyMethod ( ) const
inline

Get simplification method for geometries that will be fetched.

Note
added in 2.2
const QgsAttributeList& QgsFeatureRequest::subsetOfAttributes ( ) const
inline

Member Data Documentation

const QString QgsFeatureRequest::AllAttributes = QString( "#!allattributes!#" )
static
QgsAttributeList QgsFeatureRequest::mAttrs
protected
FilterType QgsFeatureRequest::mFilter
protected
QgsExpression* QgsFeatureRequest::mFilterExpression
protected
QgsFeatureId QgsFeatureRequest::mFilterFid
protected
QgsFeatureIds QgsFeatureRequest::mFilterFids
protected
QgsRectangle QgsFeatureRequest::mFilterRect
protected
Flags QgsFeatureRequest::mFlags
protected
QgsSimplifyMethod QgsFeatureRequest::mSimplifyMethod
protected

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