QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgsalgorithmreclassifybylayer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsalgorithmreclassifybylayer.h
3  ---------------------
4  begin : June, 2018
5  copyright : (C) 2018 by Nyall Dawson
6  email : nyall dot dawson 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 QGSALGORITHMRECLASSIFYBYLAYER_H
19 #define QGSALGORITHMRECLASSIFYBYLAYER_H
20 
21 #define SIP_NO_FILE
22 
23 #include "qgis_sip.h"
24 #include "qgsprocessingalgorithm.h"
25 #include "qgsreclassifyutils.h"
26 
28 
32 class QgsReclassifyAlgorithmBase : public QgsProcessingAlgorithm
33 {
34  public:
35 
36  QString group() const final;
37  QString groupId() const final;
38  void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) final;
39 
40  protected:
41 
46  virtual void addAlgorithmParams() = 0;
47 
48  bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) final;
49 
53  virtual bool _prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) = 0;
54 
58  virtual QVector< QgsReclassifyUtils::RasterClass > createClasses(
59  QgsReclassifyUtils::RasterClass::BoundsType boundsType,
60  const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) = 0;
61 
62  QVariantMap processAlgorithm( const QVariantMap &parameters,
63  QgsProcessingContext &context, QgsProcessingFeedback *feedback ) final;
64 
65  std::unique_ptr< QgsRasterInterface > mInterface;
66 
67  Qgis::DataType mDataType = Qgis::Float32;
68  double mNoDataValue = -9999;
69  int mBand = 1;
70  QgsRectangle mExtent;
72  double mRasterUnitsPerPixelX = 0;
73  double mRasterUnitsPerPixelY = 0;
74  int mNbCellsXProvider = 0;
75  int mNbCellsYProvider = 0;
76  QgsReclassifyUtils::RasterClass::BoundsType mBoundsType = QgsReclassifyUtils::RasterClass::IncludeMax;
77  bool mUseNoDataForMissingValues = false;
78 };
79 
83 class QgsReclassifyByLayerAlgorithm : public QgsReclassifyAlgorithmBase
84 {
85 
86  public:
87 
88  QgsReclassifyByLayerAlgorithm() = default;
89  QString name() const override;
90  QString displayName() const override;
91  QStringList tags() const override;
92  QString shortHelpString() const override;
93  QgsReclassifyByLayerAlgorithm *createInstance() const override SIP_FACTORY;
94 
95  protected:
96  void addAlgorithmParams() override;
97  bool _prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
98  QVector< QgsReclassifyUtils::RasterClass > createClasses(
99  QgsReclassifyUtils::RasterClass::BoundsType boundsType,
100  const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
101 
102  private:
103  int mMinFieldIdx = -1;
104  int mMaxFieldIdx = -1;
105  int mValueFieldIdx = -1;
106  QgsFeatureIterator mTableIterator;
107 
108 };
109 
113 class QgsReclassifyByTableAlgorithm : public QgsReclassifyAlgorithmBase
114 {
115 
116  public:
117 
118  QgsReclassifyByTableAlgorithm() = default;
119  QString name() const override;
120  QString displayName() const override;
121  QStringList tags() const override;
122  QString shortHelpString() const override;
123  QgsReclassifyByTableAlgorithm *createInstance() const override SIP_FACTORY;
124 
125  protected:
126 
127  void addAlgorithmParams() override;
128  bool _prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
129  QVector< QgsReclassifyUtils::RasterClass > createClasses( QgsReclassifyUtils::RasterClass::BoundsType boundsType,
130  const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
131 
132 };
133 
135 
136 #endif // QGSALGORITHMRECLASSIFYBYLAYER_H
137 
138 
Qgis::Float32
@ Float32
Thirty two bit floating point (float)
Definition: qgis.h:122
Qgis::DataType
DataType
Raster data types.
Definition: qgis.h:114
QgsProcessingFeedback
Definition: qgsprocessingfeedback.h:37
qgsreclassifyutils.h
QgsProcessingAlgorithm::groupId
virtual QString groupId() const
Returns the unique ID of the group this algorithm belongs to.
Definition: qgsprocessingalgorithm.h:231
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:359
QgsRectangle
Definition: qgsrectangle.h:41
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsProcessingAlgorithm::processAlgorithm
virtual QVariantMap processAlgorithm(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback) SIP_THROW(QgsProcessingException)=0
Runs the algorithm using the specified parameters.
QgsProcessingContext
Definition: qgsprocessingcontext.h:43
qgsprocessingalgorithm.h
qgis_sip.h
QgsCoordinateReferenceSystem
Definition: qgscoordinatereferencesystem.h:206
QgsProcessingAlgorithm
Definition: qgsprocessingalgorithm.h:51
QgsProcessingAlgorithm::group
virtual QString group() const
Returns the name of the group this algorithm belongs to.
Definition: qgsprocessingalgorithm.h:222
QgsFeatureIterator
Definition: qgsfeatureiterator.h:263
QgsProcessingAlgorithm::initAlgorithm
virtual void initAlgorithm(const QVariantMap &configuration=QVariantMap())=0
Initializes the algorithm using the specified configuration.