QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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"
24#include <QString>
25#include <QVector>
26#include "gdal.h"
27#include "qgis_analysis.h"
28#include "qgsogrutils.h"
29#include "qgsrastercalcnode.h"
30
31class QgsRasterLayer;
32class QgsFeedback;
33
40class ANALYSIS_EXPORT QgsRasterCalculatorEntry
41{
42
43 public:
44
55 static QVector<QgsRasterCalculatorEntry> rasterEntries();
56
60 QString ref;
61
65 QgsRasterLayer *raster = nullptr;
66
70 int bandNumber = 1;
71};
72
77class ANALYSIS_EXPORT QgsRasterCalculator
78{
79 public:
80
82 enum Result
83 {
84 Success = 0,
85 CreateOutputError = 1,
86 InputLayerError = 2,
87 Canceled = 3,
88 ParserError = 4,
89 MemoryError = 5,
90 BandError = 6,
91 CalculationError = 7,
92 };
93
94
107 QgsRasterCalculator( const QString &formulaString, const QString &outputFile, const QString &outputFormat,
108 const QgsRectangle &outputExtent, int nOutputColumns, int nOutputRows,
109 const QVector<QgsRasterCalculatorEntry> &rasterEntries,
110 const QgsCoordinateTransformContext &transformContext );
111
125 QgsRasterCalculator( const QString &formulaString, const QString &outputFile, const QString &outputFormat,
126 const QgsRectangle &outputExtent, const QgsCoordinateReferenceSystem &outputCrs,
127 int nOutputColumns, int nOutputRows,
128 const QVector<QgsRasterCalculatorEntry> &rasterEntries,
129 const QgsCoordinateTransformContext &transformContext );
130
131
143 Q_DECL_DEPRECATED QgsRasterCalculator( const QString &formulaString, const QString &outputFile, const QString &outputFormat,
144 const QgsRectangle &outputExtent, int nOutputColumns, int nOutputRows, const QVector<QgsRasterCalculatorEntry> &rasterEntries ) SIP_DEPRECATED;
145
159 Q_DECL_DEPRECATED QgsRasterCalculator( const QString &formulaString, const QString &outputFile, const QString &outputFormat,
160 const QgsRectangle &outputExtent, const QgsCoordinateReferenceSystem &outputCrs, int nOutputColumns, int nOutputRows, const QVector<QgsRasterCalculatorEntry> &rasterEntries ) SIP_DEPRECATED;
161
170 Result processCalculation( QgsFeedback *feedback = nullptr );
171
176 QString lastError() const;
177
178 private:
179 //default constructor forbidden. We need formula, output file, output format and output raster resolution obligatory
180 QgsRasterCalculator() = delete;
181
186 GDALDriverH openOutputDriver();
187
192 gdal::dataset_unique_ptr openOutputFile( GDALDriverH outputDriver );
193
198 void outputGeoTransform( double *transform ) const;
199
201 Result processCalculationGPU( std::unique_ptr< QgsRasterCalcNode > calcNode, QgsFeedback *feedback = nullptr );
202
203 QString mFormulaString;
204 QString mOutputFile;
205 QString mOutputFormat;
206
208 QgsRectangle mOutputRectangle;
210
212 int mNumOutputColumns = 0;
214 int mNumOutputRows = 0;
215
216 QString mLastError;
217
218 /***/
219 QVector<QgsRasterCalculatorEntry> mRasterEntries;
220
221 QgsCoordinateTransformContext mTransformContext;
222};
223
224#endif // QGSRASTERCALCULATOR_H
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:45
Represents an individual raster layer/band number entry within a raster calculation.
QString ref
Name of entry.
Performs raster layer calculations.
Result
Result of the calculation.
Represents a raster layer.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
std::unique_ptr< std::remove_pointer< GDALDatasetH >::type, GDALDatasetCloser > dataset_unique_ptr
Scoped GDAL dataset.
Definition: qgsogrutils.h:140
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
const QgsCoordinateReferenceSystem & outputCrs