Skip to content
Permalink
Browse files

Fix display of raster layer that would sometimes show just garbage

If a raster layer was displayed in a way that it fitted into canvas,
but would be shifted towards left or top edge of canvas, that bug
would be triggered.

By doing extra floating point math where not necessary, small
imprecisions were introduced to extent definition and GDAL provider
would end up requesting a window one pixel taller or wider, which
leads to RasterIO error and results into garbage displayed on canvas
  • Loading branch information
wonder-sk committed Jan 20, 2016
1 parent f0cb706 commit ed1efcbe22b5788b50907e1f1fb59168cca6dbaf
Showing with 4 additions and 2 deletions.
  1. +4 −2 src/core/raster/qgsrasteriterator.cpp
@@ -88,8 +88,10 @@ bool QgsRasterIterator::readNextRasterPart( int bandNumber,
//get subrectangle
QgsRectangle viewPortExtent = mExtent;
double xmin = viewPortExtent.xMinimum() + pInfo.currentCol / static_cast< double >( pInfo.nCols ) * viewPortExtent.width();
double xmax = viewPortExtent.xMinimum() + ( pInfo.currentCol + nCols ) / static_cast< double >( pInfo.nCols ) * viewPortExtent.width();
double ymin = viewPortExtent.yMaximum() - ( pInfo.currentRow + nRows ) / static_cast< double >( pInfo.nRows ) * viewPortExtent.height();
double xmax = pInfo.currentCol + nCols == pInfo.nCols ? viewPortExtent.xMaximum() : // avoid extra FP math if not necessary
viewPortExtent.xMinimum() + ( pInfo.currentCol + nCols ) / static_cast< double >( pInfo.nCols ) * viewPortExtent.width();
double ymin = pInfo.currentRow + nRows == pInfo.nRows ? viewPortExtent.yMinimum() : // avoid extra FP math if not necessary
viewPortExtent.yMaximum() - ( pInfo.currentRow + nRows ) / static_cast< double >( pInfo.nRows ) * viewPortExtent.height();
double ymax = viewPortExtent.yMaximum() - pInfo.currentRow / static_cast< double >( pInfo.nRows ) * viewPortExtent.height();
QgsRectangle blockRect( xmin, ymin, xmax, ymax );

0 comments on commit ed1efcb

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