QGIS API Documentation 4.1.0-Master (ca2ac17535b)
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 else
326 feedback->featureAddedToSink( destId );
327 }
328 continue;
329 }
330
331 std::unique_ptr<QgsGeometryEngine> engine;
332 QVector<QVector<QVariant>> values;
333
334 QgsFeatureRequest request;
335 request.setFilterRect( f.geometry().boundingBox() );
336 request.setSubsetOfAttributes( joinFieldIndices );
337 request.setDestinationCrs( baseSource->sourceCrs(), context.transformContext() );
338
339 QgsFeatureIterator joinIter = joinSource->getFeatures( request );
340 QgsFeature testJoinFeature;
341 while ( joinIter.nextFeature( testJoinFeature ) )
342 {
343 if ( feedback->isCanceled() )
344 break;
345
346 if ( !engine )
347 {
348 engine.reset( QgsGeometry::createGeometryEngine( f.geometry().constGet() ) );
349 engine->prepareGeometry();
350 }
351
352 if ( QgsJoinByLocationAlgorithm::featureFilter( testJoinFeature, engine.get(), true, predicates ) )
353 {
354 QgsAttributes joinAttributes;
355 joinAttributes.reserve( joinFieldIndices.size() );
356 for ( int joinIndex : std::as_const( joinFieldIndices ) )
357 {
358 joinAttributes.append( testJoinFeature.attribute( joinIndex ) );
359 }
360 values.append( joinAttributes );
361 }
362 }
363
364 i++;
365 feedback->setProgress( i * step );
366
367 if ( feedback->isCanceled() )
368 break;
369
370 if ( values.empty() )
371 {
372 if ( discardNonMatching )
373 {
374 continue;
375 }
376 else
377 {
378 // ensure consistent count of attributes - otherwise non matching
379 // features will have incorrect attribute length
380 // and provider may reject them
381 f.resizeAttributes( outputFields.size() );
382 if ( !sink->addFeature( f, QgsFeatureSink::FastInsert ) )
383 throw QgsProcessingException( writeFeatureError( sink.get(), parameters, u"OUTPUT"_s ) );
384 else
385 feedback->featureAddedToSink( destId );
386 }
387 }
388 else
389 {
390 // calculate statistics
391 QgsAttributes outputAttributes = f.attributes();
392 outputAttributes.reserve( outputFields.size() );
393 for ( int fieldIndex = 0; fieldIndex < joinFieldIndices.size(); ++fieldIndex )
394 {
395 const FieldType &fieldType = fieldTypes.at( fieldIndex );
396 switch ( fieldType )
397 {
398 case FieldType::Numeric:
399 {
401 for ( const QVector<QVariant> &value : std::as_const( values ) )
402 {
403 stat.addVariant( value.at( fieldIndex ) );
404 }
405 stat.finalize();
406 for ( const FieldStatistic &statistic : sNumericStats )
407 {
408 if ( summaries.contains( statistic.enumIndex ) )
409 {
410 QVariant val;
411 switch ( statistic.enumIndex )
412 {
413 case 0:
414 val = stat.count();
415 break;
416 case 1:
417 val = stat.variety();
418 break;
419 case 2:
420 val = stat.min();
421 break;
422 case 3:
423 val = stat.max();
424 break;
425 case 4:
426 val = stat.range();
427 break;
428 case 5:
429 val = stat.sum();
430 break;
431 case 6:
432 val = stat.mean();
433 break;
434 case 7:
435 val = stat.median();
436 break;
437 case 8:
438 val = stat.stDev();
439 break;
440 case 9:
441 val = stat.minority();
442 break;
443 case 10:
444 val = stat.majority();
445 break;
446 case 11:
447 val = stat.firstQuartile();
448 break;
449 case 12:
450 val = stat.thirdQuartile();
451 break;
452 case 13:
453 val = stat.interQuartileRange();
454 break;
455 }
456 if ( val.isValid() && std::isnan( val.toDouble() ) )
457 val = QVariant();
458 outputAttributes.append( val );
459 }
460 }
461 break;
462 }
463
464 case FieldType::DateTime:
465 {
467 QVariantList inputValues;
468 inputValues.reserve( values.size() );
469 for ( const QVector<QVariant> &value : std::as_const( values ) )
470 {
471 inputValues << value.at( fieldIndex );
472 }
473 stat.calculate( inputValues );
474 for ( const FieldStatistic &statistic : sDateTimeStats )
475 {
476 if ( summaries.contains( statistic.enumIndex ) )
477 {
478 QVariant val;
479 switch ( statistic.enumIndex )
480 {
481 case 0:
482 val = stat.count();
483 break;
484 case 1:
485 val = stat.countDistinct();
486 break;
487 case 2:
488 val = stat.min();
489 break;
490 case 3:
491 val = stat.max();
492 break;
493 case 14:
494 val = stat.countMissing();
495 break;
496 case 15:
497 val = stat.count() - stat.countMissing();
498 break;
499 }
500 outputAttributes.append( val );
501 }
502 }
503 break;
504 }
505
506 case FieldType::String:
507 {
509 QVariantList inputValues;
510 inputValues.reserve( values.size() );
511 for ( const QVector<QVariant> &value : std::as_const( values ) )
512 {
513 if ( value.at( fieldIndex ).isNull() )
514 stat.addString( QString() );
515 else
516 stat.addString( value.at( fieldIndex ).toString() );
517 }
518 stat.finalize();
519 for ( const FieldStatistic &statistic : sStringStats )
520 {
521 if ( summaries.contains( statistic.enumIndex ) )
522 {
523 QVariant val;
524 switch ( statistic.enumIndex )
525 {
526 case 0:
527 val = stat.count();
528 break;
529 case 1:
530 val = stat.countDistinct();
531 break;
532 case 2:
533 val = stat.min();
534 break;
535 case 3:
536 val = stat.max();
537 break;
538 case 14:
539 val = stat.countMissing();
540 break;
541 case 15:
542 val = stat.count() - stat.countMissing();
543 break;
544 case 16:
545 val = stat.minLength();
546 break;
547 case 17:
548 val = stat.maxLength();
549 break;
550 case 18:
551 val = stat.meanLength();
552 break;
553 }
554 outputAttributes.append( val );
555 }
556 }
557 break;
558 }
559 }
560 }
561
562 f.setAttributes( outputAttributes );
563 if ( !sink->addFeature( f, QgsFeatureSink::FastInsert ) )
564 throw QgsProcessingException( writeFeatureError( sink.get(), parameters, u"OUTPUT"_s ) );
565 else
566 feedback->featureAddedToSink( u"OUTPUT"_s );
567 }
568 }
569
570 sink->finalize();
571 feedback->featureSinkFinalized( u"OUTPUT"_s );
572 sink.reset();
573
574 QVariantMap results;
575 results.insert( u"OUTPUT"_s, destId );
576 return results;
577}
578
@ VectorAnyGeometry
Any vector layer with geometry.
Definition qgis.h:3714
@ NotPresent
No spatial index exists for the source.
Definition qgis.h:587
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:64
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
QgsGeometry geometry
Definition qgsfeature.h:66
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.
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.
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.