QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
classification
qgsclassificationquantile.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsclassificationquantile.h
3
---------------------
4
begin : September 2019
5
copyright : (C) 2019 by Denis Rouzaud
6
email : denis@opengis.ch
7
***************************************************************************
8
* *
9
* This program is free software; you can redistribute it and/or modify *
10
* it under the terms of the GNU General Public License as published by *
11
* the Free Software Foundation; either version 2 of the License, or *
12
* (at your option) any later version. *
13
* *
14
***************************************************************************/
15
16
17
#include "
qgsclassificationquantile.h
"
18
19
#include "
qgsapplication.h
"
20
21
#include <QString>
22
23
using namespace
Qt::StringLiterals;
24
25
QgsClassificationQuantile::QgsClassificationQuantile
()
26
:
QgsClassificationMethod
()
27
{}
28
29
QString
QgsClassificationQuantile::name
()
const
30
{
31
return
QObject::tr(
"Equal Count (Quantile)"
);
32
}
33
34
QString
QgsClassificationQuantile::id
()
const
35
{
36
return
u
"Quantile"
_s;
37
}
38
39
std::unique_ptr<QgsClassificationMethod>
QgsClassificationQuantile::clone
()
const
40
{
41
auto
c
= std::make_unique< QgsClassificationQuantile >();
42
copyBase
(
c
.get() );
43
return
c
;
44
}
45
46
QIcon
QgsClassificationQuantile::icon
()
const
47
{
48
return
QgsApplication::getThemeIcon
(
"classification_methods/mClassificationEqualCount.svg"
);
49
}
50
51
52
QList<double> QgsClassificationQuantile::calculateBreaks(
double
&minimum,
double
&maximum,
const
QList<double> &values,
int
nclasses, QString &error )
53
{
54
Q_UNUSED( minimum )
55
Q_UNUSED( maximum )
56
Q_UNUSED( error )
57
58
// q-th quantile of a data set:
59
// value where q fraction of data is below and (1-q) fraction is above this value
60
// Xq = (1 - r) * X_NI1 + r * X_NI2
61
// NI1 = (int) (q * (n+1))
62
// NI2 = NI1 + 1
63
// r = q * (n+1) - (int) (q * (n+1))
64
// (indices of X: 1...n)
65
66
// sort the values first
67
QList<double> _values = values;
68
std::sort( _values.begin(), _values.end() );
69
70
QList<double> breaks;
71
72
// If there are no values to process: bail out
73
if
( _values.isEmpty() )
74
return
QList<double>();
75
76
const
int
n = _values.count();
77
double
Xq = n > 0 ? _values[0] : 0.0;
78
79
breaks.reserve( nclasses );
80
for
(
int
i = 1; i < nclasses; i++ )
81
{
82
if
( n > 1 )
83
{
84
const
double
q = i /
static_cast<
double
>
( nclasses );
85
const
double
a = q * ( n - 1 );
86
const
int
aa =
static_cast<
int
>
( a );
87
88
const
double
r = a - aa;
89
Xq = ( 1 - r ) * _values[aa] + r * _values[aa + 1];
90
}
91
breaks.append( Xq );
92
}
93
94
breaks.append( _values[n - 1] );
95
96
return
breaks;
97
}
QgsApplication::getThemeIcon
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Definition
qgsapplication.cpp:904
QgsClassificationMethod::QgsClassificationMethod
QgsClassificationMethod(MethodProperties properties=NoFlag, int codeComplexity=1)
Creates a classification method.
Definition
qgsclassificationmethod.cpp:45
QgsClassificationMethod::copyBase
void copyBase(QgsClassificationMethod *c) const
Copy the parameters (shall be used in clone implementation).
Definition
qgsclassificationmethod.cpp:56
QgsClassificationQuantile::clone
std::unique_ptr< QgsClassificationMethod > clone() const override
Returns a clone of the method.
Definition
qgsclassificationquantile.cpp:39
QgsClassificationQuantile::QgsClassificationQuantile
QgsClassificationQuantile()
Definition
qgsclassificationquantile.cpp:25
QgsClassificationQuantile::id
QString id() const override
The id of the method as saved in the project, must be unique in registry.
Definition
qgsclassificationquantile.cpp:34
QgsClassificationQuantile::icon
QIcon icon() const override
The icon of the method.
Definition
qgsclassificationquantile.cpp:46
QgsClassificationQuantile::name
QString name() const override
The readable and translate name of the method.
Definition
qgsclassificationquantile.cpp:29
c
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
Definition
porting_processing.dox:1
qgsapplication.h
qgsclassificationquantile.h
Generated on
for QGIS API Documentation by
1.17.0