QGIS API Documentation  3.0.2-Girona (307d082)
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 "qgsogrutils.h"
27 #include "qgis_analysis.h"
28 
29 class QgsAspectFilter;
30 class QgsSlopeFilter;
31 class QgsHillshadeFilter;
32 class QgsFeedback;
33 
37 class ANALYSIS_EXPORT QgsRelief
38 {
39  public:
40  struct ReliefColor
41  {
42  ReliefColor( const QColor &c, double min, double max ): color( c ), minElevation( min ), maxElevation( max ) { }
43  QColor color;
44  double minElevation;
45  double maxElevation;
46  };
47 
48  QgsRelief( const QString &inputFile, const QString &outputFile, const QString &outputFormat );
49  ~QgsRelief();
50 
52  QgsRelief( const QgsRelief &rh ) = delete;
54  QgsRelief &operator=( const QgsRelief &rh ) = delete;
55 
60  int processRaster( QgsFeedback *feedback = nullptr );
61 
62  double zFactor() const { return mZFactor; }
63  void setZFactor( double factor ) { mZFactor = factor; }
64 
65  void clearReliefColors();
66  void addReliefColorClass( const QgsRelief::ReliefColor &color );
67  QList< QgsRelief::ReliefColor > reliefColors() const { return mReliefColors; }
68  void setReliefColors( const QList< QgsRelief::ReliefColor > &c ) { mReliefColors = c; }
69 
73  QList< QgsRelief::ReliefColor > calculateOptimizedReliefClasses();
74 
76  bool exportFrequencyDistributionToCsv( const QString &file );
77 
78  private:
79 #ifdef SIP_RUN
80  QgsRelief( const QgsRelief &rh );
81 #endif
82 
83  QString mInputFile;
84  QString mOutputFile;
85  QString mOutputFormat;
86 
87  double mCellSizeX;
88  double mCellSizeY;
90  float mInputNodataValue;
92  float mOutputNodataValue;
93 
94  double mZFactor;
95 
96  QgsSlopeFilter *mSlopeFilter = nullptr;
97  QgsAspectFilter *mAspectFilter = nullptr;
98  QgsHillshadeFilter *mHillshadeFilter285 = nullptr;
99  QgsHillshadeFilter *mHillshadeFilter300 = nullptr;
100  QgsHillshadeFilter *mHillshadeFilter315 = nullptr;
101 
102  //relief colors and corresponding elevations
103  QList< ReliefColor > mReliefColors;
104 
105  bool processNineCellWindow( float *x1, float *x2, float *x3, float *x4, float *x5, float *x6, float *x7, float *x8, float *x9,
106  unsigned char *red, unsigned char *green, unsigned char *blue );
107 
109  gdal::dataset_unique_ptr openInputFile( int &nCellsX, int &nCellsY );
110 
114  GDALDriverH openOutputDriver();
115 
119  gdal::dataset_unique_ptr openOutputFile( GDALDatasetH inputDataset, GDALDriverH outputDriver );
120 
122  bool setElevationColor( double elevation, int *red, int *green, int *blue );
123 
125  void setDefaultReliefColors();
126 
130  int frequencyClassForElevation( double elevation, double minElevation, double elevationClassRange );
132  void optimiseClassBreaks( QList<int> &breaks, double *frequencies );
133 
140  bool calculateRegression( const QList< QPair < int, double > > &input, double &a, double &b );
141 
142 };
143 
144 #endif // QGSRELIEF_H
double zFactor() const
Definition: qgsrelief.h:62
void setZFactor(double factor)
Definition: qgsrelief.h:63
QList< QgsRelief::ReliefColor > reliefColors() const
Definition: qgsrelief.h:67
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:42
std::unique_ptr< void, GDALDatasetCloser > dataset_unique_ptr
Scoped GDAL dataset.
Definition: qgsogrutils.h:134
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:68
Produces colored relief rasters from DEM.
Definition: qgsrelief.h:37