Skip to content

Commit b11769f

Browse files
committed
Calculate block extent directly from iterator
1 parent 76eb29d commit b11769f

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/analysis/processing/qgsrasteranalysisutils.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,14 @@ void QgsRasterAnalysisUtils::statisticsFromMiddlePointTest( QgsRasterInterface *
7373
int iterTop = 0;
7474
int iterCols = 0;
7575
int iterRows = 0;
76-
while ( iter.readNextRasterPart( rasterBand, iterCols, iterRows, block, iterLeft, iterTop ) )
76+
QgsRectangle blockExtent;
77+
while ( iter.readNextRasterPart( rasterBand, iterCols, iterRows, block, iterLeft, iterTop, &blockExtent ) )
7778
{
78-
double cellCenterY = rasterBBox.yMinimum() + ( iterTop + iterRows - 0.5 ) * cellSizeY;
79+
double cellCenterY = blockExtent.yMaximum() - 0.5 * cellSizeY;
80+
7981
for ( int row = 0; row < iterRows; ++row )
8082
{
81-
double cellCenterX = rasterBBox.xMinimum() + ( iterLeft + 0.5 ) * cellSizeX;
83+
double cellCenterX = blockExtent.xMinimum() + 0.5 * cellSizeX;
8284
for ( int col = 0; col < iterCols; ++col )
8385
{
8486
double pixelValue = block->value( row, col );
@@ -121,12 +123,13 @@ void QgsRasterAnalysisUtils::statisticsFromPreciseIntersection( QgsRasterInterfa
121123
int iterTop = 0;
122124
int iterCols = 0;
123125
int iterRows = 0;
124-
while ( iter.readNextRasterPart( rasterBand, iterCols, iterRows, block, iterLeft, iterTop ) )
126+
QgsRectangle blockExtent;
127+
while ( iter.readNextRasterPart( rasterBand, iterCols, iterRows, block, iterLeft, iterTop, &blockExtent ) )
125128
{
126-
double currentY = rasterBBox.yMinimum() + ( iterTop + iterRows - 0.5 ) * cellSizeY;
129+
double currentY = blockExtent.yMaximum() - 0.5 * cellSizeY;
127130
for ( int row = 0; row < iterRows; ++row )
128131
{
129-
double currentX = rasterBBox.xMinimum() + ( iterLeft + 0.5 ) * cellSizeX;
132+
double currentX = blockExtent.xMinimum() + 0.5 * cellSizeX;
130133
for ( int col = 0; col < iterCols; ++col )
131134
{
132135
double pixelValue = block->value( row, col );

0 commit comments

Comments
 (0)