QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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  };
91 
92 
105  QgsRasterCalculator( const QString &formulaString, const QString &outputFile, const QString &outputFormat,
106  const QgsRectangle &outputExtent, int nOutputColumns, int nOutputRows,
107  const QVector<QgsRasterCalculatorEntry> &rasterEntries,
108  const QgsCoordinateTransformContext &transformContext );
109 
123  QgsRasterCalculator( const QString &formulaString, const QString &outputFile, const QString &outputFormat,
124  const QgsRectangle &outputExtent, const QgsCoordinateReferenceSystem &outputCrs,
125  int nOutputColumns, int nOutputRows,
126  const QVector<QgsRasterCalculatorEntry> &rasterEntries,
127  const QgsCoordinateTransformContext &transformContext );
128 
129 
141  Q_DECL_DEPRECATED QgsRasterCalculator( const QString &formulaString, const QString &outputFile, const QString &outputFormat,
142  const QgsRectangle &outputExtent, int nOutputColumns, int nOutputRows, const QVector<QgsRasterCalculatorEntry> &rasterEntries ) SIP_DEPRECATED;
143 
157  Q_DECL_DEPRECATED QgsRasterCalculator( const QString &formulaString, const QString &outputFile, const QString &outputFormat,
158  const QgsRectangle &outputExtent, const QgsCoordinateReferenceSystem &outputCrs, int nOutputColumns, int nOutputRows, const QVector<QgsRasterCalculatorEntry> &rasterEntries ) SIP_DEPRECATED;
159 
168  Result processCalculation( QgsFeedback *feedback = nullptr );
169 
174  QString lastError() const;
175 
176  private:
177  //default constructor forbidden. We need formula, output file, output format and output raster resolution obligatory
178  QgsRasterCalculator() = delete;
179 
183  GDALDriverH openOutputDriver();
184 
188  gdal::dataset_unique_ptr openOutputFile( GDALDriverH outputDriver );
189 
193  void outputGeoTransform( double *transform ) const;
194 
196  Result processCalculationGPU( std::unique_ptr< QgsRasterCalcNode > calcNode, QgsFeedback *feedback = nullptr );
197 
198  QString mFormulaString;
199  QString mOutputFile;
200  QString mOutputFormat;
201 
203  QgsRectangle mOutputRectangle;
204  QgsCoordinateReferenceSystem mOutputCrs;
205 
207  int mNumOutputColumns = 0;
209  int mNumOutputRows = 0;
210 
211  QString mLastError;
212 
213  /***/
214  QVector<QgsRasterCalculatorEntry> mRasterEntries;
215 
216  QgsCoordinateTransformContext mTransformContext;
217 };
218 
219 #endif // QGSRASTERCALCULATOR_H
A rectangle specified with double values.
Definition: qgsrectangle.h:41
Performs raster layer calculations.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
QString ref
Name of entry.
Base class for feedback objects to be used for cancellation of something running in a worker thread...
Definition: qgsfeedback.h:44
Contains information about the context in which a coordinate transform is executed.
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
Represents an individual raster layer/band number entry within a raster calculation.
Result
Result of the calculation.
This class represents a coordinate reference system (CRS).
const QgsCoordinateReferenceSystem & outputCrs
std::unique_ptr< std::remove_pointer< GDALDatasetH >::type, GDALDatasetCloser > dataset_unique_ptr
Scoped GDAL dataset.
Definition: qgsogrutils.h:134