Skip to content

Commit 9c55e45

Browse files
committed
Remove debug code and improve comments
1 parent 8b50c3e commit 9c55e45

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/analysis/raster/qgsrastercalculator.cpp

+8-13
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,12 @@ QgsRasterCalculator::Result QgsRasterCalculator::processCalculation( QgsFeedback
106106
float outputNodataValue = -FLT_MAX;
107107
GDALSetRasterNoDataValue( outputRasterBand, outputNodataValue );
108108

109-
110-
// If we need to read the raster as a whole
109+
// Check if we need to read the raster as a whole (which is memory inefficient
110+
// and not interruptable by the user) by checking if any raster matrix nodes are
111+
// in the expression
111112
bool requiresMatrix = ! calcNode->findNodes( QgsRasterCalcNode::Type::tMatrix ).isEmpty();
112113

113-
114+
// Take the fast route (process one line at a time) if we can
114115
if ( ! requiresMatrix )
115116
{
116117
// Map of raster names -> blocks
@@ -151,12 +152,12 @@ QgsRasterCalculator::Result QgsRasterCalculator::processCalculation( QgsFeedback
151152
break;
152153
}
153154

154-
// Read one row
155+
// Calculates the rect for a single row read
155156
QgsRectangle rect( mOutputRectangle );
156157
rect.setYMaximum( rect.yMaximum() - rowHeight * row );
157158
rect.setYMinimum( rect.yMaximum() - rowHeight );
158159

159-
// Read blocks
160+
// Read rows into input blocks
160161
for ( auto &layerRef : inputBlocks )
161162
{
162163
QgsRasterCalculatorEntry ref = uniqueRasterEntries[layerRef.first];
@@ -181,17 +182,14 @@ QgsRasterCalculator::Result QgsRasterCalculator::processCalculation( QgsFeedback
181182
for ( const auto &layerRef : inputBlocks )
182183
{
183184
_rasterData.insert( layerRef.first, inputBlocks[layerRef.first].get() );
184-
//for ( int i = 0; i < mNumOutputColumns; i++ )
185-
// qDebug() << "Input: " << row << i << " = " << inputBlocks[layerRef.first]->value(0, i);
186185
}
187186

188187
if ( calcNode->calculate( _rasterData, resultMatrix, 0 ) )
189188
{
190-
//write scanline to the dataset
189+
// write scanline to the dataset
191190
for ( size_t i = 0; i < static_cast<size_t>( mNumOutputColumns ); i++ )
192191
{
193192
castedResult[i] = static_cast<float>( resultMatrix.data()[i] );
194-
// qDebug() << "Calculated: " << row << i << " = " << castedResult[i];
195193
}
196194
if ( GDALRasterIO( outputRasterBand, GF_Write, 0, row, mNumOutputColumns, 1, castedResult.data(), mNumOutputColumns, 1, GDT_Float32, 0, 0 ) != CE_None )
197195
{
@@ -204,10 +202,8 @@ QgsRasterCalculator::Result QgsRasterCalculator::processCalculation( QgsFeedback
204202
{
205203
feedback->setProgress( 100.0 );
206204
}
207-
208-
209205
}
210-
else
206+
else // Original code (memory inefficient route)
211207
{
212208
QMap< QString, QgsRasterBlock * > inputBlocks;
213209
QVector<QgsRasterCalculatorEntry>::const_iterator it = mRasterEntries.constBegin();
@@ -294,7 +290,6 @@ QgsRasterCalculator::Result QgsRasterCalculator::processCalculation( QgsFeedback
294290

295291
}
296292

297-
298293
if ( feedback && feedback->isCanceled() )
299294
{
300295
//delete the dataset without closing (because it is faster)

0 commit comments

Comments
 (0)