QGIS API Documentation 3.43.0-Master (e01d6d7c4c0)
qgsalgorithmbasicstatistics.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmbasicstatistics.cpp
3 ------------------------------
4 begin : June 2024
5 copyright : (C) 2024 by Alexander Bruy
6 email : alexander dot bruy 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
22
23
25
26QString QgsBasicStatisticsAlgorithm::name() const
27{
28 return QStringLiteral( "basicstatisticsforfields" );
29}
30
31QString QgsBasicStatisticsAlgorithm::displayName() const
32{
33 return QObject::tr( "Basic statistics for fields" );
34}
35
36QStringList QgsBasicStatisticsAlgorithm::tags() const
37{
38 return QObject::tr( "stats,statistics,date,time,datetime,string,number,text,table,layer,sum,maximum,minimum,mean,average,standard,deviation,count,distinct,unique,variance,median,quartile,range,majority,minority,summary" ).split( ',' );
39}
40
41QString QgsBasicStatisticsAlgorithm::group() const
42{
43 return QObject::tr( "Vector analysis" );
44}
45
46QString QgsBasicStatisticsAlgorithm::groupId() const
47{
48 return QStringLiteral( "vectoranalysis" );
49}
50
51QString QgsBasicStatisticsAlgorithm::shortHelpString() const
52{
53 return QObject::tr( "This algorithm generates basic statistics from the analysis of values in a field in the attribute table of a vector layer. Numeric, date, time and string fields are supported. The statistics returned will depend on the field type." );
54}
55
56QString QgsBasicStatisticsAlgorithm::shortDescription() const
57{
58 return QObject::tr( "Generates basic statistics from the values in a field of a vector layer." );
59}
60
61QgsBasicStatisticsAlgorithm *QgsBasicStatisticsAlgorithm::createInstance() const
62{
63 return new QgsBasicStatisticsAlgorithm();
64}
65
66void QgsBasicStatisticsAlgorithm::initAlgorithm( const QVariantMap & )
67{
68 addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "INPUT_LAYER" ), QObject::tr( "Input layer" ), QList<int>() << static_cast<int>( Qgis::ProcessingSourceType::Vector ) ) );
69 addParameter( new QgsProcessingParameterField( QStringLiteral( "FIELD_NAME" ), QObject::tr( "Field to calculate statistics on" ), QVariant(), QStringLiteral( "INPUT_LAYER" ) ) );
70 addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Statistics" ), Qgis::ProcessingSourceType::Vector, QVariant(), true ) );
71 addParameter( new QgsProcessingParameterFileDestination( QStringLiteral( "OUTPUT_HTML_FILE" ), QObject::tr( "Statistics report" ), QObject::tr( "'HTML files (*.html)" ), QVariant(), true ) );
72
73 addOutput( new QgsProcessingOutputNumber( QStringLiteral( "COUNT" ), QObject::tr( "Count" ) ) );
74 addOutput( new QgsProcessingOutputNumber( QStringLiteral( "UNIQUE" ), QObject::tr( "Number of unique values" ) ) );
75 addOutput( new QgsProcessingOutputNumber( QStringLiteral( "EMPTY" ), QObject::tr( "Number of empty (null) values" ) ) );
76 addOutput( new QgsProcessingOutputNumber( QStringLiteral( "FILLED" ), QObject::tr( "Number of non-empty values" ) ) );
77 addOutput( new QgsProcessingOutputNumber( QStringLiteral( "MIN" ), QObject::tr( "Minimum value" ) ) );
78 addOutput( new QgsProcessingOutputNumber( QStringLiteral( "MAX" ), QObject::tr( "Maximum value" ) ) );
79 addOutput( new QgsProcessingOutputNumber( QStringLiteral( "MIN_LENGTH" ), QObject::tr( "Minimum length" ) ) );
80 addOutput( new QgsProcessingOutputNumber( QStringLiteral( "MAX_LENGTH" ), QObject::tr( "Maximum length" ) ) );
81 addOutput( new QgsProcessingOutputNumber( QStringLiteral( "MEAN_LENGTH" ), QObject::tr( "Mean length" ) ) );
82 addOutput( new QgsProcessingOutputNumber( QStringLiteral( "CV" ), QObject::tr( "Coefficient of Variation" ) ) );
83 addOutput( new QgsProcessingOutputNumber( QStringLiteral( "SUM" ), QObject::tr( "Sum" ) ) );
84 addOutput( new QgsProcessingOutputNumber( QStringLiteral( "MEAN" ), QObject::tr( "Mean value" ) ) );
85 addOutput( new QgsProcessingOutputNumber( QStringLiteral( "STD_DEV" ), QObject::tr( "Standard deviation" ) ) );
86 addOutput( new QgsProcessingOutputNumber( QStringLiteral( "RANGE" ), QObject::tr( "Range" ) ) );
87 addOutput( new QgsProcessingOutputNumber( QStringLiteral( "MEDIAN" ), QObject::tr( "Median" ) ) );
88 addOutput( new QgsProcessingOutputNumber( QStringLiteral( "MINORITY" ), QObject::tr( "Minority (rarest occurring value)" ) ) );
89 addOutput( new QgsProcessingOutputNumber( QStringLiteral( "MAJORITY" ), QObject::tr( "Majority (most frequently occurring value)" ) ) );
90 addOutput( new QgsProcessingOutputNumber( QStringLiteral( "FIRSTQUARTILE" ), QObject::tr( "First quartile" ) ) );
91 addOutput( new QgsProcessingOutputNumber( QStringLiteral( "THIRDQUARTILE" ), QObject::tr( "Third quartile" ) ) );
92 addOutput( new QgsProcessingOutputNumber( QStringLiteral( "IQR" ), QObject::tr( "Interquartile Range (IQR)" ) ) );
93}
94
95QVariantMap QgsBasicStatisticsAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
96{
97 std::unique_ptr<QgsProcessingFeatureSource> source( parameterAsSource( parameters, QStringLiteral( "INPUT_LAYER" ), context ) );
98 if ( !source )
99 throw QgsProcessingException( invalidSourceError( parameters, QStringLiteral( "INPUT_LAYER" ) ) );
100
101 const QString fieldName = parameterAsString( parameters, QStringLiteral( "FIELD_NAME" ), context );
102 const int fieldIndex = source->fields().lookupField( fieldName );
103 if ( fieldIndex < 0 )
104 {
105 throw QgsProcessingException( QObject::tr( "Invalid field for statistics: “%1” does not exist" ).arg( fieldName ) );
106 }
107
108 QgsField field = source->fields().at( fieldIndex );
109
110 QString outputHtml = parameterAsFileOutput( parameters, QStringLiteral( "OUTPUT_HTML_FILE" ), context );
111
112 QgsFeatureRequest request;
113 request.setFlags( Qgis::FeatureRequestFlag::NoGeometry ).setSubsetOfAttributes( QStringList() << fieldName, source->fields() );
115 const long long count = source->featureCount();
116
117 QgsFields fields;
118 fields.append( QgsField( QStringLiteral( "count" ), QMetaType::Int ) );
119 fields.append( QgsField( QStringLiteral( "unique" ), QMetaType::Int ) );
120 fields.append( QgsField( QStringLiteral( "empty" ), QMetaType::Int ) );
121 fields.append( QgsField( QStringLiteral( "filled" ), QMetaType::Int ) );
122
123 if ( field.isNumeric() )
124 {
125 fields.append( QgsField( QStringLiteral( "min" ), QMetaType::Double ) );
126 fields.append( QgsField( QStringLiteral( "max" ), QMetaType::Double ) );
127 fields.append( QgsField( QStringLiteral( "range" ), QMetaType::Double ) );
128 fields.append( QgsField( QStringLiteral( "sum" ), QMetaType::Double ) );
129 fields.append( QgsField( QStringLiteral( "mean" ), QMetaType::Double ) );
130 fields.append( QgsField( QStringLiteral( "median" ), QMetaType::Double ) );
131 fields.append( QgsField( QStringLiteral( "stddev" ), QMetaType::Double ) );
132 fields.append( QgsField( QStringLiteral( "cv" ), QMetaType::Double ) );
133 fields.append( QgsField( QStringLiteral( "minority" ), QMetaType::Double ) );
134 fields.append( QgsField( QStringLiteral( "majority" ), QMetaType::Double ) );
135 fields.append( QgsField( QStringLiteral( "q1" ), QMetaType::Double ) );
136 fields.append( QgsField( QStringLiteral( "q3" ), QMetaType::Double ) );
137 fields.append( QgsField( QStringLiteral( "iqr" ), QMetaType::Double ) );
138 }
139 else if ( field.isDateOrTime() )
140 {
141 if ( field.type() == QMetaType::Type::QDate )
142 {
143 fields.append( QgsField( QStringLiteral( "min" ), QMetaType::QDate ) );
144 fields.append( QgsField( QStringLiteral( "max" ), QMetaType::QDate ) );
145 }
146 else if ( field.type() == QMetaType::Type::QTime )
147 {
148 fields.append( QgsField( QStringLiteral( "min" ), QMetaType::QTime ) );
149 fields.append( QgsField( QStringLiteral( "max" ), QMetaType::QTime ) );
150 }
151 else
152 {
153 fields.append( QgsField( QStringLiteral( "min" ), QMetaType::QDateTime ) );
154 fields.append( QgsField( QStringLiteral( "max" ), QMetaType::QDateTime ) );
155 }
156 fields.append( QgsField( QStringLiteral( "range" ), QMetaType::Double ) );
157 }
158 else
159 {
160 fields.append( QgsField( QStringLiteral( "min" ), QMetaType::QString ) );
161 fields.append( QgsField( QStringLiteral( "max" ), QMetaType::QString ) );
162 fields.append( QgsField( QStringLiteral( "min_length" ), QMetaType::Double ) );
163 fields.append( QgsField( QStringLiteral( "max_length" ), QMetaType::Double ) );
164 fields.append( QgsField( QStringLiteral( "mean_length" ), QMetaType::Double ) );
165 fields.append( QgsField( QStringLiteral( "minority" ), QMetaType::QString ) );
166 fields.append( QgsField( QStringLiteral( "majority" ), QMetaType::QString ) );
167 }
168
169 QString destId;
170 std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, destId, fields, Qgis::WkbType::NoGeometry, QgsCoordinateReferenceSystem() ) );
171 if ( parameters.value( QStringLiteral( "OUTPUT" ) ).isValid() && !sink )
172 throw QgsProcessingException( invalidSinkError( parameters, QStringLiteral( "OUTPUT" ) ) );
173
174 QStringList data;
175 data << QObject::tr( "Analyzed field: %1" ).arg( fieldName );
176
177 QVariantMap outputs;
178
179 if ( field.isNumeric() )
180 {
181 outputs = calculateNumericStatistics( fieldIndex, features, count, sink.get(), data, feedback );
182 }
183 else if ( field.isDateOrTime() )
184 {
185 outputs = calculateDateTimeStatistics( fieldIndex, field, features, count, sink.get(), data, feedback );
186 }
187 else
188 {
189 outputs = calculateStringStatistics( fieldIndex, features, count, sink.get(), data, feedback );
190 }
191 if ( sink )
192 sink->finalize();
193
194 if ( !outputHtml.isEmpty() )
195 {
196 QFile file( outputHtml );
197 if ( file.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
198 {
199 QTextStream out( &file );
200#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
201 out.setCodec( "UTF-8" );
202#endif
203 out << QStringLiteral( "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/></head><body>\n" );
204 for ( const QString &s : data )
205 {
206 out << QStringLiteral( "<p>%1</p>" ).arg( s );
207 }
208 out << QStringLiteral( "</body></html>" );
209
210 outputs.insert( QStringLiteral( "OUTPUT_HTML_FILE" ), outputHtml );
211 }
212 }
213
214 if ( sink )
215 {
216 outputs.insert( QStringLiteral( "OUTPUT" ), destId );
217 }
218
219 return outputs;
220}
221
222QVariantMap QgsBasicStatisticsAlgorithm::calculateNumericStatistics( const int fieldIndex, QgsFeatureIterator features, const long long count, QgsFeatureSink *sink, QStringList &data, QgsProcessingFeedback *feedback )
223{
224 const double step = count > 0 ? 100.0 / count : 1;
225 long long current = 0;
226
227 QgsFeature f;
229
230 while ( features.nextFeature( f ) )
231 {
232 if ( feedback->isCanceled() )
233 {
234 break;
235 }
236
237 stat.addVariant( f.attribute( fieldIndex ) );
238 feedback->setProgress( current * step );
239 current++;
240 }
241 stat.finalize();
242
243 const double cv = stat.mean() != 0 ? stat.stDev() / stat.mean() : 0;
244
245 QVariantMap outputs;
246 outputs.insert( QStringLiteral( "COUNT" ), stat.count() );
247 outputs.insert( QStringLiteral( "UNIQUE" ), stat.variety() );
248 outputs.insert( QStringLiteral( "EMPTY" ), stat.countMissing() );
249 outputs.insert( QStringLiteral( "FILLED" ), count - stat.countMissing() );
250 outputs.insert( QStringLiteral( "MIN" ), stat.min() );
251 outputs.insert( QStringLiteral( "MAX" ), stat.max() );
252 outputs.insert( QStringLiteral( "RANGE" ), stat.range() );
253 outputs.insert( QStringLiteral( "SUM" ), stat.sum() );
254 outputs.insert( QStringLiteral( "MEAN" ), stat.mean() );
255 outputs.insert( QStringLiteral( "MEDIAN" ), stat.median() );
256 outputs.insert( QStringLiteral( "STD_DEV" ), stat.stDev() );
257 outputs.insert( QStringLiteral( "CV" ), cv );
258 outputs.insert( QStringLiteral( "MINORITY" ), stat.minority() );
259 outputs.insert( QStringLiteral( "MAJORITY" ), stat.majority() );
260 outputs.insert( QStringLiteral( "FIRSTQUARTILE" ), stat.firstQuartile() );
261 outputs.insert( QStringLiteral( "THIRDQUARTILE" ), stat.thirdQuartile() );
262 outputs.insert( QStringLiteral( "IQR" ), stat.interQuartileRange() );
263
264 data << QObject::tr( "Count: %1" ).arg( stat.count() )
265 << QObject::tr( "Unique values: %1" ).arg( stat.variety() )
266 << QObject::tr( "NULL (missing) values: %1" ).arg( stat.countMissing() )
267 << QObject::tr( "NOT NULL (filled) values: %1" ).arg( count - stat.countMissing() )
268 << QObject::tr( "Minimum value: %1" ).arg( stat.min() )
269 << QObject::tr( "Maximum value: %1" ).arg( stat.max() )
270 << QObject::tr( "Range: %1" ).arg( stat.range() )
271 << QObject::tr( "Sum: %1" ).arg( stat.sum(), 0, 'f' )
272 << QObject::tr( "Mean value: %1" ).arg( stat.mean(), 0, 'f' )
273 << QObject::tr( "Median value: %1" ).arg( stat.median(), 0, 'f' )
274 << QObject::tr( "Standard deviation: %1" ).arg( stat.stDev(), 0, 'f', 12 )
275 << QObject::tr( "Coefficient of Variation: %1" ).arg( cv, 0, 'f' )
276 << QObject::tr( "Minority (rarest occurring value): %1" ).arg( stat.minority() )
277 << QObject::tr( "Majority (most frequently occurring value): %1" ).arg( stat.majority() )
278 << QObject::tr( "First quartile: %1" ).arg( stat.firstQuartile(), 0, 'f' )
279 << QObject::tr( "Third quartile: %1" ).arg( stat.thirdQuartile(), 0, 'f' )
280 << QObject::tr( "Interquartile Range (IQR): %1" ).arg( stat.interQuartileRange() );
281
282 if ( sink )
283 {
284 QgsFeature f;
285 f.setAttributes( QgsAttributes() << outputs.value( QStringLiteral( "COUNT" ) ) << outputs.value( QStringLiteral( "UNIQUE" ) ) << outputs.value( QStringLiteral( "EMPTY" ) ) << outputs.value( QStringLiteral( "FILLED" ) ) << outputs.value( QStringLiteral( "MIN" ) ) << outputs.value( QStringLiteral( "MAX" ) ) << outputs.value( QStringLiteral( "RANGE" ) ) << outputs.value( QStringLiteral( "SUM" ) ) << outputs.value( QStringLiteral( "MEAN" ) ) << outputs.value( QStringLiteral( "MEDIAN" ) ) << outputs.value( QStringLiteral( "STD_DEV" ) ) << outputs.value( QStringLiteral( "CV" ) ) << outputs.value( QStringLiteral( "MINORITY" ) ) << outputs.value( QStringLiteral( "MAJORITY" ) ) << outputs.value( QStringLiteral( "FIRSTQUARTILE" ) ) << outputs.value( QStringLiteral( "THIRDQUARTILE" ) ) << outputs.value( QStringLiteral( "IQR" ) ) );
287 }
288
289 return outputs;
290}
291
292QVariantMap QgsBasicStatisticsAlgorithm::calculateDateTimeStatistics( const int fieldIndex, QgsField field, QgsFeatureIterator features, const long long count, QgsFeatureSink *sink, QStringList &data, QgsProcessingFeedback *feedback )
293{
294 const double step = count > 0 ? 100.0 / count : 1;
295 long long current = 0;
296
297 QgsFeature f;
299
300 while ( features.nextFeature( f ) )
301 {
302 if ( feedback->isCanceled() )
303 {
304 break;
305 }
306
307 stat.addValue( f.attribute( fieldIndex ) );
308 feedback->setProgress( current * step );
309 current++;
310 }
311 stat.finalize();
312
313 QVariantMap outputs;
314 outputs.insert( QStringLiteral( "COUNT" ), stat.count() );
315 outputs.insert( QStringLiteral( "UNIQUE" ), stat.countDistinct() );
316 outputs.insert( QStringLiteral( "EMPTY" ), stat.countMissing() );
317 outputs.insert( QStringLiteral( "FILLED" ), stat.count() - stat.countMissing() );
318 outputs.insert( QStringLiteral( "MIN" ), stat.statistic( Qgis::DateTimeStatistic::Min ) );
319 outputs.insert( QStringLiteral( "MAX" ), stat.statistic( Qgis::DateTimeStatistic::Max ) );
320 outputs.insert( QStringLiteral( "RANGE" ), stat.range().seconds() );
321
322 data << QObject::tr( "Count: %1" ).arg( stat.count() )
323 << QObject::tr( "Unique values: %1" ).arg( stat.countDistinct() )
324 << QObject::tr( "NULL (missing) values: %1" ).arg( stat.countMissing() )
325 << QObject::tr( "NOT NULL (filled) values: %1" ).arg( stat.count() - stat.countMissing() )
326 << QObject::tr( "Minimum value: %1" ).arg( field.displayString( stat.statistic( Qgis::DateTimeStatistic::Min ) ) )
327 << QObject::tr( "Maximum value: %1" ).arg( field.displayString( stat.statistic( Qgis::DateTimeStatistic::Max ) ) )
328 << QObject::tr( "Range (seconds): %1" ).arg( stat.range().seconds() );
329
330 if ( sink )
331 {
332 QgsFeature f;
333 f.setAttributes( QgsAttributes() << outputs.value( QStringLiteral( "COUNT" ) ) << outputs.value( QStringLiteral( "UNIQUE" ) ) << outputs.value( QStringLiteral( "EMPTY" ) ) << outputs.value( QStringLiteral( "FILLED" ) ) << outputs.value( QStringLiteral( "MIN" ) ) << outputs.value( QStringLiteral( "MAX" ) ) << outputs.value( QStringLiteral( "RANGE" ) ) );
335 }
336
337 return outputs;
338}
339
340QVariantMap QgsBasicStatisticsAlgorithm::calculateStringStatistics( const int fieldIndex, QgsFeatureIterator features, const long long count, QgsFeatureSink *sink, QStringList &data, QgsProcessingFeedback *feedback )
341{
342 const double step = count > 0 ? 100.0 / count : 1;
343 long long current = 0;
344
345 QgsFeature f;
347
348 while ( features.nextFeature( f ) )
349 {
350 if ( feedback->isCanceled() )
351 {
352 break;
353 }
354
355 stat.addValue( f.attribute( fieldIndex ) );
356 feedback->setProgress( current * step );
357 current++;
358 }
359 stat.finalize();
360
361 QVariantMap outputs;
362 outputs.insert( QStringLiteral( "COUNT" ), stat.count() );
363 outputs.insert( QStringLiteral( "UNIQUE" ), stat.countDistinct() );
364 outputs.insert( QStringLiteral( "EMPTY" ), stat.countMissing() );
365 outputs.insert( QStringLiteral( "FILLED" ), stat.count() - stat.countMissing() );
366 outputs.insert( QStringLiteral( "MIN" ), stat.min() );
367 outputs.insert( QStringLiteral( "MAX" ), stat.max() );
368 outputs.insert( QStringLiteral( "MIN_LENGTH" ), stat.minLength() );
369 outputs.insert( QStringLiteral( "MAX_LENGTH" ), stat.maxLength() );
370 outputs.insert( QStringLiteral( "MEAN_LENGTH" ), stat.meanLength() );
371 outputs.insert( QStringLiteral( "MINORITY" ), stat.minority() );
372 outputs.insert( QStringLiteral( "MAJORITY" ), stat.majority() );
373
374 data << QObject::tr( "Count: %1" ).arg( stat.count() )
375 << QObject::tr( "Unique values: %1" ).arg( stat.countDistinct() )
376 << QObject::tr( "NULL (missing) values: %1" ).arg( stat.countMissing() )
377 << QObject::tr( "NOT NULL (filled) values: %1" ).arg( count - stat.countMissing() )
378 << QObject::tr( "Minimum value: %1" ).arg( stat.min() )
379 << QObject::tr( "Maximum value: %1" ).arg( stat.max() )
380 << QObject::tr( "Minimum length: %1" ).arg( stat.minLength() )
381 << QObject::tr( "Maximum length: %1" ).arg( stat.maxLength() )
382 << QObject::tr( "Mean length: %1" ).arg( stat.meanLength(), 0, 'f' )
383 << QObject::tr( "Minority: %1" ).arg( stat.minority() )
384 << QObject::tr( "Majority: %1" ).arg( stat.majority() );
385
386 if ( sink )
387 {
388 QgsFeature f;
389 f.setAttributes( QgsAttributes() << outputs.value( QStringLiteral( "COUNT" ) ) << outputs.value( QStringLiteral( "UNIQUE" ) ) << outputs.value( QStringLiteral( "EMPTY" ) ) << outputs.value( QStringLiteral( "FILLED" ) ) << outputs.value( QStringLiteral( "MIN" ) ) << outputs.value( QStringLiteral( "MAX" ) ) << outputs.value( QStringLiteral( "MIN_LENGTH" ) ) << outputs.value( QStringLiteral( "MAX_LENGTH" ) ) << outputs.value( QStringLiteral( "MEAN_LENGTH" ) ) << outputs.value( QStringLiteral( "MINORITY" ) ) << outputs.value( QStringLiteral( "MAJORITY" ) ) );
391 }
392
393 return outputs;
394}
395
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
@ NoGeometry
No geometry.
@ Max
Maximum (latest) datetime value.
@ Min
Minimum (earliest) datetime value.
A vector of attributes.
Represents a coordinate reference system (CRS).
Calculator for summary statistics and aggregates for a list of datetimes.
QVariant statistic(Qgis::DateTimeStatistic stat) const
Returns the value of a specified statistic.
QgsInterval range() const
Returns the range (interval between earliest and latest non-null datetime values).
void addValue(const QVariant &value)
Adds a single datetime to the statistics calculation.
void finalize()
Must be called after adding all datetimes with addValue() and before retrieving any calculated dateti...
int count() const
Returns the calculated count of values.
int countMissing() const
Returns the number of missing (null) datetime values.
int countDistinct() const
Returns the number of distinct datetime values.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
Wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFlags(Qgis::FeatureRequestFlags flags)
Sets flags that affect how features will be fetched.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
An interface for objects which accept features via addFeature(s) methods.
virtual bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags())
Adds a single feature to the sink.
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
Q_INVOKABLE QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
bool isCanceled() const
Tells whether the operation has been canceled already.
Definition qgsfeedback.h:53
void setProgress(double progress)
Sets the current progress for the feedback object.
Definition qgsfeedback.h:61
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:53
QMetaType::Type type
Definition qgsfield.h:60
bool isDateOrTime
Definition qgsfield.h:57
QString displayString(const QVariant &v) const
Formats string for display.
Definition qgsfield.cpp:318
bool isNumeric
Definition qgsfield.h:56
Container of fields for a vector layer.
Definition qgsfields.h:46
bool append(const QgsField &field, Qgis::FieldOrigin origin=Qgis::FieldOrigin::Provider, int originIndex=-1)
Appends a field.
Definition qgsfields.cpp:70
double seconds() const
Returns the interval duration in seconds.
Contains information about the context in which a processing algorithm is executed.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
A numeric output for processing algorithms.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.
A vector layer or feature source field parameter for processing algorithms.
A generic file based destination parameter, for specifying the destination path for a file (non-map l...
Calculator for summary statistics for a list of doubles.
void addVariant(const QVariant &value)
Adds a single value to the statistics calculation.
double firstQuartile() const
Returns the first quartile of the values.
double sum() const
Returns calculated sum of values.
double mean() const
Returns calculated mean of values.
double majority() const
Returns majority of values.
int countMissing() const
Returns the number of missing (null) values.
double interQuartileRange() const
Returns the inter quartile range of the values.
double median() const
Returns calculated median of values.
double minority() const
Returns minority of values.
double min() const
Returns calculated minimum from values.
double stDev() const
Returns population standard deviation.
double thirdQuartile() const
Returns the third quartile of the values.
int count() const
Returns calculated count of values.
double range() const
Returns calculated range (difference between maximum and minimum values).
double max() const
Returns calculated maximum from values.
void finalize()
Must be called after adding all values with addValues() and before retrieving any calculated statisti...
int variety() const
Returns variety of values.
Calculator for summary statistics and aggregates for a list of strings.
QString max() const
Returns the maximum (non-null) string value.
QString min() const
Returns the minimum (non-null) string value.
int countMissing() const
Returns the number of missing (null) string values.
int count() const
Returns the calculated count of values.
int countDistinct() const
Returns the number of distinct string values.
void finalize()
Must be called after adding all strings with addString() and before retrieving any calculated string ...
void addValue(const QVariant &value)
Adds a single variant to the statistics calculation.
int minLength() const
Returns the minimum length of strings.
int maxLength() const
Returns the maximum length of strings.
QString majority() const
Returns the most common string.
QString minority() const
Returns the least common string.
double meanLength() const
Returns the mean length of strings.