23 , mMaximumTileWidth( DEFAULT_MAXIMUM_TILE_WIDTH )
24 , mMaximumTileHeight( DEFAULT_MAXIMUM_TILE_HEIGHT )
40 const double xRes = rasterExtent.
width() / rasterWidth;
41 const double yRes = rasterExtent.
height() / rasterHeight;
44 int bottom = rasterHeight - 1;
46 int right = rasterWidth - 1;
66 subRegionWidth = right - left + 1;
67 subRegionHeight = bottom - top + 1;
72 rasterExtent.
yMaximum() - ( ( top + subRegionHeight ) * yRes ),
73 rasterExtent.
xMinimum() + ( ( left + subRegionWidth ) * xRes ),
74 rasterExtent.
yMaximum() - ( top * yRes ) );
88 removePartInfo( bandNumber );
96 mRasterPartInfos.insert( bandNumber, pInfo );
101 return readNextRasterPartInternal( bandNumber, columns, rows,
nullptr, topLeftColumn, topLeftRow, &blockExtent );
105 int &nCols,
int &nRows,
107 int &topLeftCol,
int &topLeftRow )
110 std::unique_ptr< QgsRasterBlock > nextBlock;
111 const bool result =
readNextRasterPart( bandNumber, nCols, nRows, nextBlock, topLeftCol, topLeftRow );
113 *block = nextBlock.release();
119 return readNextRasterPartInternal( bandNumber, nCols, nRows, &block, topLeftCol, topLeftRow, blockExtent );
122bool QgsRasterIterator::readNextRasterPartInternal(
int bandNumber,
int &nCols,
int &nRows, std::unique_ptr<QgsRasterBlock> *block,
int &topLeftCol,
int &topLeftRow,
QgsRectangle *blockExtent )
128 const QMap<int, RasterPartInfo>::iterator partIt = mRasterPartInfos.find( bandNumber );
129 if ( partIt == mRasterPartInfos.end() )
134 RasterPartInfo &pInfo = partIt.value();
137 if ( 0 == pInfo.nCols || 0 == pInfo.nRows )
145 if ( pInfo.currentCol == pInfo.nCols && pInfo.currentRow == pInfo.nRows )
151 nCols =
static_cast< int >( std::min(
static_cast< qgssize >( mMaximumTileWidth ), pInfo.nCols - pInfo.currentCol ) );
152 nRows =
static_cast< int >( std::min(
static_cast< qgssize >( mMaximumTileHeight ), pInfo.nRows - pInfo.currentRow ) );
153 QgsDebugMsgLevel( QStringLiteral(
"nCols = %1 nRows = %2" ).arg( nCols ).arg( nRows ), 4 );
157 const double xmin = viewPortExtent.
xMinimum() + pInfo.currentCol /
static_cast< double >( pInfo.nCols ) * viewPortExtent.
width();
158 const double xmax = pInfo.currentCol + nCols == pInfo.nCols ? viewPortExtent.
xMaximum() :
159 viewPortExtent.
xMinimum() + ( pInfo.currentCol + nCols ) /
static_cast< double >( pInfo.nCols ) * viewPortExtent.
width();
160 const double ymin = pInfo.currentRow + nRows == pInfo.nRows ? viewPortExtent.
yMinimum() :
161 viewPortExtent.
yMaximum() - ( pInfo.currentRow + nRows ) /
static_cast< double >( pInfo.nRows ) * viewPortExtent.
height();
162 const double ymax = viewPortExtent.
yMaximum() - pInfo.currentRow /
static_cast< double >( pInfo.nRows ) * viewPortExtent.
height();
166 *blockExtent = blockRect;
169 block->reset( mInput->
block( bandNumber, blockRect, nCols, nRows, mFeedback ) );
170 topLeftCol = pInfo.currentCol;
171 topLeftRow = pInfo.currentRow;
173 pInfo.currentCol += nCols;
174 if ( pInfo.currentCol == pInfo.nCols && pInfo.currentRow + nRows == pInfo.nRows )
176 pInfo.currentRow = pInfo.nRows;
178 else if ( pInfo.currentCol == pInfo.nCols )
180 pInfo.currentCol = 0;
181 pInfo.currentRow += nRows;
189 removePartInfo( bandNumber );
192void QgsRasterIterator::removePartInfo(
int bandNumber )
194 const auto partIt = mRasterPartInfos.constFind( bandNumber );
195 if ( partIt != mRasterPartInfos.constEnd() )
197 mRasterPartInfos.remove( bandNumber );
Feedback object tailored for raster block reading.
Base class for raster data providers.
virtual int stepHeight() const
Step height for raster iterations.
virtual int stepWidth() const
Step width for raster iterations.
Base class for processing filters like renderers, reprojector, resampler etc.
virtual QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr)=0
Read block of data using given extent and size.
virtual QgsRasterInterface * input() const
Current input.
bool next(int bandNumber, int &columns, int &rows, int &topLeftColumn, int &topLeftRow, QgsRectangle &blockExtent)
Fetches details of the next part of the raster data.
const QgsRasterInterface * input() const
Returns the input raster interface which is being iterated over.
void stopRasterRead(int bandNumber)
Cancels the raster iteration and resets the iterator.
bool readNextRasterPart(int bandNumber, int &nCols, int &nRows, QgsRasterBlock **block, int &topLeftCol, int &topLeftRow)
Fetches next part of raster data, caller takes ownership of the block and caller should delete the bl...
static QgsRectangle subRegion(const QgsRectangle &rasterExtent, int rasterWidth, int rasterHeight, const QgsRectangle &subRegion, int &subRegionWidth, int &subRegionHeight, int &subRegionLeft, int &subRegionTop)
Given an overall raster extent and width and height in pixels, calculates the sub region of the raste...
void startRasterRead(int bandNumber, qgssize nCols, qgssize nRows, const QgsRectangle &extent, QgsRasterBlockFeedback *feedback=nullptr)
Start reading of raster band.
QgsRasterIterator(QgsRasterInterface *input)
Constructor for QgsRasterIterator, iterating over the specified input raster source.
A rectangle specified with double values.
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
unsigned long long qgssize
Qgssize is used instead of size_t, because size_t is stdlib type, unknown by SIP, and it would be har...
#define QgsDebugMsgLevel(str, level)