QGIS API Documentation 3.99.0-Master (09f76ad7019)
Loading...
Searching...
No Matches
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
19
23
24#include <QString>
25
26using namespace Qt::StringLiterals;
27
29
30QString QgsBasicStatisticsAlgorithm::name() const
31{
32 return u"basicstatisticsforfields"_s;
33}
34
35QString QgsBasicStatisticsAlgorithm::displayName() const
36{
37 return QObject::tr( "Basic statistics for fields" );
38}
39
40QStringList QgsBasicStatisticsAlgorithm::tags() const
41{
42 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( ',' );
43}
44
45QString QgsBasicStatisticsAlgorithm::group() const
46{
47 return QObject::tr( "Vector analysis" );
48}
49
50QString QgsBasicStatisticsAlgorithm::groupId() const
51{
52 return u"vectoranalysis"_s;
53}
54
55QString QgsBasicStatisticsAlgorithm::shortHelpString() const
56{
57 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." );
58}
59
60QString QgsBasicStatisticsAlgorithm::shortDescription() const
61{
62 return QObject::tr( "Generates basic statistics from the values in a field of a vector layer." );
63}
64
65QgsBasicStatisticsAlgorithm *QgsBasicStatisticsAlgorithm::createInstance() const
66{
67 return new QgsBasicStatisticsAlgorithm();
68}
69
70void QgsBasicStatisticsAlgorithm::initAlgorithm( const QVariantMap & )
71{
72 addParameter( new QgsProcessingParameterFeatureSource( u"INPUT_LAYER"_s, QObject::tr( "Input layer" ), QList<int>() << static_cast<int>( Qgis::ProcessingSourceType::Vector ) ) );
73 addParameter( new QgsProcessingParameterField( u"FIELD_NAME"_s, QObject::tr( "Field to calculate statistics on" ), QVariant(), u"INPUT_LAYER"_s ) );
74 addParameter( new QgsProcessingParameterFeatureSink( u"OUTPUT"_s, QObject::tr( "Statistics" ), Qgis::ProcessingSourceType::Vector, QVariant(), true ) );
75 addParameter( new QgsProcessingParameterFileDestination( u"OUTPUT_HTML_FILE"_s, QObject::tr( "Statistics report" ), QObject::tr( "'HTML files (*.html)" ), QVariant(), true ) );
76
77 addOutput( new QgsProcessingOutputNumber( u"COUNT"_s, QObject::tr( "Count" ) ) );
78 addOutput( new QgsProcessingOutputNumber( u"UNIQUE"_s, QObject::tr( "Number of unique values" ) ) );
79 addOutput( new QgsProcessingOutputNumber( u"EMPTY"_s, QObject::tr( "Number of empty (null) values" ) ) );
80 addOutput( new QgsProcessingOutputNumber( u"FILLED"_s, QObject::tr( "Number of non-empty values" ) ) );
81 addOutput( new QgsProcessingOutputNumber( u"MIN"_s, QObject::tr( "Minimum value" ) ) );
82 addOutput( new QgsProcessingOutputNumber( u"MAX"_s, QObject::tr( "Maximum value" ) ) );
83 addOutput( new QgsProcessingOutputNumber( u"MIN_LENGTH"_s, QObject::tr( "Minimum length" ) ) );
84 addOutput( new QgsProcessingOutputNumber( u"MAX_LENGTH"_s, QObject::tr( "Maximum length" ) ) );
85 addOutput( new QgsProcessingOutputNumber( u"MEAN_LENGTH"_s, QObject::tr( "Mean length" ) ) );
86 addOutput( new QgsProcessingOutputNumber( u"CV"_s, QObject::tr( "Coefficient of Variation" ) ) );
87 addOutput( new QgsProcessingOutputNumber( u"SUM"_s, QObject::tr( "Sum" ) ) );
88 addOutput( new QgsProcessingOutputNumber( u"MEAN"_s, QObject::tr( "Mean value" ) ) );
89 addOutput( new QgsProcessingOutputNumber( u"STD_DEV"_s, QObject::tr( "Standard deviation" ) ) );
90 addOutput( new QgsProcessingOutputNumber( u"RANGE"_s, QObject::tr( "Range" ) ) );
91 addOutput( new QgsProcessingOutputNumber( u"MEDIAN"_s, QObject::tr( "Median" ) ) );
92 addOutput( new QgsProcessingOutputNumber( u"MINORITY"_s, QObject::tr( "Minority (rarest occurring value)" ) ) );
93 addOutput( new QgsProcessingOutputNumber( u"MAJORITY"_s, QObject::tr( "Majority (most frequently occurring value)" ) ) );
94 addOutput( new QgsProcessingOutputNumber( u"FIRSTQUARTILE"_s, QObject::tr( "First quartile" ) ) );
95 addOutput( new QgsProcessingOutputNumber( u"THIRDQUARTILE"_s, QObject::tr( "Third quartile" ) ) );
96 addOutput( new QgsProcessingOutputNumber( u"IQR"_s, QObject::tr( "Interquartile Range (IQR)" ) ) );
97}
98
99QVariantMap QgsBasicStatisticsAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
100{
101 std::unique_ptr<QgsProcessingFeatureSource> source( parameterAsSource( parameters, u"INPUT_LAYER"_s, context ) );
102 if ( !source )
103 throw QgsProcessingException( invalidSourceError( parameters, u"INPUT_LAYER"_s ) );
104
105 const QString fieldName = parameterAsString( parameters, u"FIELD_NAME"_s, context );
106 const int fieldIndex = source->fields().lookupField( fieldName );
107 if ( fieldIndex < 0 )
108 {
109 throw QgsProcessingException( QObject::tr( "Invalid field for statistics: “%1” does not exist" ).arg( fieldName ) );
110 }
111
112 QgsField field = source->fields().at( fieldIndex );
113
114 QString outputHtml = parameterAsFileOutput( parameters, u"OUTPUT_HTML_FILE"_s, context );
115
116 QgsFeatureRequest request;
117 request.setFlags( Qgis::FeatureRequestFlag::NoGeometry ).setSubsetOfAttributes( QStringList() << fieldName, source->fields() );
119 const long long count = source->featureCount();
120
121 QgsFields fields;
122 fields.append( QgsField( u"count"_s, QMetaType::Int ) );
123 fields.append( QgsField( u"unique"_s, QMetaType::Int ) );
124 fields.append( QgsField( u"empty"_s, QMetaType::Int ) );
125 fields.append( QgsField( u"filled"_s, QMetaType::Int ) );
126
127 if ( field.isNumeric() )
128 {
129 fields.append( QgsField( u"min"_s, QMetaType::Double ) );
130 fields.append( QgsField( u"max"_s, QMetaType::Double ) );
131 fields.append( QgsField( u"range"_s, QMetaType::Double ) );
132 fields.append( QgsField( u"sum"_s, QMetaType::Double ) );
133 fields.append( QgsField( u"mean"_s, QMetaType::Double ) );
134 fields.append( QgsField( u"median"_s, QMetaType::Double ) );
135 fields.append( QgsField( u"stddev"_s, QMetaType::Double ) );
136 fields.append( QgsField( u"cv"_s, QMetaType::Double ) );
137 fields.append( QgsField( u"minority"_s, QMetaType::Double ) );
138 fields.append( QgsField( u"majority"_s, QMetaType::Double ) );
139 fields.append( QgsField( u"q1"_s, QMetaType::Double ) );
140 fields.append( QgsField( u"q3"_s, QMetaType::Double ) );
141 fields.append( QgsField( u"iqr"_s, QMetaType::Double ) );
142 }
143 else if ( field.isDateOrTime() )
144 {
145 if ( field.type() == QMetaType::Type::QDate )
146 {
147 fields.append( QgsField( u"min"_s, QMetaType::QDate ) );
148 fields.append( QgsField( u"max"_s, QMetaType::QDate ) );
149 }
150 else if ( field.type() == QMetaType::Type::QTime )
151 {
152 fields.append( QgsField( u"min"_s, QMetaType::QTime ) );
153 fields.append( QgsField( u"max"_s, QMetaType::QTime ) );
154 }
155 else
156 {
157 fields.append( QgsField( u"min"_s, QMetaType::QDateTime ) );
158 fields.append( QgsField( u"max"_s, QMetaType::QDateTime ) );
159 }
160 fields.append( QgsField( u"range"_s, QMetaType::Double ) );
161 }
162 else
163 {
164 fields.append( QgsField( u"min"_s, QMetaType::QString ) );
165 fields.append( QgsField( u"max"_s, QMetaType::QString ) );
166 fields.append( QgsField( u"min_length"_s, QMetaType::Double ) );
167 fields.append( QgsField( u"max_length"_s, QMetaType::Double ) );
168 fields.append( QgsField( u"mean_length"_s, QMetaType::Double ) );
169 fields.append( QgsField( u"minority"_s, QMetaType::QString ) );
170 fields.append( QgsField( u"majority"_s, QMetaType::QString ) );
171 }
172
173 QString destId;
174 std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, u"OUTPUT"_s, context, destId, fields, Qgis::WkbType::NoGeometry, QgsCoordinateReferenceSystem() ) );
175 if ( parameters.value( u"OUTPUT"_s ).isValid() && !sink )
176 throw QgsProcessingException( invalidSinkError( parameters, u"OUTPUT"_s ) );
177
178 QStringList data;
179 data << QObject::tr( "Analyzed field: %1" ).arg( fieldName );
180
181 QVariantMap outputs;
182
183 if ( field.isNumeric() )
184 {
185 outputs = calculateNumericStatistics( parameters, fieldIndex, features, count, sink.get(), data, feedback );
186 }
187 else if ( field.isDateOrTime() )
188 {
189 outputs = calculateDateTimeStatistics( parameters, fieldIndex, field, features, count, sink.get(), data, feedback );
190 }
191 else
192 {
193 outputs = calculateStringStatistics( parameters, fieldIndex, features, count, sink.get(), data, feedback );
194 }
195 if ( sink )
196 sink->finalize();
197
198 if ( !outputHtml.isEmpty() )
199 {
200 QFile file( outputHtml );
201 if ( file.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
202 {
203 QTextStream out( &file );
204 out << u"<html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/></head><body>\n"_s;
205 for ( const QString &s : data )
206 {
207 out << u"<p>%1</p>"_s.arg( s );
208 }
209 out << u"</body></html>"_s;
210
211 outputs.insert( u"OUTPUT_HTML_FILE"_s, outputHtml );
212 }
213 }
214
215 if ( sink )
216 {
217 outputs.insert( u"OUTPUT"_s, destId );
218 }
219
220 return outputs;
221}
222
223QVariantMap QgsBasicStatisticsAlgorithm::calculateNumericStatistics( const QVariantMap &parameters, const int fieldIndex, QgsFeatureIterator features, const long long count, QgsFeatureSink *sink, QStringList &data, QgsProcessingFeedback *feedback )
224{
225 const double step = count > 0 ? 100.0 / count : 1;
226 long long current = 0;
227
228 QgsFeature f;
230
231 while ( features.nextFeature( f ) )
232 {
233 if ( feedback->isCanceled() )
234 {
235 break;
236 }
237
238 stat.addVariant( f.attribute( fieldIndex ) );
239 feedback->setProgress( current * step );
240 current++;
241 }
242 stat.finalize();
243
244 const double cv = stat.mean() != 0 ? stat.stDev() / stat.mean() : 0;
245
246 QVariantMap outputs;
247 outputs.insert( u"COUNT"_s, stat.count() );
248 outputs.insert( u"UNIQUE"_s, stat.variety() );
249 outputs.insert( u"EMPTY"_s, stat.countMissing() );
250 outputs.insert( u"FILLED"_s, count - stat.countMissing() );
251 outputs.insert( u"MIN"_s, stat.min() );
252 outputs.insert( u"MAX"_s, stat.max() );
253 outputs.insert( u"RANGE"_s, stat.range() );
254 outputs.insert( u"SUM"_s, stat.sum() );
255 outputs.insert( u"MEAN"_s, stat.mean() );
256 outputs.insert( u"MEDIAN"_s, stat.median() );
257 outputs.insert( u"STD_DEV"_s, stat.stDev() );
258 outputs.insert( u"CV"_s, cv );
259 outputs.insert( u"MINORITY"_s, stat.minority() );
260 outputs.insert( u"MAJORITY"_s, stat.majority() );
261 outputs.insert( u"FIRSTQUARTILE"_s, stat.firstQuartile() );
262 outputs.insert( u"THIRDQUARTILE"_s, stat.thirdQuartile() );
263 outputs.insert( u"IQR"_s, stat.interQuartileRange() );
264
265 data << QObject::tr( "Count: %1" ).arg( stat.count() )
266 << QObject::tr( "Unique values: %1" ).arg( stat.variety() )
267 << QObject::tr( "NULL (missing) values: %1" ).arg( stat.countMissing() )
268 << QObject::tr( "NOT NULL (filled) values: %1" ).arg( count - stat.countMissing() )
269 << QObject::tr( "Minimum value: %1" ).arg( stat.min() )
270 << QObject::tr( "Maximum value: %1" ).arg( stat.max() )
271 << QObject::tr( "Range: %1" ).arg( stat.range() )
272 << QObject::tr( "Sum: %1" ).arg( stat.sum(), 0, 'f' )
273 << QObject::tr( "Mean value: %1" ).arg( stat.mean(), 0, 'f' )
274 << QObject::tr( "Median value: %1" ).arg( stat.median(), 0, 'f' )
275 << QObject::tr( "Standard deviation: %1" ).arg( stat.stDev(), 0, 'f', 12 )
276 << QObject::tr( "Coefficient of Variation: %1" ).arg( cv, 0, 'f' )
277 << QObject::tr( "Minority (rarest occurring value): %1" ).arg( stat.minority() )
278 << QObject::tr( "Majority (most frequently occurring value): %1" ).arg( stat.majority() )
279 << QObject::tr( "First quartile: %1" ).arg( stat.firstQuartile(), 0, 'f' )
280 << QObject::tr( "Third quartile: %1" ).arg( stat.thirdQuartile(), 0, 'f' )
281 << QObject::tr( "Interquartile Range (IQR): %1" ).arg( stat.interQuartileRange() );
282
283 if ( sink )
284 {
285 QgsFeature f;
286 f.setAttributes( QgsAttributes() << outputs.value( u"COUNT"_s ) << outputs.value( u"UNIQUE"_s ) << outputs.value( u"EMPTY"_s ) << outputs.value( u"FILLED"_s ) << outputs.value( u"MIN"_s ) << outputs.value( u"MAX"_s ) << outputs.value( u"RANGE"_s ) << outputs.value( u"SUM"_s ) << outputs.value( u"MEAN"_s ) << outputs.value( u"MEDIAN"_s ) << outputs.value( u"STD_DEV"_s ) << outputs.value( u"CV"_s ) << outputs.value( u"MINORITY"_s ) << outputs.value( u"MAJORITY"_s ) << outputs.value( u"FIRSTQUARTILE"_s ) << outputs.value( u"THIRDQUARTILE"_s ) << outputs.value( u"IQR"_s ) );
287 if ( !sink->addFeature( f, QgsFeatureSink::FastInsert ) )
288 {
289 throw QgsProcessingException( writeFeatureError( sink, parameters, QString() ) );
290 }
291 }
292
293 return outputs;
294}
295
296QVariantMap QgsBasicStatisticsAlgorithm::calculateDateTimeStatistics( const QVariantMap &parameters, const int fieldIndex, QgsField field, QgsFeatureIterator features, const long long count, QgsFeatureSink *sink, QStringList &data, QgsProcessingFeedback *feedback )
297{
298 const double step = count > 0 ? 100.0 / count : 1;
299 long long current = 0;
300
301 QgsFeature f;
303
304 while ( features.nextFeature( f ) )
305 {
306 if ( feedback->isCanceled() )
307 {
308 break;
309 }
310
311 stat.addValue( f.attribute( fieldIndex ) );
312 feedback->setProgress( current * step );
313 current++;
314 }
315 stat.finalize();
316
317 QVariantMap outputs;
318 outputs.insert( u"COUNT"_s, stat.count() );
319 outputs.insert( u"UNIQUE"_s, stat.countDistinct() );
320 outputs.insert( u"EMPTY"_s, stat.countMissing() );
321 outputs.insert( u"FILLED"_s, stat.count() - stat.countMissing() );
322 outputs.insert( u"MIN"_s, stat.statistic( Qgis::DateTimeStatistic::Min ) );
323 outputs.insert( u"MAX"_s, stat.statistic( Qgis::DateTimeStatistic::Max ) );
324 outputs.insert( u"RANGE"_s, stat.range().seconds() );
325
326 data << QObject::tr( "Count: %1" ).arg( stat.count() )
327 << QObject::tr( "Unique values: %1" ).arg( stat.countDistinct() )
328 << QObject::tr( "NULL (missing) values: %1" ).arg( stat.countMissing() )
329 << QObject::tr( "NOT NULL (filled) values: %1" ).arg( stat.count() - stat.countMissing() )
330 << QObject::tr( "Minimum value: %1" ).arg( field.displayString( stat.statistic( Qgis::DateTimeStatistic::Min ) ) )
331 << QObject::tr( "Maximum value: %1" ).arg( field.displayString( stat.statistic( Qgis::DateTimeStatistic::Max ) ) )
332 << QObject::tr( "Range (seconds): %1" ).arg( stat.range().seconds() );
333
334 if ( sink )
335 {
336 QgsFeature f;
337 f.setAttributes( QgsAttributes() << outputs.value( u"COUNT"_s ) << outputs.value( u"UNIQUE"_s ) << outputs.value( u"EMPTY"_s ) << outputs.value( u"FILLED"_s ) << outputs.value( u"MIN"_s ) << outputs.value( u"MAX"_s ) << outputs.value( u"RANGE"_s ) );
338 if ( !sink->addFeature( f, QgsFeatureSink::FastInsert ) )
339 {
340 throw QgsProcessingException( writeFeatureError( sink, parameters, QString() ) );
341 }
342 }
343
344 return outputs;
345}
346
347QVariantMap QgsBasicStatisticsAlgorithm::calculateStringStatistics( const QVariantMap &parameters, const int fieldIndex, QgsFeatureIterator features, const long long count, QgsFeatureSink *sink, QStringList &data, QgsProcessingFeedback *feedback )
348{
349 const double step = count > 0 ? 100.0 / count : 1;
350 long long current = 0;
351
352 QgsFeature f;
354
355 while ( features.nextFeature( f ) )
356 {
357 if ( feedback->isCanceled() )
358 {
359 break;
360 }
361
362 stat.addValue( f.attribute( fieldIndex ) );
363 feedback->setProgress( current * step );
364 current++;
365 }
366 stat.finalize();
367
368 QVariantMap outputs;
369 outputs.insert( u"COUNT"_s, stat.count() );
370 outputs.insert( u"UNIQUE"_s, stat.countDistinct() );
371 outputs.insert( u"EMPTY"_s, stat.countMissing() );
372 outputs.insert( u"FILLED"_s, stat.count() - stat.countMissing() );
373 outputs.insert( u"MIN"_s, stat.min() );
374 outputs.insert( u"MAX"_s, stat.max() );
375 outputs.insert( u"MIN_LENGTH"_s, stat.minLength() );
376 outputs.insert( u"MAX_LENGTH"_s, stat.maxLength() );
377 outputs.insert( u"MEAN_LENGTH"_s, stat.meanLength() );
378 outputs.insert( u"MINORITY"_s, stat.minority() );
379 outputs.insert( u"MAJORITY"_s, stat.majority() );
380
381 data << QObject::tr( "Count: %1" ).arg( stat.count() )
382 << QObject::tr( "Unique values: %1" ).arg( stat.countDistinct() )
383 << QObject::tr( "NULL (missing) values: %1" ).arg( stat.countMissing() )
384 << QObject::tr( "NOT NULL (filled) values: %1" ).arg( count - stat.countMissing() )
385 << QObject::tr( "Minimum value: %1" ).arg( stat.min() )
386 << QObject::tr( "Maximum value: %1" ).arg( stat.max() )
387 << QObject::tr( "Minimum length: %1" ).arg( stat.minLength() )
388 << QObject::tr( "Maximum length: %1" ).arg( stat.maxLength() )
389 << QObject::tr( "Mean length: %1" ).arg( stat.meanLength(), 0, 'f' )
390 << QObject::tr( "Minority: %1" ).arg( stat.minority() )
391 << QObject::tr( "Majority: %1" ).arg( stat.majority() );
392
393 if ( sink )
394 {
395 QgsFeature f;
396 f.setAttributes( QgsAttributes() << outputs.value( u"COUNT"_s ) << outputs.value( u"UNIQUE"_s ) << outputs.value( u"EMPTY"_s ) << outputs.value( u"FILLED"_s ) << outputs.value( u"MIN"_s ) << outputs.value( u"MAX"_s ) << outputs.value( u"MIN_LENGTH"_s ) << outputs.value( u"MAX_LENGTH"_s ) << outputs.value( u"MEAN_LENGTH"_s ) << outputs.value( u"MINORITY"_s ) << outputs.value( u"MAJORITY"_s ) );
397 if ( !sink->addFeature( f, QgsFeatureSink::FastInsert ) )
398 {
399 throw QgsProcessingException( writeFeatureError( sink, parameters, QString() ) );
400 }
401 }
402
403 return outputs;
404}
405
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
Definition qgis.h:3610
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
Definition qgis.h:2254
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
Definition qgis.h:3782
@ NoGeometry
No geometry.
Definition qgis.h:298
@ Max
Maximum (latest) datetime value.
Definition qgis.h:6191
@ Min
Minimum (earliest) datetime value.
Definition qgis.h:6190
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:60
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:55
void setProgress(double progress)
Sets the current progress for the feedback object.
Definition qgsfeedback.h:63
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:56
QMetaType::Type type
Definition qgsfield.h:63
bool isDateOrTime
Definition qgsfield.h:60
QString displayString(const QVariant &v) const
Formats string for display.
Definition qgsfield.cpp:323
bool isNumeric
Definition qgsfield.h:59
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:76
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.