Skip to content

Commit

Permalink
Possibility to set maximum tile width / height in raster iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jul 11, 2012
1 parent 6002e6f commit 54a82e0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
21 changes: 5 additions & 16 deletions src/core/raster/qgsrasteriterator.cpp
Expand Up @@ -3,7 +3,8 @@
#include "qgsrasterprojector.h"
#include "qgsrasterviewport.h"

QgsRasterIterator::QgsRasterIterator( QgsRasterInterface* input ): mInput( input )
QgsRasterIterator::QgsRasterIterator( QgsRasterInterface* input ): mInput( input ),
mMaximumTileWidth( 2000 ), mMaximumTileHeight( 2000 )
{
}

Expand All @@ -27,18 +28,6 @@ void QgsRasterIterator::startRasterRead( int bandNumber, int nCols, int nRows, c
RasterPartInfo pInfo;
pInfo.nCols = nCols;
pInfo.nRows = nRows;

//effective oversampling factors are different to global one because of rounding
//oversamplingX = (( double )pInfo.nCols * oversampling ) / viewPort->drawableAreaXDim;
//oversamplingY = (( double )pInfo.nRows * oversampling ) / viewPort->drawableAreaYDim;

// TODO : we dont know oversampling (grid size) here - how to get totalMemoryUsage ?
//int totalMemoryUsage = pInfo.nCols * oversamplingX * pInfo.nRows * oversamplingY * mInput->dataTypeSize( bandNumber );
int totalMemoryUsage = pInfo.nCols * pInfo.nRows * mInput->dataTypeSize( bandNumber );
int parts = totalMemoryUsage / 100000000 + 1;
int nPartsPerDimension = sqrt( parts );
pInfo.nColsPerPart = pInfo.nCols / nPartsPerDimension;
pInfo.nRowsPerPart = pInfo.nRows / nPartsPerDimension;
pInfo.currentCol = 0;
pInfo.currentRow = 0;
pInfo.data = 0;
Expand Down Expand Up @@ -74,8 +63,8 @@ bool QgsRasterIterator::readNextRasterPart( int bandNumber,
}

//read data block
nCols = qMin( pInfo.nColsPerPart, pInfo.nCols - pInfo.currentCol );
nRows = qMin( pInfo.nRowsPerPart, pInfo.nRows - pInfo.currentRow );
nCols = qMin( mMaximumTileWidth, pInfo.nCols - pInfo.currentCol );
nRows = qMin( mMaximumTileHeight, pInfo.nRows - pInfo.currentRow );

//get subrectangle
QgsRectangle viewPortExtent = mExtent;
Expand All @@ -99,7 +88,7 @@ bool QgsRasterIterator::readNextRasterPart( int bandNumber,
else if ( pInfo.currentCol == pInfo.nCols ) //start new row
{
pInfo.currentCol = 0;
pInfo.currentRow += pInfo.nRowsPerPart;
pInfo.currentRow += nRows;
}

return true;
Expand Down
11 changes: 9 additions & 2 deletions src/core/raster/qgsrasteriterator.h
Expand Up @@ -19,8 +19,6 @@ class QgsRasterIterator
int currentRow;
int nCols;
int nRows;
int nColsPerPart;
int nRowsPerPart;
void* data; //data (can be in oversampled/undersampled resolution)
QgsRasterProjector* prj; //raster projector (or 0 if no reprojection is done)
};
Expand Down Expand Up @@ -48,11 +46,20 @@ class QgsRasterIterator

const QgsRasterInterface* input() const { return mInput; }

void setMaximumTileWidth( int w ) { mMaximumTileWidth = w; }
int maximumTileWidth() const { return mMaximumTileWidth; }

void setMaximumTileHeight( int h ) { mMaximumTileHeight = h; }
int maximumTileHeight() const { return mMaximumTileHeight; }

private:
QgsRasterInterface* mInput;
QMap<int, RasterPartInfo> mRasterPartInfos;
QgsRectangle mExtent;

int mMaximumTileWidth;
int mMaximumTileHeight;

/**Remove part into and release memory*/
void removePartInfo( int bandNumber );
};
Expand Down

0 comments on commit 54a82e0

Please sign in to comment.