Skip to content
Permalink
Browse files

Possibility to set maximum tile width / height in raster iterator

  • Loading branch information
mhugent committed Jul 11, 2012
1 parent 6002e6f commit 54a82e0b899b60493c699b9c292c810175745faa
Showing with 14 additions and 18 deletions.
  1. +5 −16 src/core/raster/qgsrasteriterator.cpp
  2. +9 −2 src/core/raster/qgsrasteriterator.h
@@ -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 )
{
}

@@ -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;
@@ -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;
@@ -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;
@@ -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)
};
@@ -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 );
};

0 comments on commit 54a82e0

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