QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 = 0.0;
88  double mCellSizeY = 0.0;
90  float mInputNodataValue = -1;
92  float mOutputNodataValue = -1;
93 
94  double mZFactor = 1;
95 
96  std::unique_ptr< QgsSlopeFilter > mSlopeFilter;
97  std::unique_ptr< QgsAspectFilter > mAspectFilter;
98  std::unique_ptr< QgsHillshadeFilter > mHillshadeFilter285;
99  std::unique_ptr< QgsHillshadeFilter > mHillshadeFilter300;
100  std::unique_ptr< QgsHillshadeFilter > mHillshadeFilter315;
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 cancellation of something running in a worker thread...
Definition: qgsfeedback.h:44
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
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
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
std::unique_ptr< std::remove_pointer< GDALDatasetH >::type, GDALDatasetCloser > dataset_unique_ptr
Scoped GDAL dataset.
Definition: qgsogrutils.h:134
Produces colored relief rasters from DEM.
Definition: qgsrelief.h:37