QGIS API Documentation 3.99.0-Master (357b655ed83)
Loading...
Searching...
No Matches
qgsalgorithmjoinbylocationsummary.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmjoinbylocationsummary.cpp
3 ---------------------
4 begin : September 2023
5 copyright : (C) 2023 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
19
21#include "qgsapplication.h"
23#include "qgsfeature.h"
24#include "qgsfeaturesource.h"
25#include "qgsgeometryengine.h"
26#include "qgsprocessing.h"
28#include "qgsvectorlayer.h"
29
30#include <QString>
31
32using namespace Qt::StringLiterals;
33
35
36
37void QgsJoinByLocationSummaryAlgorithm::initAlgorithm( const QVariantMap & )
38{
39 addParameter( new QgsProcessingParameterFeatureSource( u"INPUT"_s, QObject::tr( "Join to features in" ), QList<int>() << static_cast<int>( Qgis::ProcessingSourceType::VectorAnyGeometry ) ) );
40
41 auto predicateParam = std::make_unique<QgsProcessingParameterEnum>( u"PREDICATE"_s, QObject::tr( "Where the features" ), QgsJoinByLocationAlgorithm::translatedPredicates(), true, 0 );
42 QVariantMap predicateMetadata;
43 QVariantMap widgetMetadata;
44 widgetMetadata.insert( u"useCheckBoxes"_s, true );
45 widgetMetadata.insert( u"columns"_s, 2 );
46 predicateMetadata.insert( u"widget_wrapper"_s, widgetMetadata );
47 predicateParam->setMetadata( predicateMetadata );
48 addParameter( predicateParam.release() );
49
50 addParameter( new QgsProcessingParameterFeatureSource( u"JOIN"_s, QObject::tr( "By comparing to" ), QList<int>() << static_cast<int>( Qgis::ProcessingSourceType::VectorAnyGeometry ) ) );
51
52 addParameter( new QgsProcessingParameterField( u"JOIN_FIELDS"_s, QObject::tr( "Fields to summarise (leave empty to use all fields)" ), QVariant(), u"JOIN"_s, Qgis::ProcessingFieldParameterDataType::Any, true, true ) );
53
54 mAllSummaries << QObject::tr( "count" )
55 << QObject::tr( "unique" )
56 << QObject::tr( "min" )
57 << QObject::tr( "max" )
58 << QObject::tr( "range" )
59 << QObject::tr( "sum" )
60 << QObject::tr( "mean" )
61 << QObject::tr( "median" )
62 << QObject::tr( "stddev" )
63 << QObject::tr( "minority" )
64 << QObject::tr( "majority" )
65 << QObject::tr( "q1" )
66 << QObject::tr( "q3" )
67 << QObject::tr( "iqr" )
68 << QObject::tr( "empty" )
69 << QObject::tr( "filled" )
70 << QObject::tr( "min_length" )
71 << QObject::tr( "max_length" )
72 << QObject::tr( "mean_length" );
73
74 auto summaryParam = std::make_unique<QgsProcessingParameterEnum>( u"SUMMARIES"_s, QObject::tr( "Summaries to calculate (leave empty to use all available)" ), mAllSummaries, true, QVariant(), true );
75 addParameter( summaryParam.release() );
76
77 addParameter( new QgsProcessingParameterBoolean( u"DISCARD_NONMATCHING"_s, QObject::tr( "Discard records which could not be joined" ), false ) );
78 addParameter( new QgsProcessingParameterFeatureSink( u"OUTPUT"_s, QObject::tr( "Joined layer" ) ) );
79}
80
81QString QgsJoinByLocationSummaryAlgorithm::name() const
82{
83 return u"joinbylocationsummary"_s;
84}
85
86QString QgsJoinByLocationSummaryAlgorithm::displayName() const
87{
88 return QObject::tr( "Join attributes by location (summary)" );
89}
90
91QStringList QgsJoinByLocationSummaryAlgorithm::tags() const
92{
93 return QObject::tr( "summary,aggregate,join,intersects,intersecting,touching,within,contains,overlaps,relation,spatial,"
94 "stats,statistics,sum,maximum,minimum,mean,average,standard,deviation,"
95 "count,distinct,unique,variance,median,quartile,range,majority,minority,histogram,distinct" )
96 .split( ',' );
97}
98
99QString QgsJoinByLocationSummaryAlgorithm::group() const
100{
101 return QObject::tr( "Vector general" );
102}
103
104QString QgsJoinByLocationSummaryAlgorithm::groupId() const
105{
106 return u"vectorgeneral"_s;
107}
108
109QString QgsJoinByLocationSummaryAlgorithm::shortHelpString() const
110{
111 return QObject::tr( "This algorithm takes an input vector layer and creates a new vector layer that is an extended version of the input one, with additional attributes in its attribute table.\n\n"
112 "The additional attributes and their values are taken from a second vector layer. A spatial criteria is applied to select the values from the second layer that are added to each feature from the first layer in the resulting one.\n\n"
113 "The algorithm calculates a statistical summary for the values from matching features in the second layer( e.g. maximum value, mean value, etc )." );
114}
115
116QString QgsJoinByLocationSummaryAlgorithm::shortDescription() const
117{
118 return QObject::tr( "Calculates summaries of attributes from one vector layer to another by location." );
119}
120
121QIcon QgsJoinByLocationSummaryAlgorithm::icon() const
122{
123 return QgsApplication::getThemeIcon( u"/algorithms/mAlgorithmBasicStatistics.svg"_s );
124}
125
126QString QgsJoinByLocationSummaryAlgorithm::svgIconPath() const
127{
128 return QgsApplication::iconPath( u"/algorithms/mAlgorithmBasicStatistics.svg"_s );
129}
130
131QgsJoinByLocationSummaryAlgorithm *QgsJoinByLocationSummaryAlgorithm::createInstance() const
132{
133 return new QgsJoinByLocationSummaryAlgorithm();
134}
135
136QVariantMap QgsJoinByLocationSummaryAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
137{
138 std::unique_ptr<QgsProcessingFeatureSource> baseSource( parameterAsSource( parameters, u"INPUT"_s, context ) );
139 if ( !baseSource )
140 throw QgsProcessingException( invalidSourceError( parameters, u"INPUT"_s ) );
141
142 std::unique_ptr<QgsProcessingFeatureSource> joinSource( parameterAsSource( parameters, u"JOIN"_s, context ) );
143 if ( !joinSource )
144 throw QgsProcessingException( invalidSourceError( parameters, u"JOIN"_s ) );
145
146 if ( joinSource->hasSpatialIndex() == Qgis::SpatialIndexPresence::NotPresent )
147 feedback->reportError( QObject::tr( "No spatial index exists for join layer, performance will be severely degraded" ) );
148
149 QStringList joinedFieldNames = parameterAsStrings( parameters, u"JOIN_FIELDS"_s, context );
150
151 bool discardNonMatching = parameterAsBoolean( parameters, u"DISCARD_NONMATCHING"_s, context );
152
153 QList<int> summaries = parameterAsEnums( parameters, u"SUMMARIES"_s, context );
154 if ( summaries.empty() )
155 {
156 for ( int i = 0; i < mAllSummaries.size(); ++i )
157 summaries << i;
158 }
159
160 QgsFields sourceFields = baseSource->fields();
161 QgsFields fieldsToJoin;
162 QList<int> joinFieldIndices;
163 if ( joinedFieldNames.empty() )
164 {
165 // no fields selected, use all
166 for ( const QgsField &sourceField : joinSource->fields() )
167 {
168 joinedFieldNames.append( sourceField.name() );
169 }
170 }
171
172 // Adds a field to the output, keeping the same data type as the original
173 auto addFieldKeepType = [&fieldsToJoin]( const QgsField &original, const QString &statistic ) {
174 QgsField field = QgsField( original );
175 field.setName( field.name() + '_' + statistic );
176 fieldsToJoin.append( field );
177 };
178
179 // Adds a field to the output, with a specified type
180 auto addFieldWithType = [&fieldsToJoin]( const QgsField &original, const QString &statistic, QMetaType::Type type ) {
181 QgsField field = QgsField( original );
182 field.setName( field.name() + '_' + statistic );
183 field.setType( type );
184 if ( type == QMetaType::Type::Double )
185 {
186 field.setLength( 20 );
187 field.setPrecision( 6 );
188 }
189 fieldsToJoin.append( field );
190 };
191
192 enum class FieldType
193 {
194 Numeric,
195 DateTime,
196 String
197 };
198 QList<FieldType> fieldTypes;
199
200 struct FieldStatistic
201 {
202 FieldStatistic( int enumIndex, const QString &name, QMetaType::Type type )
203 : enumIndex( enumIndex )
204 , name( name )
205 , type( type )
206 {}
207
208 int enumIndex = 0;
209 QString name;
210 QMetaType::Type type;
211 };
212 static const QVector<FieldStatistic> sNumericStats {
213 FieldStatistic( 0, u"count"_s, QMetaType::Type::LongLong ),
214 FieldStatistic( 1, u"unique"_s, QMetaType::Type::LongLong ),
215 FieldStatistic( 2, u"min"_s, QMetaType::Type::Double ),
216 FieldStatistic( 3, u"max"_s, QMetaType::Type::Double ),
217 FieldStatistic( 4, u"range"_s, QMetaType::Type::Double ),
218 FieldStatistic( 5, u"sum"_s, QMetaType::Type::Double ),
219 FieldStatistic( 6, u"mean"_s, QMetaType::Type::Double ),
220 FieldStatistic( 7, u"median"_s, QMetaType::Type::Double ),
221 FieldStatistic( 8, u"stddev"_s, QMetaType::Type::Double ),
222 FieldStatistic( 9, u"minority"_s, QMetaType::Type::Double ),
223 FieldStatistic( 10, u"majority"_s, QMetaType::Type::Double ),
224 FieldStatistic( 11, u"q1"_s, QMetaType::Type::Double ),
225 FieldStatistic( 12, u"q3"_s, QMetaType::Type::Double ),
226 FieldStatistic( 13, u"iqr"_s, QMetaType::Type::Double ),
227 };
228 static const QVector<FieldStatistic> sDateTimeStats {
229 FieldStatistic( 0, u"count"_s, QMetaType::Type::LongLong ),
230 FieldStatistic( 1, u"unique"_s, QMetaType::Type::LongLong ),
231 FieldStatistic( 14, u"empty"_s, QMetaType::Type::LongLong ),
232 FieldStatistic( 15, u"filled"_s, QMetaType::Type::LongLong ),
233 FieldStatistic( 2, u"min"_s, QMetaType::Type::UnknownType ),
234 FieldStatistic( 3, u"max"_s, QMetaType::Type::UnknownType ),
235 };
236 static const QVector<FieldStatistic> sStringStats {
237 FieldStatistic( 0, u"count"_s, QMetaType::Type::LongLong ),
238 FieldStatistic( 1, u"unique"_s, QMetaType::Type::LongLong ),
239 FieldStatistic( 14, u"empty"_s, QMetaType::Type::LongLong ),
240 FieldStatistic( 15, u"filled"_s, QMetaType::Type::LongLong ),
241 FieldStatistic( 2, u"min"_s, QMetaType::Type::UnknownType ),
242 FieldStatistic( 3, u"max"_s, QMetaType::Type::UnknownType ),
243 FieldStatistic( 16, u"min_length"_s, QMetaType::Type::Int ),
244 FieldStatistic( 17, u"max_length"_s, QMetaType::Type::Int ),
245 FieldStatistic( 18, u"mean_length"_s, QMetaType::Type::Double ),
246 };
247
248 for ( const QString &field : std::as_const( joinedFieldNames ) )
249 {
250 const int fieldIndex = joinSource->fields().lookupField( field );
251 if ( fieldIndex >= 0 )
252 {
253 joinFieldIndices.append( fieldIndex );
254
255 const QgsField joinField = joinSource->fields().at( fieldIndex );
256 QVector<FieldStatistic> statisticList;
257 if ( joinField.isNumeric() )
258 {
259 fieldTypes.append( FieldType::Numeric );
260 statisticList = sNumericStats;
261 }
262 else if ( joinField.type() == QMetaType::Type::QDate
263 || joinField.type() == QMetaType::Type::QTime
264 || joinField.type() == QMetaType::Type::QDateTime )
265 {
266 fieldTypes.append( FieldType::DateTime );
267 statisticList = sDateTimeStats;
268 }
269 else
270 {
271 fieldTypes.append( FieldType::String );
272 statisticList = sStringStats;
273 }
274
275 for ( const FieldStatistic &statistic : std::as_const( statisticList ) )
276 {
277 if ( summaries.contains( statistic.enumIndex ) )
278 {
279 if ( statistic.type != QMetaType::Type::UnknownType )
280 addFieldWithType( joinField, statistic.name, statistic.type );
281 else
282 addFieldKeepType( joinField, statistic.name );
283 }
284 }
285 }
286 }
287
288 const QgsFields outputFields = QgsProcessingUtils::combineFields( sourceFields, fieldsToJoin );
289
290 QString destId;
291 std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, u"OUTPUT"_s, context, destId, outputFields, baseSource->wkbType(), baseSource->sourceCrs() ) );
292
293 if ( !sink )
294 throw QgsProcessingException( invalidSinkError( parameters, u"OUTPUT"_s ) );
295
296
297 QList<int> predicates = parameterAsEnums( parameters, u"PREDICATE"_s, context );
298 QgsJoinByLocationAlgorithm::sortPredicates( predicates );
299
300 QgsFeatureIterator sourceIter = baseSource->getFeatures();
301 QgsFeature f;
302 const double step = baseSource->featureCount() > 0 ? 100.0 / baseSource->featureCount() : 1;
303 long long i = 0;
304 while ( sourceIter.nextFeature( f ) )
305 {
306 if ( feedback->isCanceled() )
307 break;
308
309 if ( !f.hasGeometry() )
310 {
311 if ( !discardNonMatching )
312 {
313 // ensure consistent count of attributes - otherwise non matching
314 // features will have incorrect attribute length
315 // and provider may reject them
316 f.resizeAttributes( outputFields.size() );
317 if ( !sink->addFeature( f, QgsFeatureSink::FastInsert ) )
318 throw QgsProcessingException( writeFeatureError( sink.get(), parameters, u"OUTPUT"_s ) );
319 }
320 continue;
321 }
322
323 std::unique_ptr<QgsGeometryEngine> engine;
324 QVector<QVector<QVariant>> values;
325
326 QgsFeatureRequest request;
327 request.setFilterRect( f.geometry().boundingBox() );
328 request.setSubsetOfAttributes( joinFieldIndices );
329 request.setDestinationCrs( baseSource->sourceCrs(), context.transformContext() );
330
331 QgsFeatureIterator joinIter = joinSource->getFeatures( request );
332 QgsFeature testJoinFeature;
333 while ( joinIter.nextFeature( testJoinFeature ) )
334 {
335 if ( feedback->isCanceled() )
336 break;
337
338 if ( !engine )
339 {
340 engine.reset( QgsGeometry::createGeometryEngine( f.geometry().constGet() ) );
341 engine->prepareGeometry();
342 }
343
344 if ( QgsJoinByLocationAlgorithm::featureFilter( testJoinFeature, engine.get(), true, predicates ) )
345 {
346 QgsAttributes joinAttributes;
347 joinAttributes.reserve( joinFieldIndices.size() );
348 for ( int joinIndex : std::as_const( joinFieldIndices ) )
349 {
350 joinAttributes.append( testJoinFeature.attribute( joinIndex ) );
351 }
352 values.append( joinAttributes );
353 }
354 }
355
356 i++;
357 feedback->setProgress( i * step );
358
359 if ( feedback->isCanceled() )
360 break;
361
362 if ( values.empty() )
363 {
364 if ( discardNonMatching )
365 {
366 continue;
367 }
368 else
369 {
370 // ensure consistent count of attributes - otherwise non matching
371 // features will have incorrect attribute length
372 // and provider may reject them
373 f.resizeAttributes( outputFields.size() );
374 if ( !sink->addFeature( f, QgsFeatureSink::FastInsert ) )
375 throw QgsProcessingException( writeFeatureError( sink.get(), parameters, u"OUTPUT"_s ) );
376 }
377 }
378 else
379 {
380 // calculate statistics
381 QgsAttributes outputAttributes = f.attributes();
382 outputAttributes.reserve( outputFields.size() );
383 for ( int fieldIndex = 0; fieldIndex < joinFieldIndices.size(); ++fieldIndex )
384 {
385 const FieldType &fieldType = fieldTypes.at( fieldIndex );
386 switch ( fieldType )
387 {
388 case FieldType::Numeric:
389 {
391 for ( const QVector<QVariant> &value : std::as_const( values ) )
392 {
393 stat.addVariant( value.at( fieldIndex ) );
394 }
395 stat.finalize();
396 for ( const FieldStatistic &statistic : sNumericStats )
397 {
398 if ( summaries.contains( statistic.enumIndex ) )
399 {
400 QVariant val;
401 switch ( statistic.enumIndex )
402 {
403 case 0:
404 val = stat.count();
405 break;
406 case 1:
407 val = stat.variety();
408 break;
409 case 2:
410 val = stat.min();
411 break;
412 case 3:
413 val = stat.max();
414 break;
415 case 4:
416 val = stat.range();
417 break;
418 case 5:
419 val = stat.sum();
420 break;
421 case 6:
422 val = stat.mean();
423 break;
424 case 7:
425 val = stat.median();
426 break;
427 case 8:
428 val = stat.stDev();
429 break;
430 case 9:
431 val = stat.minority();
432 break;
433 case 10:
434 val = stat.majority();
435 break;
436 case 11:
437 val = stat.firstQuartile();
438 break;
439 case 12:
440 val = stat.thirdQuartile();
441 break;
442 case 13:
443 val = stat.interQuartileRange();
444 break;
445 }
446 if ( val.isValid() && std::isnan( val.toDouble() ) )
447 val = QVariant();
448 outputAttributes.append( val );
449 }
450 }
451 break;
452 }
453
454 case FieldType::DateTime:
455 {
457 QVariantList inputValues;
458 inputValues.reserve( values.size() );
459 for ( const QVector<QVariant> &value : std::as_const( values ) )
460 {
461 inputValues << value.at( fieldIndex );
462 }
463 stat.calculate( inputValues );
464 for ( const FieldStatistic &statistic : sDateTimeStats )
465 {
466 if ( summaries.contains( statistic.enumIndex ) )
467 {
468 QVariant val;
469 switch ( statistic.enumIndex )
470 {
471 case 0:
472 val = stat.count();
473 break;
474 case 1:
475 val = stat.countDistinct();
476 break;
477 case 2:
478 val = stat.min();
479 break;
480 case 3:
481 val = stat.max();
482 break;
483 case 14:
484 val = stat.countMissing();
485 break;
486 case 15:
487 val = stat.count() - stat.countMissing();
488 break;
489 }
490 outputAttributes.append( val );
491 }
492 }
493 break;
494 }
495
496 case FieldType::String:
497 {
499 QVariantList inputValues;
500 inputValues.reserve( values.size() );
501 for ( const QVector<QVariant> &value : std::as_const( values ) )
502 {
503 if ( value.at( fieldIndex ).isNull() )
504 stat.addString( QString() );
505 else
506 stat.addString( value.at( fieldIndex ).toString() );
507 }
508 stat.finalize();
509 for ( const FieldStatistic &statistic : sStringStats )
510 {
511 if ( summaries.contains( statistic.enumIndex ) )
512 {
513 QVariant val;
514 switch ( statistic.enumIndex )
515 {
516 case 0:
517 val = stat.count();
518 break;
519 case 1:
520 val = stat.countDistinct();
521 break;
522 case 2:
523 val = stat.min();
524 break;
525 case 3:
526 val = stat.max();
527 break;
528 case 14:
529 val = stat.countMissing();
530 break;
531 case 15:
532 val = stat.count() - stat.countMissing();
533 break;
534 case 16:
535 val = stat.minLength();
536 break;
537 case 17:
538 val = stat.maxLength();
539 break;
540 case 18:
541 val = stat.meanLength();
542 break;
543 }
544 outputAttributes.append( val );
545 }
546 }
547 break;
548 }
549 }
550 }
551
552 f.setAttributes( outputAttributes );
553 if ( !sink->addFeature( f, QgsFeatureSink::FastInsert ) )
554 throw QgsProcessingException( writeFeatureError( sink.get(), parameters, u"OUTPUT"_s ) );
555 }
556 }
557
558 sink->finalize();
559 sink.reset();
560
561 QVariantMap results;
562 results.insert( u"OUTPUT"_s, destId );
563 return results;
564}
565
@ VectorAnyGeometry
Any vector layer with geometry.
Definition qgis.h:3604
@ NotPresent
No spatial index exists for the source.
Definition qgis.h:579
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
A vector of attributes.
Calculator for summary statistics and aggregates for a list of datetimes.
void calculate(const QVariantList &values)
Calculates summary statistics for a list of variants.
QDateTime min() const
Returns the minimum (earliest) non-null datetime value.
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.
QDateTime max() const
Returns the maximum (latest) non-null datetime value.
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 & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QgsFeatureRequest & setDestinationCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets the destination crs for feature's geometries.
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
@ 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 resizeAttributes(int fieldCount)
Resizes the attributes attached to this feature to the given number of fields.
QgsAttributes attributes
Definition qgsfeature.h:69
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
QgsGeometry geometry
Definition qgsfeature.h:71
bool hasGeometry() const
Returns true if the feature has an associated geometry.
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
QString name
Definition qgsfield.h:65
void setPrecision(int precision)
Set the field precision.
Definition qgsfield.cpp:267
void setName(const QString &name)
Set the field name.
Definition qgsfield.cpp:233
void setType(QMetaType::Type type)
Set variant type.
Definition qgsfield.cpp:238
void setLength(int len)
Set the field length.
Definition qgsfield.cpp:263
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
int size() const
Returns number of items.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry, double precision=0.0, Qgis::GeosCreationFlags flags=Qgis::GeosCreationFlag::SkipEmptyInteriorRings)
Creates and returns a new geometry engine representing the specified geometry using precision on a gr...
Contains information about the context in which a processing algorithm is executed.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
A boolean parameter 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.
static QgsFields combineFields(const QgsFields &fieldsA, const QgsFields &fieldsB, const QString &fieldsBPrefix=QString())
Combines two field lists, avoiding duplicate field names (in a case-insensitive manner).
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.
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 addString(const QString &string)
Adds a single string to the statistics calculation.
int minLength() const
Returns the minimum length of strings.
int maxLength() const
Returns the maximum length of strings.
double meanLength() const
Returns the mean length of strings.