26using namespace Qt::StringLiterals;
29QString QgsD8AnalysisAlgorithmBase::group()
const
31 return QObject::tr(
"Raster terrain analysis" );
34QString QgsD8AnalysisAlgorithmBase::groupId()
const
36 return u
"rasterterrainanalysis"_s;
39QList<QgsAcademicReference> QgsD8AnalysisAlgorithmBase::academicReferences()
const
42 QgsAcademicReference::createJournalArticle( { u
"Strahler, A. N."_s }, 1957, u
"Quantitative analysis of watershed geomorphology"_s, u
"Eos, Transactions American Geophysical Union"_s, u
"38"_s, u
"6"_s, u
"913-920"_s ),
44 createJournalArticle( { u
"O'Callaghan, J. F."_s, u
"Mark, D. M."_s }, 1984, u
"The extraction of drainage networks from digital elevation data"_s, u
"Computer Vision, Graphics and Image Processing"_s, u
"28"_s, QString(), u
"323-344"_s )
48QList<QgsProcessingAlgorithm::ExternalLink> QgsD8AnalysisAlgorithmBase::externalLinks()
const
51 QgsProcessingAlgorithm::ExternalLink { QObject::tr(
"SAGA tool source code" ), u
"https://sourceforge.net/p/saga-gis/code/ci/33d1062b7120c696c9dd258378c48d86dc33560c/tree/saga-gis/src/tools/terrain_analysis/ta_channels/D8_Flow_Analysis.cpp"_s }
55void QgsD8AnalysisAlgorithmBase::computeStrahlerOrder(
56 const QgsRasterBlock *demBlock,
const std::vector<int8_t> &d8Directions,
int width,
int height,
int threshold, int16_t *outOrder,
QgsProcessingFeedback *feedback,
int outputNoData
59 const std::size_t totalCells =
static_cast<std::size_t
>( width ) * height;
60 std::fill_n( outOrder, totalCells,
static_cast<int16_t
>( 0 ) );
72 std::vector<StackFrame> stack;
73 stack.reserve( 1024 );
75 for (
int row = 0; row < height; ++row )
80 feedback->
setProgress( 100.0 *
static_cast<double>( row ) / height );
83 for (
int column = 0; column < width; ++column )
85 const qgssize startIdx = rowOffset + column;
86 if ( demBlock->
isNoData( row, column ) || outOrder[startIdx] >= 1 )
92 stack.push_back( { .column = column, .row = row, .dir = 0, .maxOrderCount = 0, .maxOrder = 1 } );
94 while ( !stack.empty() )
96 StackFrame ¤t = stack.back();
97 const qgssize currentIdx =
static_cast<qgssize>( current.row ) * width + current.column;
99 bool pushedChild =
false;
100 for ( ; current.dir < 8; )
102 const int oppositeDir = ( current.dir + 4 ) % 8;
103 int neighborColumn = 0;
105 if ( QgsRasterAnalysisUtils::neighborCellCoordinates( oppositeDir, current.row, current.column, neighborRow, neighborColumn, height, width ) )
107 const qgssize neighborIdx =
static_cast<qgssize>( neighborRow ) * width + neighborColumn;
108 if ( d8Directions[neighborIdx] == current.dir )
110 const int16_t neighborOrder = outOrder[neighborIdx];
111 if ( neighborOrder < 1 )
114 stack.push_back( { neighborColumn, neighborRow, 0, 0, 1 } );
120 if ( current.maxOrder < neighborOrder )
122 current.maxOrder = neighborOrder;
123 current.maxOrderCount = 1;
125 else if ( current.maxOrder == neighborOrder )
127 current.maxOrderCount++;
137 int finalOrder = current.maxOrder;
138 if ( current.maxOrderCount > 1 )
142 outOrder[currentIdx] =
static_cast<int16_t
>( finalOrder );
151 const int shift = 1 - threshold;
152 for ( std::size_t i = 0; i < totalCells; ++i )
154 if ( outOrder[i] >= threshold )
156 outOrder[i] +=
static_cast<int16_t
>( shift );
160 outOrder[i] = outputNoData;
166 for ( std::size_t i = 0; i < totalCells; ++i )
168 if ( outOrder[i] < 1 )
170 outOrder[i] = outputNoData;
Encapsulates an academic reference and formats it according to style guidelines.
static QgsAcademicReference createJournalArticle(const QStringList &authors, int year, const QString &title, const QString &journal, const QString &volume=QString(), const QString &issue=QString(), const QString &pages=QString())
Creates a journal article reference.
bool isCanceled() const
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
Base class for providing feedback from a processing algorithm.
bool isNoData(int row, int column) const
Checks if value at position is no data.
unsigned long long qgssize
Qgssize is used instead of size_t, because size_t is stdlib type, unknown by SIP, and it would be har...
Encapsulates details of an external link describing an algorithm's behavior or source.