Skip to content

Commit 54a82e0

Browse files
committed
Possibility to set maximum tile width / height in raster iterator
1 parent 6002e6f commit 54a82e0

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

src/core/raster/qgsrasteriterator.cpp

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
#include "qgsrasterprojector.h"
44
#include "qgsrasterviewport.h"
55

6-
QgsRasterIterator::QgsRasterIterator( QgsRasterInterface* input ): mInput( input )
6+
QgsRasterIterator::QgsRasterIterator( QgsRasterInterface* input ): mInput( input ),
7+
mMaximumTileWidth( 2000 ), mMaximumTileHeight( 2000 )
78
{
89
}
910

@@ -27,18 +28,6 @@ void QgsRasterIterator::startRasterRead( int bandNumber, int nCols, int nRows, c
2728
RasterPartInfo pInfo;
2829
pInfo.nCols = nCols;
2930
pInfo.nRows = nRows;
30-
31-
//effective oversampling factors are different to global one because of rounding
32-
//oversamplingX = (( double )pInfo.nCols * oversampling ) / viewPort->drawableAreaXDim;
33-
//oversamplingY = (( double )pInfo.nRows * oversampling ) / viewPort->drawableAreaYDim;
34-
35-
// TODO : we dont know oversampling (grid size) here - how to get totalMemoryUsage ?
36-
//int totalMemoryUsage = pInfo.nCols * oversamplingX * pInfo.nRows * oversamplingY * mInput->dataTypeSize( bandNumber );
37-
int totalMemoryUsage = pInfo.nCols * pInfo.nRows * mInput->dataTypeSize( bandNumber );
38-
int parts = totalMemoryUsage / 100000000 + 1;
39-
int nPartsPerDimension = sqrt( parts );
40-
pInfo.nColsPerPart = pInfo.nCols / nPartsPerDimension;
41-
pInfo.nRowsPerPart = pInfo.nRows / nPartsPerDimension;
4231
pInfo.currentCol = 0;
4332
pInfo.currentRow = 0;
4433
pInfo.data = 0;
@@ -74,8 +63,8 @@ bool QgsRasterIterator::readNextRasterPart( int bandNumber,
7463
}
7564

7665
//read data block
77-
nCols = qMin( pInfo.nColsPerPart, pInfo.nCols - pInfo.currentCol );
78-
nRows = qMin( pInfo.nRowsPerPart, pInfo.nRows - pInfo.currentRow );
66+
nCols = qMin( mMaximumTileWidth, pInfo.nCols - pInfo.currentCol );
67+
nRows = qMin( mMaximumTileHeight, pInfo.nRows - pInfo.currentRow );
7968

8069
//get subrectangle
8170
QgsRectangle viewPortExtent = mExtent;
@@ -99,7 +88,7 @@ bool QgsRasterIterator::readNextRasterPart( int bandNumber,
9988
else if ( pInfo.currentCol == pInfo.nCols ) //start new row
10089
{
10190
pInfo.currentCol = 0;
102-
pInfo.currentRow += pInfo.nRowsPerPart;
91+
pInfo.currentRow += nRows;
10392
}
10493

10594
return true;

src/core/raster/qgsrasteriterator.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ class QgsRasterIterator
1919
int currentRow;
2020
int nCols;
2121
int nRows;
22-
int nColsPerPart;
23-
int nRowsPerPart;
2422
void* data; //data (can be in oversampled/undersampled resolution)
2523
QgsRasterProjector* prj; //raster projector (or 0 if no reprojection is done)
2624
};
@@ -48,11 +46,20 @@ class QgsRasterIterator
4846

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

49+
void setMaximumTileWidth( int w ) { mMaximumTileWidth = w; }
50+
int maximumTileWidth() const { return mMaximumTileWidth; }
51+
52+
void setMaximumTileHeight( int h ) { mMaximumTileHeight = h; }
53+
int maximumTileHeight() const { return mMaximumTileHeight; }
54+
5155
private:
5256
QgsRasterInterface* mInput;
5357
QMap<int, RasterPartInfo> mRasterPartInfos;
5458
QgsRectangle mExtent;
5559

60+
int mMaximumTileWidth;
61+
int mMaximumTileHeight;
62+
5663
/**Remove part into and release memory*/
5764
void removePartInfo( int bandNumber );
5865
};

0 commit comments

Comments
 (0)