Skip to content

Commit 62d02b5

Browse files
elpasonyalldawson
authored andcommittedOct 5, 2020
Raster paletted float: reduce memory consumption & UX improvements
Also, makes it possible to interrupt the block reading and makes the feedback reporting much more precise and smoother, at the cost of a bit slower execution.
1 parent 09fe306 commit 62d02b5

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed
 

‎src/core/raster/qgspalettedrasterrenderer.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -480,26 +480,26 @@ QgsPalettedRasterRenderer::ClassData QgsPalettedRasterRenderer::classDataFromRas
480480
// Collect unique values for float rasters
481481
if ( raster->dataType( bandNumber ) == Qgis::DataType::Float32 || raster->dataType( bandNumber ) == Qgis::DataType::Float64 )
482482
{
483+
const QgsRectangle fullExtent { raster->extent() };
483484
QList<double> values;
484-
if ( feedback )
485-
{
486-
// Start showing some progress
487-
feedback->setProgress( 1 );
488-
}
489-
std::unique_ptr<QgsRasterBlock> block { raster->block( bandNumber, raster->extent(), raster->xSize(), raster->ySize(), feedback ) };
485+
490486
if ( feedback && feedback->isCanceled() )
491487
{
492488
return data;
493489
}
490+
const double yStep { fullExtent.height() / raster->ySize() };
494491
// Max MAX_FLOAT_CLASSES classes!
495492
qgssize col = 0;
496493
qgssize row = 0;
497-
for ( ; row < static_cast<qgssize>( raster->ySize() ); ++row )
494+
for ( row = raster->ySize() - 1; row >= 0; --row )
498495
{
499496
if ( presentValues >= MAX_FLOAT_CLASSES )
500497
{
501498
break;
502499
}
500+
raster->extent();
501+
const QgsRectangle rowExtent { fullExtent.xMinimum(), fullExtent.yMinimum() + yStep * row, fullExtent.xMaximum(), fullExtent.yMinimum() + yStep *( row + 1 ) };
502+
std::unique_ptr<QgsRasterBlock> block { raster->block( bandNumber, rowExtent, raster->xSize(), 1, feedback ) };
503503
for ( col = 0; col < static_cast<qgssize>( raster->xSize() ); ++col )
504504
{
505505
if ( presentValues >= MAX_FLOAT_CLASSES )
@@ -511,7 +511,7 @@ QgsPalettedRasterRenderer::ClassData QgsPalettedRasterRenderer::classDataFromRas
511511
return data;
512512
}
513513
bool isNoData;
514-
const double currentValue { block->valueAndNoData( row, col, isNoData ) };
514+
const double currentValue { block->valueAndNoData( 0, col, isNoData ) };
515515
if ( ! isNoData && !values.contains( currentValue ) )
516516
{
517517
values.push_back( currentValue );
@@ -521,8 +521,10 @@ QgsPalettedRasterRenderer::ClassData QgsPalettedRasterRenderer::classDataFromRas
521521
}
522522
if ( feedback )
523523
{
524-
// Show no less than 2%, then the max between class fill and real progress
525-
feedback->setProgress( std::max<int>( 2, 100 * std::max<double>( ( row + 1 ) / raster->ySize(), presentValues / MAX_FLOAT_CLASSES ) ) );
524+
// Show the max between class fill and real
525+
const double progress { 100 * std::max<double>( ( raster->ySize() - row + 1 ) / raster->ySize(), presentValues / MAX_FLOAT_CLASSES ) };
526+
feedback->setProgress( progress );
527+
// qDebug() << "Progress: " << progress;
526528
}
527529
}
528530
if ( presentValues == MAX_FLOAT_CLASSES && ( col < static_cast<qgssize>( raster->xSize() ) || row < static_cast<qgssize>( raster->ySize() ) ) )

0 commit comments

Comments
 (0)
Please sign in to comment.