QGIS API Documentation  2.99.0-Master (ae4d26a)
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 QgsFeedback;
32 
36 class ANALYSIS_EXPORT QgsRelief
37 {
38  public:
39  struct ReliefColor
40  {
41  ReliefColor( const QColor &c, double min, double max ): color( c ), minElevation( min ), maxElevation( max ) { }
42  QColor color;
43  double minElevation;
44  double maxElevation;
45  };
46 
47  QgsRelief( const QString &inputFile, const QString &outputFile, const QString &outputFormat );
48  ~QgsRelief();
49 
51  QgsRelief( const QgsRelief &rh ) = delete;
53  QgsRelief &operator=( const QgsRelief &rh ) = delete;
54 
59  int processRaster( QgsFeedback *feedback = nullptr );
60 
61  double zFactor() const { return mZFactor; }
62  void setZFactor( double factor ) { mZFactor = factor; }
63 
64  void clearReliefColors();
65  void addReliefColorClass( const QgsRelief::ReliefColor &color );
66  QList< QgsRelief::ReliefColor > reliefColors() const { return mReliefColors; }
67  void setReliefColors( const QList< QgsRelief::ReliefColor > &c ) { mReliefColors = c; }
68 
72  QList< QgsRelief::ReliefColor > calculateOptimizedReliefClasses();
73 
75  bool exportFrequencyDistributionToCsv( const QString &file );
76 
77  private:
78 #ifdef SIP_RUN
79  QgsRelief( const QgsRelief &rh );
80 #endif
81 
82  QString mInputFile;
83  QString mOutputFile;
84  QString mOutputFormat;
85 
86  double mCellSizeX;
87  double mCellSizeY;
89  float mInputNodataValue;
91  float mOutputNodataValue;
92 
93  double mZFactor;
94 
95  QgsSlopeFilter *mSlopeFilter = nullptr;
96  QgsAspectFilter *mAspectFilter = nullptr;
97  QgsHillshadeFilter *mHillshadeFilter285 = nullptr;
98  QgsHillshadeFilter *mHillshadeFilter300 = nullptr;
99  QgsHillshadeFilter *mHillshadeFilter315 = nullptr;
100 
101  //relief colors and corresponding elevations
102  QList< ReliefColor > mReliefColors;
103 
104  bool processNineCellWindow( float *x1, float *x2, float *x3, float *x4, float *x5, float *x6, float *x7, float *x8, float *x9,
105  unsigned char *red, unsigned char *green, unsigned char *blue );
106 
108  GDALDatasetH openInputFile( int &nCellsX, int &nCellsY );
109 
113  GDALDriverH openOutputDriver();
114 
118  GDALDatasetH openOutputFile( GDALDatasetH inputDataset, GDALDriverH outputDriver );
119 
121  bool setElevationColor( double elevation, int *red, int *green, int *blue );
122 
124  void setDefaultReliefColors();
125 
129  int frequencyClassForElevation( double elevation, double minElevation, double elevationClassRange );
131  void optimiseClassBreaks( QList<int> &breaks, double *frequencies );
132 
139  bool calculateRegression( const QList< QPair < int, double > > &input, double &a, double &b );
140 
141 };
142 
143 #endif // QGSRELIEF_H
double zFactor() const
Definition: qgsrelief.h:61
void setZFactor(double factor)
Definition: qgsrelief.h:62
QList< QgsRelief::ReliefColor > reliefColors() const
Definition: qgsrelief.h:66
Base class for feedback objects to be used for cancelation of something running in a worker thread...
Definition: qgsfeedback.h:44
Calculates aspect values in a window of 3x3 cells based on first order derivatives in x- and y- direc...
void * GDALDatasetH
ReliefColor(const QColor &c, double min, double max)
Definition: qgsrelief.h:41
Calculates slope values in a window of 3x3 cells based on first order derivatives in x- and y- direct...
void setReliefColors(const QList< QgsRelief::ReliefColor > &c)
Definition: qgsrelief.h:67
Produces colored relief rasters from DEM.
Definition: qgsrelief.h:36