Skip to content

Commit 8336565

Browse files
committed
Fix some errors related to reading rasters in multiple parts
1 parent c81f4fb commit 8336565

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/core/raster/qgspalettedrasterrenderer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ void QgsPalettedRasterRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort,
5959
QImage img( nCols, nRows, QImage::Format_ARGB32_Premultiplied );
6060
QRgb* imageScanLine = 0;
6161
int val = 0;
62+
currentRasterPos = 0;
6263

6364
for ( int i = 0; i < nRows; ++i )
6465
{

src/core/raster/qgsrasterrenderer.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void QgsRasterRenderer::startRasterRead( int bandNumber, QgsRasterViewPort* view
5353
pInfo.nCols = viewPort->drawableAreaXDim * oversampling;
5454
pInfo.nRows = viewPort->drawableAreaYDim * oversampling;
5555
int totalMemoryUsage = pInfo.nCols * pInfo.nRows * mProvider->dataTypeSize( bandNumber );
56-
int parts = totalMemoryUsage / 100000000 + 1;
56+
int parts = totalMemoryUsage / 100000000 /*10000*/ + 1;
5757
pInfo.nPartsPerDimension = sqrt( parts );
5858
pInfo.nColsPerPart = pInfo.nCols / pInfo.nPartsPerDimension;
5959
pInfo.nRowsPerPart = pInfo.nRows / pInfo.nPartsPerDimension;
@@ -97,10 +97,10 @@ bool QgsRasterRenderer::readNextRasterPart( int bandNumber, QgsRasterViewPort* v
9797

9898
//get subrectangle
9999
QgsRectangle viewPortExtent = viewPort->mDrawnExtent;
100-
double xmin = viewPortExtent.xMinimum() + pInfo.currentCol / pInfo.nCols * viewPortExtent.width();
101-
double xmax = viewPortExtent.xMinimum() + ( pInfo.currentCol + nCols ) / pInfo.nCols * viewPortExtent.width();
102-
double ymin = viewPortExtent.yMinimum() + ( pInfo.currentRow + nRows ) / pInfo.nRows * viewPortExtent.height();
103-
double ymax = viewPortExtent.yMinimum() + pInfo.currentRow / pInfo.nRows * viewPortExtent.height();
100+
double xmin = viewPortExtent.xMinimum() + pInfo.currentCol / ( double )pInfo.nCols * viewPortExtent.width();
101+
double xmax = viewPortExtent.xMinimum() + ( pInfo.currentCol + nCols ) / ( double )pInfo.nCols * viewPortExtent.width();
102+
double ymin = viewPortExtent.yMaximum() - ( pInfo.currentRow + nRows ) / ( double )pInfo.nRows * viewPortExtent.height();
103+
double ymax = viewPortExtent.yMaximum() - pInfo.currentRow / ( double )pInfo.nRows * viewPortExtent.height();
104104
QgsRectangle blockRect( xmin, ymin, xmax, ymax );
105105

106106
mProvider->readBlock( bandNumber, blockRect, nCols, nRows, viewPort->mSrcCRS, viewPort->mDestCRS, pInfo.data );
@@ -109,9 +109,11 @@ bool QgsRasterRenderer::readNextRasterPart( int bandNumber, QgsRasterViewPort* v
109109
topLeftRow = pInfo.currentRow;
110110

111111
pInfo.currentCol += nCols;
112-
pInfo.currentRow += nRows;
113-
114-
if ( pInfo.currentCol == pInfo.nCols && pInfo.currentRow != pInfo.nRows ) //start new row
112+
if ( pInfo.currentCol == pInfo.nCols && pInfo.currentRow + nRows == pInfo.nRows ) //end of raster
113+
{
114+
pInfo.currentRow = pInfo.nRows;
115+
}
116+
else if ( pInfo.currentCol == pInfo.nCols ) //start new row
115117
{
116118
pInfo.currentCol = 0;
117119
pInfo.currentRow += pInfo.nRowsPerPart;

0 commit comments

Comments
 (0)