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