QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsaggregatecalculator.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsaggregatecalculator.h
3  ------------------------
4  begin : May 2016
5  copyright : (C) 2016 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSAGGREGATECALCULATOR_H
19 #define QGSAGGREGATECALCULATOR_H
20 
21 #include "qgsstatisticalsummary.h"
24 #include <QVariant>
25 
26 
27 class QgsFeatureIterator;
28 class QgsExpression;
29 class QgsVectorLayer;
31 
40 class CORE_EXPORT QgsAggregateCalculator
41 {
42  public:
43 
46  enum Aggregate
47  {
51  Min,
52  Max,
53  Sum,
54  Mean,
67  };
68 
71  {
78 
84  };
85 
90 
93  QgsVectorLayer* layer() const;
94 
98  void setParameters( const AggregateParameters& parameters );
99 
104  void setFilter( const QString& filterExpression ) { mFilterExpression = filterExpression; }
105 
109  QString filter() const { return mFilterExpression; }
110 
115  void setDelimiter( const QString& delimiter ) { mDelimiter = delimiter; }
116 
120  QString delimiter() const { return mDelimiter; }
121 
130  QVariant calculate( Aggregate aggregate, const QString& fieldOrExpression,
131  QgsExpressionContext* context = nullptr, bool* ok = nullptr ) const;
132 
138  static Aggregate stringToAggregate( const QString& string, bool* ok = nullptr );
139 
140  private:
141 
143  QgsVectorLayer* mLayer;
144 
146  QString mFilterExpression;
147 
149  QString mDelimiter;
150 
151  static QgsStatisticalSummary::Statistic numericStatFromAggregate( Aggregate aggregate, bool* ok = nullptr );
152  static QgsStringStatisticalSummary::Statistic stringStatFromAggregate( Aggregate aggregate, bool* ok = nullptr );
153  static QgsDateTimeStatisticalSummary::Statistic dateTimeStatFromAggregate( Aggregate aggregate, bool* ok = nullptr );
154 
155  static QVariant calculateNumericAggregate( QgsFeatureIterator& fit, int attr, QgsExpression* expression,
157 
158  static QVariant calculateStringAggregate( QgsFeatureIterator& fit, int attr, QgsExpression* expression,
160 
161  static QVariant calculateDateTimeAggregate( QgsFeatureIterator& fit, int attr, QgsExpression* expression,
163 
164  QgsExpressionContext* createContext() const;
165 
166  static QVariant calculate( Aggregate aggregate, QgsFeatureIterator& fit, QVariant::Type resultType,
167  int attr, QgsExpression* expression,
168  const QString& delimiter,
169  QgsExpressionContext* context, bool* ok = nullptr );
170  static QVariant concatenateStrings( QgsFeatureIterator& fit, int attr, QgsExpression* expression,
171  QgsExpressionContext* context, const QString& delimiter );
172 
173  QVariant defaultValue( Aggregate aggregate ) const;
174 };
175 
176 #endif //QGSAGGREGATECALCULATOR_H
177 
Class for parsing and evaluation of expressions (formerly called "search strings").
Wrapper for iterator of features from vector data provider or vector layer.
Third quartile (numeric fields only)
Inter quartile range (IQR) (numeric fields only)
Median of values (numeric fields only)
void setDelimiter(const QString &delimiter)
Sets the delimiter to use for joining values with the StringConcatenate aggregate.
Statistic
Enumeration of flags that specify statistics to be calculated.
void setFilter(const QString &filterExpression)
Sets a filter to limit the features used during the aggregate calculation.
First quartile (numeric fields only)
Number of missing (null) values.
Statistic
Enumeration of flags that specify statistics to be calculated.
Utility class for calculating aggregates for a field (or expression) over the features from a vector ...
Standard deviation of values (numeric fields only)
QString delimiter
Delimiter to use for joining values with the StringConcatenate aggregate.
Minimum length of string (string fields only)
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Statistic
Enumeration of flags that specify statistics to be calculated.
QString filter() const
Returns the filter which limits the features used during the aggregate calculation.
Majority of values (numeric fields only)
QString delimiter() const
Returns the delimiter used for joining values with the StringConcatenate aggregate.
Maximum length of string (string fields only)
QString filter
Optional filter for calculating aggregate over a subset of features, or an empty string to use all fe...
Mean of values (numeric fields only)
Minority of values (numeric fields only)
Represents a vector layer which manages a vector based data sets.
Range of values (max - min) (numeric and datetime fields only)
Sample standard deviation of values (numeric fields only)
Aggregate
Available aggregates to calculate.
A bundle of parameters controlling aggregate calculation.