QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgsrastercalculator.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrastercalculator.h - description
3  ---------------------
4  begin : September 28th, 2010
5  copyright : (C) 2010 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 QGSRASTERCALCULATOR_H
19 #define QGSRASTERCALCULATOR_H
20 
21 #include "qgsrectangle.h"
23 #include <QString>
24 #include <QVector>
25 #include "gdal.h"
26 #include "qgis_analysis.h"
27 #include "qgsogrutils.h"
28 #include "qgsrastercalcnode.h"
29 
30 class QgsRasterLayer;
31 class QgsFeedback;
32 
39 class ANALYSIS_EXPORT QgsRasterCalculatorEntry
40 {
41 
42  public:
43 
54  static QVector<QgsRasterCalculatorEntry> rasterEntries();
55 
59  QString ref;
60 
64  QgsRasterLayer *raster = nullptr;
65 
69  int bandNumber = 1;
70 };
71 
76 class ANALYSIS_EXPORT QgsRasterCalculator
77 {
78  public:
79 
81  enum Result
82  {
83  Success = 0,
84  CreateOutputError = 1,
85  InputLayerError = 2,
86  Canceled = 3,
87  ParserError = 4,
88  MemoryError = 5,
89  BandError = 6,
90  CalculationError = 7,
91  };
92 
93 
106  QgsRasterCalculator( const QString &formulaString, const QString &outputFile, const QString &outputFormat,
107  const QgsRectangle &outputExtent, int nOutputColumns, int nOutputRows,
108  const QVector<QgsRasterCalculatorEntry> &rasterEntries,
109  const QgsCoordinateTransformContext &transformContext );
110 
124  QgsRasterCalculator( const QString &formulaString, const QString &outputFile, const QString &outputFormat,
125  const QgsRectangle &outputExtent, const QgsCoordinateReferenceSystem &outputCrs,
126  int nOutputColumns, int nOutputRows,
127  const QVector<QgsRasterCalculatorEntry> &rasterEntries,
128  const QgsCoordinateTransformContext &transformContext );
129 
130 
142  Q_DECL_DEPRECATED QgsRasterCalculator( const QString &formulaString, const QString &outputFile, const QString &outputFormat,
143  const QgsRectangle &outputExtent, int nOutputColumns, int nOutputRows, const QVector<QgsRasterCalculatorEntry> &rasterEntries ) SIP_DEPRECATED;
144 
158  Q_DECL_DEPRECATED QgsRasterCalculator( const QString &formulaString, const QString &outputFile, const QString &outputFormat,
159  const QgsRectangle &outputExtent, const QgsCoordinateReferenceSystem &outputCrs, int nOutputColumns, int nOutputRows, const QVector<QgsRasterCalculatorEntry> &rasterEntries ) SIP_DEPRECATED;
160 
169  Result processCalculation( QgsFeedback *feedback = nullptr );
170 
175  QString lastError() const;
176 
177  private:
178  //default constructor forbidden. We need formula, output file, output format and output raster resolution obligatory
179  QgsRasterCalculator() = delete;
180 
184  GDALDriverH openOutputDriver();
185 
189  gdal::dataset_unique_ptr openOutputFile( GDALDriverH outputDriver );
190 
194  void outputGeoTransform( double *transform ) const;
195 
197  Result processCalculationGPU( std::unique_ptr< QgsRasterCalcNode > calcNode, QgsFeedback *feedback = nullptr );
198 
199  QString mFormulaString;
200  QString mOutputFile;
201  QString mOutputFormat;
202 
204  QgsRectangle mOutputRectangle;
205  QgsCoordinateReferenceSystem mOutputCrs;
206 
208  int mNumOutputColumns = 0;
210  int mNumOutputRows = 0;
211 
212  QString mLastError;
213 
214  /***/
215  QVector<QgsRasterCalculatorEntry> mRasterEntries;
216 
217  QgsCoordinateTransformContext mTransformContext;
218 };
219 
220 #endif // QGSRASTERCALCULATOR_H
QgsRasterCalculator::Result
Result
Result of the calculation.
Definition: qgsrastercalculator.h:81
outputCrs
const QgsCoordinateReferenceSystem & outputCrs
Definition: qgswfsgetfeature.cpp:115
QgsCoordinateTransformContext
Definition: qgscoordinatetransformcontext.h:57
QgsRasterCalculatorEntry::ref
QString ref
Name of entry.
Definition: qgsrastercalculator.h:59
qgsrectangle.h
qgsogrutils.h
QgsRasterCalculatorEntry
Definition: qgsrastercalculator.h:39
QgsRectangle
Definition: qgsrectangle.h:41
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
gdal::dataset_unique_ptr
std::unique_ptr< std::remove_pointer< GDALDatasetH >::type, GDALDatasetCloser > dataset_unique_ptr
Scoped GDAL dataset.
Definition: qgsogrutils.h:134
QgsFeedback
Definition: qgsfeedback.h:43
QgsRasterCalculator
Definition: qgsrastercalculator.h:76
QgsRasterLayer
Definition: qgsrasterlayer.h:72
QgsCoordinateReferenceSystem
Definition: qgscoordinatereferencesystem.h:206
qgsrastercalcnode.h
qgscoordinatereferencesystem.h