QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
QgsStatisticalSummary Class Reference

Calculator for summary statistics for a list of doubles. More...

#include <qgsstatisticalsummary.h>

Public Member Functions

 QgsStatisticalSummary (Qgis::Statistics stats=Qgis::Statistic::All)
 Constructor for QgsStatisticalSummary.
virtual ~QgsStatisticalSummary ()=default
void addValue (double value)
 Adds a single value to the statistics calculation.
void addVariant (const QVariant &value)
 Adds a single value to the statistics calculation.
void calculate (const QList< double > &values)
 Calculates summary statistics for a list of values.
int count () const
 Returns calculated count of values.
int countMissing () const
 Returns the number of missing (null) values.
void finalize ()
 Must be called after adding all values with addValues() and before retrieving any calculated statistics.
double first () const
 Returns the first value obtained.
double firstQuartile () const
 Returns the first quartile of the values.
double interQuartileRange () const
 Returns the inter quartile range of the values.
double last () const
 Returns the last value obtained.
double majority () const
 Returns majority of values.
double max () const
 Returns calculated maximum from values.
double mean () const
 Returns calculated mean of values.
double median () const
 Returns calculated median of values.
double min () const
 Returns calculated minimum from values.
double minority () const
 Returns minority of values.
double range () const
 Returns calculated range (difference between maximum and minimum values).
void reset ()
 Resets the calculated values.
double sampleStDev () const
 Returns sample standard deviation.
void setStatistics (Qgis::Statistics stats)
 Sets flags which specify which statistics will be calculated.
double statistic (Qgis::Statistic stat) const
 Returns the value of a specified statistic.
Qgis::Statistics statistics () const
 Returns flags which specify which statistics will be calculated.
double stDev () const
 Returns population standard deviation.
double sum () const
 Returns calculated sum of values.
double thirdQuartile () const
 Returns the third quartile of the values.
int variety () const
 Returns variety of values.

Static Public Member Functions

static QString displayName (Qgis::Statistic statistic)
 Returns the friendly display name for a statistic.
static QString shortName (Qgis::Statistic statistic)
 Returns a short, friendly display name for a statistic, suitable for use in a field name.

Detailed Description

Calculator for summary statistics for a list of doubles.

Statistics are calculated by calling calculate() and passing a list of doubles. The individual statistics can then be retrieved using the associated methods. Note that not all statistics are calculated by default. Statistics which require slower computations are only calculated by specifying the statistic in the constructor or via setStatistics().

Definition at line 46 of file qgsstatisticalsummary.h.

Constructor & Destructor Documentation

◆ QgsStatisticalSummary()

QgsStatisticalSummary::QgsStatisticalSummary ( Qgis::Statistics stats = Qgis::Statistic::All)

Constructor for QgsStatisticalSummary.

Parameters
statsflags for statistics to calculate

Definition at line 31 of file qgsstatisticalsummary.cpp.

◆ ~QgsStatisticalSummary()

virtual QgsStatisticalSummary::~QgsStatisticalSummary ( )
virtualdefault

Member Function Documentation

◆ addValue()

void QgsStatisticalSummary::addValue ( double value)

Adds a single value to the statistics calculation.

Calling this method allows values to be added to the calculation one at a time. For large quantities of values this may be more efficient then first adding all the values to a list and calling calculate().

Parameters
valuevalue to add
Note
call reset() before adding the first value using this method to clear the results from any previous calculations
finalize() must be called after adding the final value and before retrieving calculated statistics.
See also
calculate()
addVariant()
finalize()

Definition at line 88 of file qgsstatisticalsummary.cpp.

◆ addVariant()

void QgsStatisticalSummary::addVariant ( const QVariant & value)

Adds a single value to the statistics calculation.

Calling this method allows values to be added to the calculation one at a time. For large quantities of values this may be more efficient then first adding all the values to a list and calling calculate().

Parameters
valuevariant containing to add. Non-numeric values are treated as null.
Note
call reset() before adding the first value using this method to clear the results from any previous calculations
finalize() must be called after adding the final value and before retrieving calculated statistics.
See also
addValue()
calculate()
finalize()

Definition at line 105 of file qgsstatisticalsummary.cpp.

◆ calculate()

void QgsStatisticalSummary::calculate ( const QList< double > & values)

Calculates summary statistics for a list of values.

Parameters
valueslist of doubles

Definition at line 76 of file qgsstatisticalsummary.cpp.

◆ count()

int QgsStatisticalSummary::count ( ) const
inline

Returns calculated count of values.

Definition at line 135 of file qgsstatisticalsummary.h.

◆ countMissing()

int QgsStatisticalSummary::countMissing ( ) const
inline

Returns the number of missing (null) values.

Definition at line 140 of file qgsstatisticalsummary.h.

◆ displayName()

QString QgsStatisticalSummary::displayName ( Qgis::Statistic statistic)
static

Returns the friendly display name for a statistic.

See also
shortName()

Definition at line 301 of file qgsstatisticalsummary.cpp.

◆ finalize()

void QgsStatisticalSummary::finalize ( )

Must be called after adding all values with addValues() and before retrieving any calculated statistics.

See also
addValue()
addVariant()

Definition at line 120 of file qgsstatisticalsummary.cpp.

◆ first()

double QgsStatisticalSummary::first ( ) const
inline

Returns the first value obtained.

A NaN value may be returned if no values were encountered.

See also
last()
Since
QGIS 3.6

Definition at line 184 of file qgsstatisticalsummary.h.

◆ firstQuartile()

double QgsStatisticalSummary::firstQuartile ( ) const
inline

Returns the first quartile of the values.

The quartile is calculated using the "Tukey's hinges" method. A NaN value may be returned if the first quartile cannot be calculated.

See also
thirdQuartile
interQuartileRange

Definition at line 242 of file qgsstatisticalsummary.h.

◆ interQuartileRange()

double QgsStatisticalSummary::interQuartileRange ( ) const
inline

Returns the inter quartile range of the values.

The quartiles are calculated using the "Tukey's hinges" method. A NaN value may be returned if the IQR cannot be calculated.

See also
firstQuartile
thirdQuartile

Definition at line 260 of file qgsstatisticalsummary.h.

◆ last()

double QgsStatisticalSummary::last ( ) const
inline

Returns the last value obtained.

A NaN value may be returned if no values were encountered.

See also
first()
Since
QGIS 3.6

Definition at line 192 of file qgsstatisticalsummary.h.

◆ majority()

double QgsStatisticalSummary::majority ( ) const
inline

Returns majority of values.

The majority is the value with most occurrences in the list. This is only calculated if Statistic::Majority has been specified in the constructor or via setStatistics. If multiple values match, return the first value relative to the initial values order. A NaN value may be returned if the minority cannot be calculated.

See also
minority

Definition at line 233 of file qgsstatisticalsummary.h.

◆ max()

double QgsStatisticalSummary::max ( ) const
inline

Returns calculated maximum from values.

A NaN value may be returned if the maximum cannot be calculated.

Definition at line 170 of file qgsstatisticalsummary.h.

◆ mean()

double QgsStatisticalSummary::mean ( ) const
inline

Returns calculated mean of values.

A NaN value may be returned if the mean cannot be calculated.

Definition at line 151 of file qgsstatisticalsummary.h.

◆ median()

double QgsStatisticalSummary::median ( ) const
inline

Returns calculated median of values.

This is only calculated if Statistic::Median has been specified in the constructor or via setStatistics. A NaN value may be returned if the median cannot be calculated.

Definition at line 158 of file qgsstatisticalsummary.h.

◆ min()

double QgsStatisticalSummary::min ( ) const
inline

Returns calculated minimum from values.

A NaN value may be returned if the minimum cannot be calculated.

Definition at line 164 of file qgsstatisticalsummary.h.

◆ minority()

double QgsStatisticalSummary::minority ( ) const
inline

Returns minority of values.

The minority is the value with least occurrences in the list. This is only calculated if Statistic::Minority has been specified in the constructor or via setStatistics. If multiple values match, return the first value relative to the initial values order. A NaN value may be returned if the minority cannot be calculated.

See also
majority

Definition at line 224 of file qgsstatisticalsummary.h.

◆ range()

double QgsStatisticalSummary::range ( ) const
inline

Returns calculated range (difference between maximum and minimum values).

A NaN value may be returned if the range cannot be calculated.

Definition at line 176 of file qgsstatisticalsummary.h.

◆ reset()

void QgsStatisticalSummary::reset ( )

Resets the calculated values.

Definition at line 43 of file qgsstatisticalsummary.cpp.

◆ sampleStDev()

double QgsStatisticalSummary::sampleStDev ( ) const
inline

Returns sample standard deviation.

This is only calculated if Statistic::StDev has been specified in the constructor or via setStatistics. A NaN value may be returned if the standard deviation cannot be calculated.

See also
stDev

Definition at line 208 of file qgsstatisticalsummary.h.

◆ setStatistics()

void QgsStatisticalSummary::setStatistics ( Qgis::Statistics stats)

Sets flags which specify which statistics will be calculated.

Some statistics are always calculated (e.g., sum, min and max).

Parameters
statsflags for statistics to calculate
See also
statistics

Definition at line 37 of file qgsstatisticalsummary.cpp.

◆ shortName()

QString QgsStatisticalSummary::shortName ( Qgis::Statistic statistic)
static

Returns a short, friendly display name for a statistic, suitable for use in a field name.

See also
displayName()
Since
QGIS 3.6

Definition at line 347 of file qgsstatisticalsummary.cpp.

◆ statistic()

double QgsStatisticalSummary::statistic ( Qgis::Statistic stat) const

Returns the value of a specified statistic.

Parameters
statstatistic to return
Returns
calculated value of statistic. A NaN value may be returned for invalid statistics.

Definition at line 255 of file qgsstatisticalsummary.cpp.

◆ statistics()

Qgis::Statistics QgsStatisticalSummary::statistics ( ) const
inline

Returns flags which specify which statistics will be calculated.

Some statistics are always calculated (e.g., sum, min and max).

See also
setStatistics

Definition at line 63 of file qgsstatisticalsummary.h.

◆ stDev()

double QgsStatisticalSummary::stDev ( ) const
inline

Returns population standard deviation.

This is only calculated if Statistic::StDev has been specified in the constructor or via setStatistics. A NaN value may be returned if the standard deviation cannot be calculated.

See also
sampleStDev

Definition at line 200 of file qgsstatisticalsummary.h.

◆ sum()

double QgsStatisticalSummary::sum ( ) const
inline

Returns calculated sum of values.

Definition at line 145 of file qgsstatisticalsummary.h.

◆ thirdQuartile()

double QgsStatisticalSummary::thirdQuartile ( ) const
inline

Returns the third quartile of the values.

The quartile is calculated using the "Tukey's hinges" method. A NaN value may be returned if the third quartile cannot be calculated.

See also
firstQuartile
interQuartileRange

Definition at line 251 of file qgsstatisticalsummary.h.

◆ variety()

int QgsStatisticalSummary::variety ( ) const
inline

Returns variety of values.

The variety is the count of unique values from the list. This is only calculated if Statistic::Variety has been specified in the constructor or via setStatistics.

Definition at line 215 of file qgsstatisticalsummary.h.


The documentation for this class was generated from the following files: