QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
27 class QgsAspectFilter;
28 class QgsSlopeFilter;
29 class QgsHillshadeFilter;
30 class QProgressDialog;
31 
33 class ANALYSIS_EXPORT QgsRelief
34 {
35  public:
36  struct ReliefColor
37  {
38  ReliefColor( const QColor& c, double min, double max ): color( c ), minElevation( min ), maxElevation( max ) { }
39  QColor color;
40  double minElevation;
41  double maxElevation;
42  };
43 
44  QgsRelief( const QString& inputFile, const QString& outputFile, const QString& outputFormat );
45  ~QgsRelief();
46 
50  int processRaster( QProgressDialog* p );
51 
52  double zFactor() const { return mZFactor; }
53  void setZFactor( double factor ) { mZFactor = factor; }
54 
55  void clearReliefColors();
56  void addReliefColorClass( const ReliefColor& color );
57  const QList< ReliefColor >& reliefColors() const { return mReliefColors; }
58  void setReliefColors( const QList< ReliefColor >& c ) { mReliefColors = c; }
59 
62  QList< ReliefColor > calculateOptimizedReliefClasses();
63 
65  bool exportFrequencyDistributionToCsv( const QString& file );
66 
67  private:
68 
69  QString mInputFile;
70  QString mOutputFile;
71  QString mOutputFormat;
72 
73  double mCellSizeX;
74  double mCellSizeY;
76  float mInputNodataValue;
78  float mOutputNodataValue;
79 
80  double mZFactor;
81 
82  QgsSlopeFilter* mSlopeFilter;
83  QgsAspectFilter* mAspectFilter;
84  QgsHillshadeFilter* mHillshadeFilter285;
85  QgsHillshadeFilter* mHillshadeFilter300;
86  QgsHillshadeFilter* mHillshadeFilter315;
87 
88  //relief colors and corresponding elevations
89  QList< ReliefColor > mReliefColors;
90 
91  bool processNineCellWindow( float* x1, float* x2, float* x3, float* x4, float* x5, float* x6, float* x7, float* x8, float* x9,
92  unsigned char* red, unsigned char* green, unsigned char* blue );
93 
95  GDALDatasetH openInputFile( int& nCellsX, int& nCellsY );
98  GDALDriverH openOutputDriver();
101  GDALDatasetH openOutputFile( GDALDatasetH inputDataset, GDALDriverH outputDriver );
102 
104  bool setElevationColor( double elevation, int* red, int* green, int* blue );
105 
107  void setDefaultReliefColors();
110  int frequencyClassForElevation( double elevation, double minElevation, double elevationClassRange );
112  void optimiseClassBreaks( QList<int>& breaks, double* frequencies );
118  bool calculateRegression( const QList< QPair < int, double > >& input, double& a, double& b );
119 };
120 
121 #endif // QGSRELIEF_H