Skip to content

Commit 6a76502

Browse files
committed
Make QgsRasterIterator optionally return the exact extent of the
current block returned ... because this is very difficult to calculate exactly outside of the iterator, yet the iterator itself has this knowledge already...
1 parent dcff720 commit 6a76502

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/core/raster/qgsrasteriterator.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ bool QgsRasterIterator::readNextRasterPart( int bandNumber,
7070
return result;
7171
}
7272

73-
bool QgsRasterIterator::readNextRasterPart( int bandNumber, int &nCols, int &nRows, std::unique_ptr<QgsRasterBlock> &block, int &topLeftCol, int &topLeftRow )
73+
bool QgsRasterIterator::readNextRasterPart( int bandNumber, int &nCols, int &nRows, std::unique_ptr<QgsRasterBlock> &block, int &topLeftCol, int &topLeftRow, QgsRectangle *blockExtent )
7474
{
7575
QgsDebugMsgLevel( QStringLiteral( "Entered" ), 4 );
7676
block.reset();
@@ -112,6 +112,9 @@ bool QgsRasterIterator::readNextRasterPart( int bandNumber, int &nCols, int &nRo
112112
double ymax = viewPortExtent.yMaximum() - pInfo.currentRow / static_cast< double >( pInfo.nRows ) * viewPortExtent.height();
113113
QgsRectangle blockRect( xmin, ymin, xmax, ymax );
114114

115+
if ( blockExtent )
116+
*blockExtent = blockRect;
117+
115118
block.reset( mInput->block( bandNumber, blockRect, nCols, nRows, mFeedback ) );
116119
topLeftCol = pInfo.currentCol;
117120
topLeftRow = pInfo.currentRow;

src/core/raster/qgsrasteriterator.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,16 @@ class CORE_EXPORT QgsRasterIterator
7070
* \param block address of block pointer
7171
* \param topLeftCol top left column
7272
* \param topLeftRow top left row
73+
* \param blockExtent optional storage for exact extent of returned raster block
7374
* \returns false if the last part was already returned
7475
* \note Not available in Python bindings
7576
* \since QGIS 3.2
7677
*/
7778
bool readNextRasterPart( int bandNumber,
7879
int &nCols, int &nRows,
7980
std::unique_ptr< QgsRasterBlock > &block,
80-
int &topLeftCol, int &topLeftRow ) SIP_SKIP;
81+
int &topLeftCol, int &topLeftRow,
82+
QgsRectangle *blockExtent = nullptr ) SIP_SKIP;
8183

8284
void stopRasterRead( int bandNumber );
8385

0 commit comments

Comments
 (0)