QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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>

Collaboration diagram for QgsFeatureRequest:
Collaboration graph
[legend]

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:

Definition at line 58 of file qgsfeaturerequest.h.

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.

Definition at line 70 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 61 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 32 of file qgsfeaturerequest.cpp.

QgsFeatureRequest::QgsFeatureRequest ( const QgsRectangle rect)
explicit

construct a request with rectangle filter

Definition at line 40 of file qgsfeaturerequest.cpp.

QgsFeatureRequest::QgsFeatureRequest ( const QgsExpression expr)
explicit

construct a request with a filter expression

Definition at line 48 of file qgsfeaturerequest.cpp.

QgsFeatureRequest::QgsFeatureRequest ( const QgsFeatureRequest rh)

copy constructor

Definition at line 55 of file qgsfeaturerequest.cpp.

References operator=().

QgsFeatureRequest::~QgsFeatureRequest ( )

Definition at line 80 of file qgsfeaturerequest.cpp.

References mFilterExpression.

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 154 of file qgsfeaturerequest.cpp.

References QgsExpression::evaluate(), FilterExpression, FilterFid, FilterFids, FilterNone, FilterRect, QgsFeature::geometry(), QgsFeature::id(), QgsGeometry::intersects(), mFilter, mFilterExpression, mFilterFid, mFilterFids, and mFilterRect.

Referenced by QgsAttributeTableModel::attributeValueChanged(), QgsAttributeTableModel::featureAdded(), QgsCachedFeatureIterator::fetchFeature(), and QgsVectorLayerFeatureIterator::fetchNextAddedFeature().

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}

Definition at line 106 of file qgsfeaturerequest.cpp.

References FilterExpression, mFilter, and mFilterExpression.

Referenced by QgsRelation::getRelatedFeaturesRequest().

QgsFeatureRequest & QgsFeatureRequest::setFilterFid ( QgsFeatureId  fid)
QgsFeatureRequest & QgsFeatureRequest::setFilterFids ( QgsFeatureIds  fids)

Set feature ID that should be fetched.

Definition at line 99 of file qgsfeaturerequest.cpp.

References FilterFids, mFilter, and mFilterFids.

Referenced by QgsVectorLayerFeatureIterator::QgsVectorLayerFeatureIterator().

QgsFeatureRequest & QgsFeatureRequest::setFilterRect ( const QgsRectangle rect)

Set rectangle from which features will be taken.

Empty rectangle removes the filter.

Definition at line 85 of file qgsfeaturerequest.cpp.

References FilterRect, mFilter, and mFilterRect.

Referenced by QgsComposerAttributeTable::getFeatureAttributes(), QgsVectorLayerRenderer::render(), QgsDxfExport::writeEntities(), and QgsDxfExport::writeEntitiesSymbolLevels().

QgsFeatureRequest & QgsFeatureRequest::setFlags ( Flags  flags)
QgsFeatureRequest & QgsFeatureRequest::setSimplifyMethod ( const QgsSimplifyMethod simplifyMethod)

Set a simplification method for geometries that will be fetched.

Note
added in 2.2

Definition at line 148 of file qgsfeaturerequest.cpp.

References mSimplifyMethod, and simplifyMethod().

Referenced by QgsVectorLayerRenderer::render().

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

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

Definition at line 127 of file qgsfeaturerequest.cpp.

References AllAttributes, QgsFields::fieldNameIndex(), mAttrs, mFlags, and SubsetOfAttributes.

const QgsSimplifyMethod& QgsFeatureRequest::simplifyMethod ( ) const
inline

Get simplification method for geometries that will be fetched.

Note
added in 2.2

Definition at line 132 of file qgsfeaturerequest.h.

Referenced by QgsAbstractFeatureIterator::ref(), and setSimplifyMethod().

const QgsAttributeList& QgsFeatureRequest::subsetOfAttributes ( ) const
inline

Member Data Documentation

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

Definition at line 156 of file qgsfeaturerequest.h.

Referenced by operator=(), and setSubsetOfAttributes().

FilterType QgsFeatureRequest::mFilter
protected
QgsExpression* QgsFeatureRequest::mFilterExpression
protected
QgsFeatureId QgsFeatureRequest::mFilterFid
protected

Definition at line 152 of file qgsfeaturerequest.h.

Referenced by acceptFeature(), operator=(), and setFilterFid().

QgsFeatureIds QgsFeatureRequest::mFilterFids
protected

Definition at line 153 of file qgsfeaturerequest.h.

Referenced by acceptFeature(), operator=(), and setFilterFids().

QgsRectangle QgsFeatureRequest::mFilterRect
protected

Definition at line 151 of file qgsfeaturerequest.h.

Referenced by acceptFeature(), operator=(), and setFilterRect().

Flags QgsFeatureRequest::mFlags
protected

Definition at line 155 of file qgsfeaturerequest.h.

Referenced by operator=(), setFlags(), and setSubsetOfAttributes().

QgsSimplifyMethod QgsFeatureRequest::mSimplifyMethod
protected

Definition at line 157 of file qgsfeaturerequest.h.

Referenced by operator=(), and setSimplifyMethod().


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