Skip to content
Permalink
Browse files

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...
  • Loading branch information
nyalldawson committed Jun 14, 2018
1 parent dcff720 commit 6a76502bbc62f44cad2de4a72d515b02591f6aed
Showing with 7 additions and 2 deletions.
  1. +4 −1 src/core/raster/qgsrasteriterator.cpp
  2. +3 −1 src/core/raster/qgsrasteriterator.h
@@ -70,7 +70,7 @@ bool QgsRasterIterator::readNextRasterPart( int bandNumber,
return result;
}

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

if ( blockExtent )
*blockExtent = blockRect;

block.reset( mInput->block( bandNumber, blockRect, nCols, nRows, mFeedback ) );
topLeftCol = pInfo.currentCol;
topLeftRow = pInfo.currentRow;
@@ -70,14 +70,16 @@ class CORE_EXPORT QgsRasterIterator
* \param block address of block pointer
* \param topLeftCol top left column
* \param topLeftRow top left row
* \param blockExtent optional storage for exact extent of returned raster block
* \returns false if the last part was already returned
* \note Not available in Python bindings
* \since QGIS 3.2
*/
bool readNextRasterPart( int bandNumber,
int &nCols, int &nRows,
std::unique_ptr< QgsRasterBlock > &block,
int &topLeftCol, int &topLeftRow ) SIP_SKIP;
int &topLeftCol, int &topLeftRow,
QgsRectangle *blockExtent = nullptr ) SIP_SKIP;

void stopRasterRead( int bandNumber );

0 comments on commit 6a76502

Please sign in to comment.
You can’t perform that action at this time.