QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsalgorithmcellstatistics.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsalgorithmcellstatistics.h
3  ---------------------
4  begin : May 2020
5  copyright : (C) 2020 by Clemens Raffler
6  email : clemens dot raffler at gmail dot com
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 QGSALGORITHMCELLSTATISTICS_H
19 #define QGSALGORITHMCELLSTATISTICS_H
20 
21 #define SIP_NO_FILE
22 
23 #include "qgis_sip.h"
24 #include "qgsapplication.h"
25 #include "qgsprocessingalgorithm.h"
26 #include "qgsrasterprojector.h"
27 #include "qgsrasteranalysisutils.h"
28 
30 
31 class QgsCellStatisticsAlgorithmBase : public QgsProcessingAlgorithm
32 {
33 
34  public:
35  QString group() const final;
36  QString groupId() const final;
37  void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) final;
38 
39 
40  protected:
41  virtual void addSpecificAlgorithmParams() = 0;
42  virtual bool prepareSpecificAlgorithmParameters( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) = 0;
43  bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) final;
44  QVariantMap processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) final;
45  virtual void processRasterStack( QgsProcessingFeedback *feedback ) = 0;
46 
47  std::vector< QgsRasterAnalysisUtils::RasterLogicInput > mInputs;
48  bool mIgnoreNoData;
49  Qgis::DataType mDataType;
50  double mNoDataValue = -9999;
51  int mLayerWidth;
52  int mLayerHeight;
53  QgsRectangle mExtent;
55  double mRasterUnitsPerPixelX;
56  double mRasterUnitsPerPixelY;
57  QgsRasterDataProvider *mOutputRasterDataProvider;
58 };
59 
60 class QgsCellStatisticsAlgorithm : public QgsCellStatisticsAlgorithmBase
61 {
62  public:
63  QgsCellStatisticsAlgorithm() = default;
64  QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmCellStatistics.svg" ) ); }
65  QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmCellStatistics.svg" ) ); }
66  QString name() const override;
67  QString displayName() const override;
68  QStringList tags() const override;
69  QString shortHelpString() const override;
70  QgsCellStatisticsAlgorithm *createInstance() const override SIP_FACTORY;
71 
72  protected:
73  void addSpecificAlgorithmParams() override;
74  bool prepareSpecificAlgorithmParameters( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
75  void processRasterStack( QgsProcessingFeedback *feedback ) override;
76 
77  private:
78  QgsRasterAnalysisUtils::CellValueStatisticMethods mMethod;
79 
80 };
81 
82 
83 class QgsCellStatisticsPercentileAlgorithm : public QgsCellStatisticsAlgorithmBase
84 {
85  public:
86  QgsCellStatisticsPercentileAlgorithm() = default;
87  QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmCellStatisticsPercentile.svg" ) ); }
88  QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmCellStatisticsPercentile.svg" ) ); }
89  QString name() const override;
90  QString displayName() const override;
91  QStringList tags() const override;
92  QString shortHelpString() const override;
93  QgsCellStatisticsPercentileAlgorithm *createInstance() const override SIP_FACTORY;
94 
95  protected:
96  void addSpecificAlgorithmParams() override;
97  bool prepareSpecificAlgorithmParameters( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
98  void processRasterStack( QgsProcessingFeedback *feedback ) override;
99 
100  private:
101  QgsRasterAnalysisUtils::CellValuePercentileMethods mMethod;
102  double mPercentile = 0.0;
103 };
104 
105 
106 class QgsCellStatisticsPercentRankFromValueAlgorithm : public QgsCellStatisticsAlgorithmBase
107 {
108  public:
109  QgsCellStatisticsPercentRankFromValueAlgorithm() = default;
110  QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmCellStatisticsPercentRank.svg" ) ); }
111  QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmCellStatisticsPercentRank.svg" ) ); }
112  QString name() const override;
113  QString displayName() const override;
114  QStringList tags() const override;
115  QString shortHelpString() const override;
116  QgsCellStatisticsPercentRankFromValueAlgorithm *createInstance() const override SIP_FACTORY;
117 
118  protected:
119  void addSpecificAlgorithmParams() override;
120  bool prepareSpecificAlgorithmParameters( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
121  void processRasterStack( QgsProcessingFeedback *feedback ) override;
122 
123  private:
124  QgsRasterAnalysisUtils::CellValuePercentRankMethods mMethod;
125  double mValue = 0.0;
126 
127 };
128 
129 
130 class QgsCellStatisticsPercentRankFromRasterAlgorithm : public QgsCellStatisticsAlgorithmBase
131 {
132  public:
133  QgsCellStatisticsPercentRankFromRasterAlgorithm() = default;
134  QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmCellStatisticsPercentRank.svg" ) ); }
135  QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmCellStatisticsPercentRank.svg" ) ); }
136  QString name() const override;
137  QString displayName() const override;
138  QStringList tags() const override;
139  QString shortHelpString() const override;
140  QgsCellStatisticsPercentRankFromRasterAlgorithm *createInstance() const override SIP_FACTORY;
141 
142  protected:
143  void addSpecificAlgorithmParams() override;
144  bool prepareSpecificAlgorithmParameters( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
145  void processRasterStack( QgsProcessingFeedback *feedback ) override;
146 
147  private:
148  QgsRasterAnalysisUtils::CellValuePercentRankMethods mMethod;
149  std::unique_ptr< QgsRasterInterface > mValueRasterInterface;
150  int mValueRasterBand;
151 
152 };
153 
154 
156 
157 #endif // QGSALGORITHMCELLSTATISTICS_H
158 
qgsrasterprojector.h
QgsProcessingFeedback
Base class for providing feedback from a processing algorithm.
Definition: qgsprocessingfeedback.h:37
Qgis::DataType
DataType
Raster data types.
Definition: qgis.h:128
QgsProcessingAlgorithm::groupId
virtual QString groupId() const
Returns the unique ID of the group this algorithm belongs to.
Definition: qgsprocessingalgorithm.h:234
qgsrasteranalysisutils.h
QgsProcessingAlgorithm::prepareAlgorithm
virtual bool prepareAlgorithm(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback) SIP_THROW(QgsProcessingException)
Prepares the algorithm to run using the specified parameters.
Definition: qgsprocessingalgorithm.cpp:451
QgsApplication::iconPath
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
Definition: qgsapplication.cpp:682
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
qgsapplication.h
geos::unique_ptr
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
QgsProcessingAlgorithm::processAlgorithm
virtual QVariantMap processAlgorithm(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback) SIP_THROW(QgsProcessingException)=0
Runs the algorithm using the specified parameters.
QgsProcessingContext
Contains information about the context in which a processing algorithm is executed.
Definition: qgsprocessingcontext.h:46
qgsprocessingalgorithm.h
qgis_sip.h
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsRasterInterface
Base class for processing filters like renderers, reprojector, resampler etc.
Definition: qgsrasterinterface.h:135
QgsProcessingAlgorithm
Abstract base class for processing algorithms.
Definition: qgsprocessingalgorithm.h:52
QgsProcessingAlgorithm::group
virtual QString group() const
Returns the name of the group this algorithm belongs to.
Definition: qgsprocessingalgorithm.h:225
QgsApplication::getThemeIcon
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Definition: qgsapplication.cpp:693
QgsRasterDataProvider
Base class for raster data providers.
Definition: qgsrasterdataprovider.h:88
QgsProcessingAlgorithm::initAlgorithm
virtual void initAlgorithm(const QVariantMap &configuration=QVariantMap())=0
Initializes the algorithm using the specified configuration.