QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 
29 class QgsRasterLayer;
30 class QgsFeedback;
31 
38 class ANALYSIS_EXPORT QgsRasterCalculatorEntry
39 {
40 
41  public:
42 
46  QString ref;
47 
51  QgsRasterLayer *raster = nullptr;
52 
56  int bandNumber = 1;
57 };
58 
63 class ANALYSIS_EXPORT QgsRasterCalculator
64 {
65  public:
66 
68  enum Result
69  {
70  Success = 0,
71  CreateOutputError = 1,
72  InputLayerError = 2,
73  Canceled = 3,
74  ParserError = 4,
75  MemoryError = 5,
76  BandError = 6,
77  };
78 
89  QgsRasterCalculator( const QString &formulaString, const QString &outputFile, const QString &outputFormat,
90  const QgsRectangle &outputExtent, int nOutputColumns, int nOutputRows, const QVector<QgsRasterCalculatorEntry> &rasterEntries );
91 
104  QgsRasterCalculator( const QString &formulaString, const QString &outputFile, const QString &outputFormat,
105  const QgsRectangle &outputExtent, const QgsCoordinateReferenceSystem &outputCrs, int nOutputColumns, int nOutputRows, const QVector<QgsRasterCalculatorEntry> &rasterEntries );
106 
115  Result processCalculation( QgsFeedback *feedback = nullptr );
116 
121  QString lastError() const;
122 
123  private:
124  //default constructor forbidden. We need formula, output file, output format and output raster resolution obligatory
125  QgsRasterCalculator() = delete;
126 
130  GDALDriverH openOutputDriver();
131 
135  gdal::dataset_unique_ptr openOutputFile( GDALDriverH outputDriver );
136 
140  void outputGeoTransform( double *transform ) const;
141 
142  QString mFormulaString;
143  QString mOutputFile;
144  QString mOutputFormat;
145 
147  QgsRectangle mOutputRectangle;
148  QgsCoordinateReferenceSystem mOutputCrs;
149 
151  int mNumOutputColumns = 0;
153  int mNumOutputRows = 0;
154 
155  QString mLastError;
156 
157  /***/
158  QVector<QgsRasterCalculatorEntry> mRasterEntries;
159 };
160 
161 #endif // QGSRASTERCALCULATOR_H
A rectangle specified with double values.
Definition: qgsrectangle.h:40
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
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