QGIS API Documentation  2.99.0-Master (314842d)
qgsrelief.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrelief.h - description
3  ---------------------------
4  begin : November 2011
5  copyright : (C) 2011 by Marco Hugentobler
6  email : marco dot hugentobler at sourcepole dot ch
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 QGSRELIEF_H
19 #define QGSRELIEF_H
20 
21 #include <QColor>
22 #include <QMap>
23 #include <QPair>
24 #include <QString>
25 #include "gdal.h"
26 #include "qgis_analysis.h"
27 
28 class QgsAspectFilter;
29 class QgsSlopeFilter;
30 class QgsHillshadeFilter;
31 class QProgressDialog;
32 
35 class ANALYSIS_EXPORT QgsRelief
36 {
37  public:
38  struct ReliefColor
39  {
40  ReliefColor( const QColor &c, double min, double max ): color( c ), minElevation( min ), maxElevation( max ) { }
41  QColor color;
42  double minElevation;
43  double maxElevation;
44  };
45 
46  QgsRelief( const QString &inputFile, const QString &outputFile, const QString &outputFormat );
47  ~QgsRelief();
48 
50  QgsRelief( const QgsRelief &rh ) = delete;
52  QgsRelief &operator=( const QgsRelief &rh ) = delete;
53 
57  int processRaster( QProgressDialog *p );
58 
59  double zFactor() const { return mZFactor; }
60  void setZFactor( double factor ) { mZFactor = factor; }
61 
62  void clearReliefColors();
63  void addReliefColorClass( const ReliefColor &color );
64  QList< ReliefColor > reliefColors() const { return mReliefColors; }
65  void setReliefColors( const QList< ReliefColor > &c ) { mReliefColors = c; }
66 
69  QList< ReliefColor > calculateOptimizedReliefClasses();
70 
72  bool exportFrequencyDistributionToCsv( const QString &file );
73 
74  private:
75 
76  QString mInputFile;
77  QString mOutputFile;
78  QString mOutputFormat;
79 
80  double mCellSizeX;
81  double mCellSizeY;
83  float mInputNodataValue;
85  float mOutputNodataValue;
86 
87  double mZFactor;
88 
89  QgsSlopeFilter *mSlopeFilter = nullptr;
90  QgsAspectFilter *mAspectFilter = nullptr;
91  QgsHillshadeFilter *mHillshadeFilter285 = nullptr;
92  QgsHillshadeFilter *mHillshadeFilter300 = nullptr;
93  QgsHillshadeFilter *mHillshadeFilter315 = nullptr;
94 
95  //relief colors and corresponding elevations
96  QList< ReliefColor > mReliefColors;
97 
98  bool processNineCellWindow( float *x1, float *x2, float *x3, float *x4, float *x5, float *x6, float *x7, float *x8, float *x9,
99  unsigned char *red, unsigned char *green, unsigned char *blue );
100 
102  GDALDatasetH openInputFile( int &nCellsX, int &nCellsY );
103 
106  GDALDriverH openOutputDriver();
107 
110  GDALDatasetH openOutputFile( GDALDatasetH inputDataset, GDALDriverH outputDriver );
111 
113  bool setElevationColor( double elevation, int *red, int *green, int *blue );
114 
116  void setDefaultReliefColors();
117 
120  int frequencyClassForElevation( double elevation, double minElevation, double elevationClassRange );
122  void optimiseClassBreaks( QList<int> &breaks, double *frequencies );
123 
129  bool calculateRegression( const QList< QPair < int, double > > &input, double &a, double &b );
130 
131 };
132 
133 #endif // QGSRELIEF_H
QList< ReliefColor > reliefColors() const
Definition: qgsrelief.h:64
double zFactor() const
Definition: qgsrelief.h:59
void setZFactor(double factor)
Definition: qgsrelief.h:60
Calculates aspect values in a window of 3x3 cells based on first order derivatives in x- and y- direc...
double ANALYSIS_EXPORT min(double x, double y)
Returns the minimum of two doubles or the first argument if both are equal.
Definition: MathUtils.cc:452
void * GDALDatasetH
ReliefColor(const QColor &c, double min, double max)
Definition: qgsrelief.h:40
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
Definition: MathUtils.cc:437
Calculates slope values in a window of 3x3 cells based on first order derivatives in x- and y- direct...
void setReliefColors(const QList< ReliefColor > &c)
Definition: qgsrelief.h:65
Produces colored relief rasters from DEM.
Definition: qgsrelief.h:35