14 changes: 11 additions & 3 deletions src/core/raster/qgsrasterprojector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,18 +752,26 @@ QgsRasterBlock * QgsRasterProjector::block( int bandNo, QgsRectangle const & ex
return outputBlock;
}

// TODO: fill by no data or transparent
// we are using memcpy on bits, so we have to use setIsNoData if necessary
// so that bitmaps is set if necessary
//outputBlock->setIsNoData();

int srcRow, srcCol;
for ( int i = 0; i < height; ++i )
{
for ( int j = 0; j < width; ++j )
{
srcRowCol( i, j, &srcRow, &srcCol );
QgsDebugMsgLevel( QString( "row = %1 col = %2 srcRow = %3 srcCol = %4" ).arg( i ).arg( j ).arg( srcRow ).arg( srcCol ), 5 );
size_t srcIndex = srcRow * mSrcCols + srcCol;
size_t destIndex = i * width + j;
QgsDebugMsgLevel( QString( "row = %1 col = %2 srcRow = %3 srcCol = %4" ).arg( i ).arg( j ).arg( srcRow ).arg( srcCol ), 5 );

if ( inputBlock->isNoData( srcRow, srcCol ) )
{
outputBlock->setIsNoData( srcRow, srcCol );
continue ;
}

size_t destIndex = i * width + j;
char *srcBits = inputBlock->bits( srcIndex );
char *destBits = outputBlock->bits( destIndex );
if ( !srcBits )
Expand Down
11 changes: 10 additions & 1 deletion src/providers/gdal/qgsgdalprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ QgsRasterBlock* QgsGdalProvider::block( int theBandNo, const QgsRectangle &theEx

if ( !mExtent.contains( theExtent ) )
{
block->setIsNoData();
QRect subRect = QgsRasterBlock::subRect( theExtent, theWidth, theHeight, mExtent );
block->setIsNoDataExcept( subRect );
}
readBlock( theBandNo, theExtent, theWidth, theHeight, block->data() );
block->applyNodataValues( userNoDataValue( theBandNo ) );
Expand Down Expand Up @@ -450,6 +451,7 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,

// Find top, bottom rows and left, right column the raster extent covers
// These are limits in target grid space
#if 0
int top = 0;
int bottom = thePixelHeight - 1;
int left = 0;
Expand All @@ -472,8 +474,15 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
{
right = qRound(( myRasterExtent.xMaximum() - theExtent.xMinimum() ) / xRes ) - 1;
}
#endif
QRect subRect = QgsRasterBlock::subRect( theExtent, thePixelWidth, thePixelHeight, myRasterExtent );
int top = subRect.top();
int bottom = subRect.bottom();
int left = subRect.left();
int right = subRect.right();
QgsDebugMsg( QString( "top = %1 bottom = %2 left = %3 right = %4" ).arg( top ).arg( bottom ).arg( left ).arg( right ) );


// We want to avoid another resampling, so we read data approximately with
// the same resolution as requested and exactly the width/height we need.

Expand Down