QGIS API Documentation 4.1.0-Master (0cdd3ae6384)
Loading...
Searching...
No Matches
qgsrasterlayerutils.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsrasterlayerutils.h
3 -------------------------
4 begin : March 2024
5 copyright : (C) 2024 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
18#ifndef QGSRASTERLAYERUTILS_H
19#define QGSRASTERLAYERUTILS_H
20
21#include "qgis.h"
22#include "qgis_core.h"
23#include "qgis_sip.h"
24#include "qgspointxy.h"
25#include "qgsrange.h"
26
27#include <QColor>
28#include <QString>
29
30using namespace Qt::StringLiterals;
31
32class QgsRasterLayer;
35class QgsRectangle;
36
46class CORE_EXPORT QgsRasterReliefColor
47{
48 public:
55 QgsRasterReliefColor( const QColor &c, double min, double max )
56 : color( c )
57 , minElevation( min )
58 , maxElevation( max )
59 {}
60
62 QColor color;
64 double minElevation = 0;
66 double maxElevation = 0;
67
68 bool operator==( const QgsRasterReliefColor &other ) const
69 {
71 }
72
73 bool operator!=( const QgsRasterReliefColor &other ) const { return !( *this == other ); }
74
75#ifdef SIP_RUN
76 // clang-format off
77 SIP_PYOBJECT __repr__();
78 % MethodCode
79 QString str = u"<QgsRasterReliefColor: %1-%2 (%3)>"_s.arg( qgsDoubleToString( sipCpp->minElevation ), qgsDoubleToString( sipCpp->maxElevation ), sipCpp->color.name() );
80 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
81 % End
82// clang-format on
83#endif
84};
85
93class CORE_EXPORT QgsRasterLayerUtils
94{
95 public:
108 static int renderedBandForElevationAndTemporalRange( QgsRasterLayer *layer, const QgsDateTimeRange &temporalRange, const QgsDoubleRange &elevationRange, bool &matched SIP_OUT );
109
116 static void computeMinMax(
117 QgsRasterDataProvider *provider, int band, const QgsRasterMinMaxOrigin &mmo, Qgis::RasterRangeLimit limits, const QgsRectangle &extent, int sampleSize, double &min SIP_OUT, double &max SIP_OUT
118 );
119
130 static QgsRectangle alignRasterExtent( const QgsRectangle &extent, const QgsPointXY &origin, double pixelSizeX, double pixelSizeY );
131
137 static QList<QgsRasterReliefColor> calculateOptimizedReliefClasses( QgsRasterDataProvider *provider, int band );
138
139 private:
144 static int frequencyClassForElevation( double elevation, double minElevation, double elevationClassRange );
145
147 static void optimiseClassBreaks( QList<int> &breaks, double *frequencies );
148
155 static bool calculateRegression( const QList<QPair<int, double>> &input, double &a, double &b );
156};
157
158#endif //QGSRASTERLAYERUTILS_H
RasterRangeLimit
Describes the limits used to compute raster ranges (min/max values).
Definition qgis.h:1665
QgsRange which stores a range of double values.
Definition qgsrange.h:217
Represents a 2D point.
Definition qgspointxy.h:62
Base class for raster data providers.
Contains utility functions for working with raster layers.
static void computeMinMax(QgsRasterDataProvider *provider, int band, const QgsRasterMinMaxOrigin &mmo, Qgis::RasterRangeLimit limits, const QgsRectangle &extent, int sampleSize, double &min, double &max)
Compute the min max values for provider along band according to MinMaxOrigin parameters mmo and exten...
static int renderedBandForElevationAndTemporalRange(QgsRasterLayer *layer, const QgsDateTimeRange &temporalRange, const QgsDoubleRange &elevationRange, bool &matched)
Given a raster layer, returns the band which should be used for rendering the layer for a specified t...
static QList< QgsRasterReliefColor > calculateOptimizedReliefClasses(QgsRasterDataProvider *provider, int band)
Calculates optimized relief class breaks according with the method of Buenzli (2011) using an iterati...
static QgsRectangle alignRasterExtent(const QgsRectangle &extent, const QgsPointXY &origin, double pixelSizeX, double pixelSizeY)
Returns a new extent that includes the given extent with corners coordinates aligned to the pixel gri...
Represents a raster layer.
Describes the origin of minimum and maximum values in a raster.
QgsRasterReliefColor(const QColor &c, double min, double max)
Constructor for QgsRasterReliefColor.
double minElevation
Elevation range minimum.
bool operator!=(const QgsRasterReliefColor &other) const
bool operator==(const QgsRasterReliefColor &other) const
double maxElevation
Elevation range maximum.
A rectangle specified with double values.
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
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition qgis.h:7247
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
Definition qgis.h:7340
#define SIP_OUT
Definition qgis_sip.h:57
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.
Definition qgsrange.h:705