QGIS API Documentation 4.3.0-Master (2b7e6c9893e)
Loading...
Searching...
No Matches
qgsalgorithmupslopearea.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmupslopearea.h
3 ---------------------
4 begin : September 2026
5 copyright : (C) 2026 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 QGSALGORITHMUPSLOPEAREA_H
19#define QGSALGORITHMUPSLOPEAREA_H
20
21
22#include "qgis_sip.h"
24
25#define SIP_NO_FILE
26
28
35class QgsUpslopeAreaAlgorithmBase : public QgsProcessingAlgorithm
36{
37 public:
38 QgsUpslopeAreaAlgorithmBase() = default;
39
40 QString group() const override;
41 QString groupId() const override;
42 QStringList tags() const override;
43 QList<QgsAcademicReference> academicReferences() const override;
44 QList<QgsProcessingAlgorithm::ExternalLink> externalLinks() const override;
45
46 protected:
47 enum class Method : int
48 {
49 D8 = 0,
50 DInf = 1,
51 MFD = 2,
52 MDInf = 3,
53 MMDGFD = 4
54 };
55
56 void addCommonParameters();
57 bool prepareBase( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback );
58
59 // Core flow accumulation engine
60 bool calculateUpslopeArea( const std::vector<QgsPointXY> &targetPoints, QgsProcessingContext &context, QgsProcessingFeedback *feedback );
61
62 static double neighborLength( int dir, double cellSizeX, double cellSizeY );
63 static int neighborTo( int dir, int col, int &outCol, int row, int &outRow, int cols, int rows );
64
65 void computeCellValue( const QgsRasterBlock *demBlock, int col, int row, int cols, int rows, double cellSizeX, double cellSizeY, Method method, double converge, bool contour );
66 void computeD8( const QgsRasterBlock *demBlock, int col, int row, int cols, int rows, double cellSizeX, double cellSizeY );
67 void computeDInf( const QgsRasterBlock *demBlock, int col, int row, int cols, int rows, double cellSizeX, double cellSizeY );
68 void computeMFD( const QgsRasterBlock *demBlock, int col, int row, int cols, int rows, double cellSizeX, double cellSizeY, double converge, bool contour );
69 void computeMMDGFD( const QgsRasterBlock *demBlock, int col, int row, int cols, int rows, double cellSizeX, double cellSizeY, bool contour );
70 void computeMDInf( const QgsRasterBlock *demBlock, int col, int row, int cols, int rows, double cellSizeX, double cellSizeY, double converge );
71
72 std::unique_ptr<QgsRasterInterface> mDemProvider;
74 std::unique_ptr<QgsRasterInterface> mRouteProvider;
75
76 int mCols = 0;
77 int mRows = 0;
78 double mCellSizeX = 0.0;
79 double mCellSizeY = 0.0;
80 double mDemNoData = -9999.0;
81 double mRouteNoData = -9999.0;
82 QgsRectangle mExtent;
83
84 std::vector<double> mRouteData;
85 std::vector<double> mFlowData;
86
87 Method mMethod = Method::MFD;
88 double mConvergence = 1.1;
89 bool mMfdContour = false;
90 QString mOutputPath;
91 QString mOutputFormat;
92 QString mCreationOptions;
93 double mOutputNoData = -9999;
94};
95
100class QgsUpslopeAreaPointAlgorithm : public QgsUpslopeAreaAlgorithmBase
101{
102 public:
103 QgsUpslopeAreaPointAlgorithm();
104
105 QString name() const override;
106 QString displayName() const override;
107 QString shortDescription() const override;
108 QString shortHelpString() const override;
109 QgsProcessingAlgorithm *createInstance() const override;
110
111 void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
112
113 protected:
114 bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
115 QVariantMap processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
116};
117
122class QgsUpslopeAreaLayerAlgorithm : public QgsUpslopeAreaAlgorithmBase
123{
124 public:
125 QgsUpslopeAreaLayerAlgorithm();
126
127 QString name() const override;
128 QString displayName() const override;
129 QString shortDescription() const override;
130 QString shortHelpString() const override;
131 QgsProcessingAlgorithm *createInstance() const override;
132
133 void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
134
135 protected:
136 bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
137 QVariantMap processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
138};
139
141
142#endif // QGSALGORITHMUPSLOPEAREA_H
Represents a coordinate reference system (CRS).
Abstract base class for processing algorithms.
virtual QString group() const
Returns the name of the group this algorithm belongs to.
virtual QString groupId() const
Returns the unique ID of the group this algorithm belongs to.
virtual QStringList tags() const
Returns a list of tags which relate to the algorithm, and are used to assist users in searching for s...
virtual QList< QgsProcessingAlgorithm::ExternalLink > externalLinks() const
Returns a list of external links describing the algorithm's behavior or source.
virtual QList< QgsAcademicReference > academicReferences() const
Returns the list of academic references describing the logic and processes used by the algorithm.
Contains information about the context in which a processing algorithm is executed.
Base class for providing feedback from a processing algorithm.
Raster data container.
A rectangle specified with double values.