Skip to content

Commit

Permalink
Make QgsRasterIterator optionally return the exact extent of the
Browse files Browse the repository at this point in the history
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 6a76502
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/core/raster/qgsrasteriterator.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/core/raster/qgsrasteriterator.h
Expand Up @@ -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 );

Expand Down

0 comments on commit 6a76502

Please sign in to comment.