QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
185  GDALDriverH openOutputDriver();
186 
191  gdal::dataset_unique_ptr openOutputFile( GDALDriverH outputDriver );
192 
197  void outputGeoTransform( double *transform ) const;
198 
200  Result processCalculationGPU( std::unique_ptr< QgsRasterCalcNode > calcNode, QgsFeedback *feedback = nullptr );
201 
202  QString mFormulaString;
203  QString mOutputFile;
204  QString mOutputFormat;
205 
207  QgsRectangle mOutputRectangle;
208  QgsCoordinateReferenceSystem mOutputCrs;
209 
211  int mNumOutputColumns = 0;
213  int mNumOutputRows = 0;
214 
215  QString mLastError;
216 
217  /***/
218  QVector<QgsRasterCalculatorEntry> mRasterEntries;
219 
220  QgsCoordinateTransformContext mTransformContext;
221 };
222 
223 #endif // QGSRASTERCALCULATOR_H
QgsRasterCalculator::Result
Result
Result of the calculation.
Definition: qgsrastercalculator.h:82
outputCrs
const QgsCoordinateReferenceSystem & outputCrs
Definition: qgswfsgetfeature.cpp:61
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:58
QgsRasterCalculatorEntry::ref
QString ref
Name of entry.
Definition: qgsrastercalculator.h:59
qgsrectangle.h
qgsogrutils.h
QgsRasterCalculatorEntry
Represents an individual raster layer/band number entry within a raster calculation.
Definition: qgsrastercalculator.h:40
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
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
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:44
QgsRasterCalculator
Performs raster layer calculations.
Definition: qgsrastercalculator.h:77
QgsRasterLayer
Represents a raster layer.
Definition: qgsrasterlayer.h:71
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:206
qgsrastercalcnode.h
qgscoordinatereferencesystem.h