QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
27 QgsProcessingParameterEnum *param =
new QgsProcessingParameterEnum( QStringLiteral(
"ZERO_NEG_VALUES_HANDLE" ), QObject::tr(
"Handling of 0 or negative values" ), QStringList() << QObject::tr(
"no handling (faster)" ) << QObject::tr(
"discard (slower)" ) << QObject::tr(
"prepend range (slower)" ),
false, 0 );
41 return QObject::tr(
"Logarithmic scale" );
46 return QStringLiteral(
"Logarithmic" );
54 QList<double> QgsClassificationLogarithmic::calculateBreaks(
double &minimum,
double &maximum,
const QList<double> &values,
int nclasses )
60 double positiveMinimum = std::numeric_limits<double>::max();
61 if ( nvh != NegativeValueHandling::NoHandling && minimum <= 0 )
63 Q_ASSERT( values.count() );
66 for (
int i = 0; i < values.count(); i++ )
68 if ( values.at( i ) > 0 )
69 positiveMinimum = std::min( positiveMinimum, values.at( i ) );
72 if ( positiveMinimum == std::numeric_limits<double>::max() )
75 if ( nvh == NegativeValueHandling::PrependBreak )
76 return QList<double>( {0} );
78 return QList<double>();
84 if ( positiveMinimum != std::numeric_limits<double>::max() )
86 if ( nvh == NegativeValueHandling::PrependBreak )
87 breaks << std::floor( std::log10( positiveMinimum ) );
88 else if ( nvh == NegativeValueHandling::Discard )
89 minimum = positiveMinimum;
93 positiveMinimum = minimum;
97 double logMin = std::floor( std::log10( positiveMinimum ) );
98 double logMax = std::ceil( std::log10( maximum ) );
104 for (
int i = 0; i < breaks.count(); i++ )
105 breaks[i] = std::pow( 10, breaks.at( i ) );
110 QString QgsClassificationLogarithmic::valueToLabel(
double value )
const
114 return QString::number( value );
118 if ( std::isnan( value ) )
120 return QObject::tr(
"invalid (0 or negative values in the data)" );
124 return QString( QStringLiteral(
"10^%1" ) ).arg( std::log10( value ) );
132 const QString upperLabel = valueToLabel( upperValue );
141 lowerLabel = valueToLabel( lowerValue );
145 return labelFormat().arg( lowerLabel ).arg( upperLabel );
154 return nvh != NegativeValueHandling::NoHandling;
QgsClassificationMethod is an abstract class for implementations of classification methods.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
QString name() const override
The readable and translate name of the method.
@ UpperBound
The class is at the upper bound.
QString labelForRange(double lowerValue, double upperValue, ClassPosition position) const override
Returns the label for a range.
QString formatNumber(double value) const
Format the number according to label properties.
void addParameter(QgsProcessingParameterDefinition *definition)
Add a parameter to the method.
Base class for the definition of processing parameters.
const QgsProcessingParameterDefinition * parameterDefinition(const QString ¶meterName) const
Returns the parameter from its name.
@ LowerBound
The class is at the lower bound.
QString id() const override
The id of the method as saved in the project, must be unique in registry.
Contains information about the context in which a processing algorithm is executed.
NegativeValueHandling
Handling of negative and 0 values in the method.
static QList< double > prettyBreaks(double minimum, double maximum, int classes)
Computes a sequence of about 'classes' equally spaced round values which cover the range of values fr...
void copyBase(QgsClassificationMethod *c) const
Copy the parameters (shall be used in clone implementation)
@ Inner
The class is not at a bound.
QString labelFormat() const
Returns the format of the label for the classes.
QgsClassificationLogarithmic()
Implementation of a logarithmic scale method.
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
ClassPosition
Defines the class position.
bool valuesRequired() const override
Returns if the method requires values to calculate the classes If not, bounds are sufficient.
An enum based parameter for processing algorithms, allowing for selection from predefined values.
QgsClassificationMethod * clone() const override
Returns a clone of the method.
static int parameterAsEnum(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a enum value.
QVariantMap parameterValues() const
Returns the values of the processing parameters.
QIcon icon() const override
The icon of the method.