QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
21 #include <QStringList>
33 : mFilter( FilterFid )
39 : mFilter( FilterFids )
46 : mSpatialFilter( !rect.isNull() ?
Qgis::SpatialFilterType::BoundingBox :
Qgis::SpatialFilterType::NoFilter )
52 : mFilter( FilterExpression )
54 , mExpressionContext( context )
251 const auto constAttrNames = attrNames;
252 for (
const QString &attrName : constAttrNames )
254 const int attrNum = fields.
lookupField( attrName );
255 if ( attrNum != -1 && !
mAttrs.contains( attrNum ) )
273 const auto constAttrNames = attrNames;
274 for (
const QString &attrName : constAttrNames )
276 const int attrNum = fields.
lookupField( attrName );
277 if ( attrNum != -1 && !
mAttrs.contains( attrNum ) )
439 : mExpression( expression )
440 , mAscending( ascending )
447 : mExpression( expression )
448 , mAscending( ascending )
449 , mNullsFirst( nullsfirst )
454 : mExpression( expression )
455 , mAscending( ascending )
462 : mExpression( expression )
463 , mAscending( ascending )
464 , mNullsFirst( nullsfirst )
476 mAscending = ascending;
486 mNullsFirst = nullsFirst;
491 return QStringLiteral(
"%1 %2 %3" )
492 .arg( mExpression.expression(),
493 mAscending ?
"ASC" :
"DESC",
494 mNullsFirst ?
"NULLS FIRST" :
"NULLS LAST" );
504 return mExpression.prepare( context );
511 const auto constOther = other;
525 QDomDocument doc = elem.ownerDocument();
526 QList<OrderByClause>::ConstIterator it;
527 for ( it = constBegin(); it != constEnd(); ++it )
530 QDomElement clauseElem = doc.createElement( QStringLiteral(
"orderByClause" ) );
531 clauseElem.setAttribute( QStringLiteral(
"asc" ), clause.
ascending() );
532 clauseElem.setAttribute( QStringLiteral(
"nullsFirst" ), clause.
nullsFirst() );
535 elem.appendChild( clauseElem );
543 const QDomNodeList clauses = elem.childNodes();
545 for (
int i = 0; i < clauses.size(); ++i )
547 const QDomElement clauseElem = clauses.at( i ).toElement();
548 const QString expression = clauseElem.text();
549 const bool asc = clauseElem.attribute( QStringLiteral(
"asc" ) ).toInt() != 0;
550 const bool nullsFirst = clauseElem.attribute( QStringLiteral(
"nullsFirst" ) ).toInt() != 0;
558 QSet<QString> usedAttributes;
560 QList<OrderByClause>::ConstIterator it;
561 for ( it = constBegin(); it != constEnd(); ++it )
568 return usedAttributes;
573 QSet<int> usedAttributeIdx;
577 for (
const QString &fieldName : referencedColumns )
582 usedAttributeIdx.insert( idx );
586 return usedAttributeIdx;
593 QList<OrderByClause>::ConstIterator it;
594 for ( it = constBegin(); it != constEnd(); ++it )
598 results << clause.
dump();
601 return results.join( QLatin1String(
", " ) );
QgsSimplifyMethod mSimplifyMethod
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
The OrderByClause class represents an order by clause for a QgsFeatureRequest.
@ FilterFid
Filter using feature ID.
QgsExpression expression() const
The expression.
InvalidGeometryCheck mInvalidGeometryFilter
QgsFeatureRequest & setInvalidGeometryCheck(InvalidGeometryCheck check)
Sets invalid geometry checking behavior.
Contains information about the context in which a coordinate transform is executed.
This class contains information about how to simplify geometries fetched from a QgsFeatureIterator.
QgsFeatureIds mFilterFids
QgsFeatureRequest & addOrderBy(const QString &expression, bool ascending=true)
Adds a new OrderByClause, appending it as the least important one.
@ NoFilter
No spatial filtering of features.
QgsFeedback * feedback() const
Returns the feedback object that can be queried regularly by the iterator to check if it should be ca...
QgsCoordinateTransformContext transformContext() const
Returns the transform context, for use when a destinationCrs() has been set and reprojection is requi...
@ ExactIntersect
Use exact geometry intersection (slower) instead of bounding boxes.
bool acceptFeature(const QgsFeature &feature)
Check if a feature is accepted by this requests filter.
virtual ~QgsAbstractFeatureSource()
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
CORE_EXPORT OrderBy()
Create a new empty order by.
void setAscending(bool ascending)
Set if ascending order is requested.
#define QgsDebugMsgLevel(str, level)
void CORE_EXPORT save(QDomElement &elem) const
Serialize to XML.
QgsFeatureRequest & operator=(const QgsFeatureRequest &rh)
Assignment operator.
double mDistanceWithin
Maximum distance from reference geometry.
int timeout() const
Returns the timeout (in milliseconds) for the maximum time we should wait during feature requests bef...
const QgsCoordinateReferenceSystem & crs
QgsCoordinateReferenceSystem mCrs
Container of fields for a vector layer.
@ FilterFids
Filter using feature IDs.
QSet< QgsAbstractFeatureIterator * > mActiveIterators
QgsGeometry mReferenceGeometry
Reference geometry for Qgis::RequestSpatialFilter::DistanceWithin filtering.
QgsRectangle filterRect() const
Returns the rectangle from which features will be taken.
QgsFeatureRequest & setInvalidGeometryCallback(const std::function< void(const QgsFeature &)> &callback)
Sets a callback function to use when encountering an invalid geometry and invalidGeometryCheck() is s...
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for feature's geometries, or an invalid QgsCoordi...
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
InvalidGeometryCheck
Handling of features with invalid geometries.
QList< int > QgsAttributeList
bool prepare(QgsExpressionContext *context)
Prepare the expression with the given context.
A rectangle specified with double values.
@ SubsetOfAttributes
Fetch only a subset of attributes (setSubsetOfAttributes sets this flag)
QSet< QString > CORE_EXPORT usedAttributes() const
Returns a set of used attributes.
QgsFeatureRequest & setExpressionContext(const QgsExpressionContext &context)
Sets the expression context used to evaluate filter expressions.
QgsFeatureRequest & setFilterFid(QgsFeatureId fid)
Sets the feature ID that should be fetched.
Flags flags() const
Returns the flags which affect how features are fetched.
QgsFeatureRequest & setDistanceWithin(const QgsGeometry &geometry, double distance)
Sets a reference geometry and a maximum distance from this geometry to retrieve features within.
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
void setNullsFirst(bool nullsFirst)
Set if NULLS should be returned first.
QgsFeatureRequest()
construct a default request: for all features get attributes and geometries
QString dump() const
Dumps the content to an SQL equivalent.
QgsExpressionContext mExpressionContext
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
static const QString ALL_ATTRIBUTES
A special attribute that if set matches all attributes.
This class wraps a request for features to a vector layer (or directly its vector data provider).
bool intersects(const QgsRectangle &rectangle) const
Returns true if this geometry exactly intersects with a rectangle.
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 ...
std::unique_ptr< QgsExpression > mFilterExpression
QgsFeatureRequest & combineFilterExpression(const QString &expression)
Modifies the existing filter expression to add an additional expression filter.
long long limit() const
Returns the maximum number of features to request, or -1 if no limit set.
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 des...
bool ascending() const
Order ascending.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
void CORE_EXPORT load(const QDomElement &elem)
Deserialize from XML.
bool requestMayBeNested() const
In case this request may be run nested within another already running iteration on the same connectio...
QgsFeatureRequest & setFilterFids(const QgsFeatureIds &fids)
Sets the feature IDs that should be fetched.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
void setFeedback(QgsFeedback *feedback)
Attach a feedback object that can be queried regularly by the iterator to check if it should be cance...
void iteratorClosed(QgsAbstractFeatureIterator *it)
std::shared_ptr< QgsGeometryEngine > mReferenceGeometryEngine
Prepared geometry engine for mReferenceGeometry.
QgsRectangle mFilterRect
Bounding box for spatial filtering.
QgsCoordinateTransformContext mTransformContext
QgsFeatureRequest & setSimplifyMethod(const QgsSimplifyMethod &simplifyMethod)
Set a simplification method for geometries that will be fetched.
@ FilterExpression
Filter using expression.
QgsRectangle buffered(double width) const
Gets rectangle enlarged by buffer.
QgsFeatureRequest & setTimeout(int timeout)
Sets the timeout (in milliseconds) for the maximum time we should wait during feature requests before...
QgsFeatureRequest & setNoAttributes()
Set that no attributes will be fetched.
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QSet< QgsFeatureId > QgsFeatureIds
This class represents a coordinate reference system (CRS).
QSet< int > CORE_EXPORT usedAttributeIndices(const QgsFields &fields) const
Returns a set of used, validated attribute indices.
std::function< void(const QgsFeature &) > mInvalidGeometryCallback
OrderByClause(const QString &expression, bool ascending=true)
Creates a new OrderByClause for a QgsFeatureRequest.
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry)
Creates and returns a new geometry engine representing the specified geometry.
bool nullsFirst() const
Set if NULLS should be returned first.
QgsFeatureRequest & setRequestMayBeNested(bool requestMayBeNested)
In case this request may be run nested within another already running iteration on the same connectio...
Represents a list of OrderByClauses, with the most important first and the least important last.
A geometry is the spatial representation of a feature.
OrderBy orderBy() const
Returns a list of order by clauses specified for this feature request.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
QgsFeatureRequest & setLimit(long long limit)
Set the maximum number of features to request.
@ BoundingBox
Filter using a bounding box.
QList< QgsFeatureRequest::OrderByClause > CORE_EXPORT list() const
Gets a copy as a list of OrderByClauses.
void iteratorOpened(QgsAbstractFeatureIterator *it)
QString CORE_EXPORT dump() const
Dumps the content to an SQL equivalent syntax.
std::function< void(const QgsFeature &) > mTransformErrorCallback
const QgsSimplifyMethod & simplifyMethod() const
Returns the simplification method for geometries that will be fetched.
QgsFeatureRequest & setOrderBy(const OrderBy &orderBy)
Set a list of order by clauses.
Qgis::SpatialFilterType mSpatialFilter
Spatial filter type.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
Q_DECL_DEPRECATED int connectionTimeout() const
Returns the timeout (in milliseconds) for how long we should wait for a connection if none is availab...
The Qgis class provides global constants for use throughout the application.
@ FilterNone
No filter is applied.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
QgsFeatureRequest & setDestinationCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets the destination crs for feature's geometries.
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
Class for parsing and evaluation of expressions (formerly called "search strings")....
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
Internal feature iterator to be implemented within data providers.
QString expression() const
Returns the original, unmodified expression string.
virtual bool close()=0
end of iterating: free the resources / lock
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
bool boundingBoxIntersects(const QgsRectangle &rectangle) const
Returns true if the bounding box of this geometry intersects with a rectangle.
FilterType mFilter
Attribute/ID filter type.
@ DistanceWithin
Filter by distance to reference geometry.
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.