QGIS API Documentation  3.37.0-Master (a5b4d9743e8)
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 
38 class ANALYSIS_EXPORT QgsRelief
39 {
40  public:
41  struct ReliefColor
42  {
43  ReliefColor( const QColor &c, double min, double max ): color( c ), minElevation( min ), maxElevation( max ) { }
44  QColor color;
45  double minElevation;
46  double maxElevation;
47  };
48 
49  QgsRelief( const QString &inputFile, const QString &outputFile, const QString &outputFormat );
51 
53  QgsRelief( const QgsRelief &rh ) = delete;
55  QgsRelief &operator=( const QgsRelief &rh ) = delete;
56 
62  int processRaster( QgsFeedback *feedback = nullptr );
63 
64  double zFactor() const { return mZFactor; }
65  void setZFactor( double factor ) { mZFactor = factor; }
66 
67  void clearReliefColors();
68  void addReliefColorClass( const QgsRelief::ReliefColor &color );
69  QList< QgsRelief::ReliefColor > reliefColors() const { return mReliefColors; }
70  void setReliefColors( const QList< QgsRelief::ReliefColor > &c ) { mReliefColors = c; }
71 
76  QList< QgsRelief::ReliefColor > calculateOptimizedReliefClasses();
77 
79  bool exportFrequencyDistributionToCsv( const QString &file );
80 
81  private:
82 #ifdef SIP_RUN
83  QgsRelief( const QgsRelief &rh );
84 #endif
85 
86  QString mInputFile;
87  QString mOutputFile;
88  QString mOutputFormat;
89 
90  double mCellSizeX = 0.0;
91  double mCellSizeY = 0.0;
93  float mInputNodataValue = -1;
95  float mOutputNodataValue = -1;
96 
97  double mZFactor = 1;
98 
99  std::unique_ptr< QgsSlopeFilter > mSlopeFilter;
100  std::unique_ptr< QgsAspectFilter > mAspectFilter;
101  std::unique_ptr< QgsHillshadeFilter > mHillshadeFilter285;
102  std::unique_ptr< QgsHillshadeFilter > mHillshadeFilter300;
103  std::unique_ptr< QgsHillshadeFilter > mHillshadeFilter315;
104 
105  //relief colors and corresponding elevations
106  QList< ReliefColor > mReliefColors;
107 
108  bool processNineCellWindow( float *x1, float *x2, float *x3, float *x4, float *x5, float *x6, float *x7, float *x8, float *x9,
109  unsigned char *red, unsigned char *green, unsigned char *blue );
110 
112  gdal::dataset_unique_ptr openInputFile( int &nCellsX, int &nCellsY );
113 
118  GDALDriverH openOutputDriver();
119 
124  gdal::dataset_unique_ptr openOutputFile( GDALDatasetH inputDataset, GDALDriverH outputDriver );
125 
127  bool setElevationColor( double elevation, int *red, int *green, int *blue );
128 
130  void setDefaultReliefColors();
131 
136  int frequencyClassForElevation( double elevation, double minElevation, double elevationClassRange );
138  void optimiseClassBreaks( QList<int> &breaks, double *frequencies );
139 
146  bool calculateRegression( const QList< QPair < int, double > > &input, double &a, double &b );
147 
148 };
149 
150 #endif // QGSRELIEF_H
Calculates aspect values in a window of 3x3 cells based on first order derivatives in x- and y- direc...
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:44
A hillshade filter.
Produces colored relief rasters from DEM.
Definition: qgsrelief.h:39
void setZFactor(double factor)
Definition: qgsrelief.h:65
QList< QgsRelief::ReliefColor > reliefColors() const
Definition: qgsrelief.h:69
double zFactor() const
Definition: qgsrelief.h:64
void setReliefColors(const QList< QgsRelief::ReliefColor > &c)
Definition: qgsrelief.h:70
QgsRelief(const QgsRelief &rh)=delete
QgsRelief cannot be copied.
QgsRelief & operator=(const QgsRelief &rh)=delete
QgsRelief cannot be copied.
Calculates slope values in a window of 3x3 cells based on first order derivatives in x- and y- direct...
std::unique_ptr< std::remove_pointer< GDALDatasetH >::type, GDALDatasetCloser > dataset_unique_ptr
Scoped GDAL dataset.
Definition: qgsogrutils.h:157
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
void * GDALDatasetH
ReliefColor(const QColor &c, double min, double max)
Definition: qgsrelief.h:43