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