Skip to content

Commit 7505792

Browse files
committed
Implement readBlock in gdal provider for performance reason
1 parent d1a976e commit 7505792

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/providers/gdal/qgsgdalprovider.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,36 @@ QImage* QgsGdalProvider::draw( QgsRectangle const & viewExtent, int pixelWidth,
363363
return image;
364364
}
365365

366+
QgsRasterBlock* QgsGdalProvider::block( int theBandNo, const QgsRectangle &theExtent, int theWidth, int theHeight )
367+
{
368+
QgsRasterBlock *block = new QgsRasterBlock( dataType( theBandNo ), theWidth, theHeight, noDataValue( theBandNo ) );
369+
370+
if ( block->isEmpty() )
371+
{
372+
return block;
373+
}
374+
375+
readBlock( theBandNo, theExtent, theWidth, theHeight, block->data() );
376+
377+
// apply user no data values
378+
QList<QgsRasterBlock::Range> myNoDataRangeList = userNoDataValue( theBandNo );
379+
if ( !myNoDataRangeList.isEmpty() )
380+
{
381+
double myNoDataValue = noDataValue( theBandNo );
382+
size_t size = theWidth * theHeight;
383+
for ( size_t i = 0; i < size; i++ )
384+
{
385+
double value = block->value( i );
386+
387+
if ( QgsRasterBlock::valueInRange( value, myNoDataRangeList ) )
388+
{
389+
block->setValue( i, myNoDataValue );
390+
}
391+
}
392+
}
393+
return block;
394+
}
395+
366396

367397
void QgsGdalProvider::readBlock( int theBandNo, int xBlock, int yBlock, void *block )
368398
{

src/providers/gdal/qgsgdalprovider.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ class QgsGdalProvider : public QgsRasterDataProvider, QgsGdalProviderBase
166166
int xSize() const;
167167
int ySize() const;
168168

169+
/**Reimplemented from QgsRasterDataProvider to bypass second resampling (more efficient for local file based sources)*/
170+
QgsRasterBlock *block( int theBandNo, const QgsRectangle &theExtent, int theWidth, int theHeight );
169171

170172
void readBlock( int bandNo, int xBlock, int yBlock, void *data );
171173
void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data );

0 commit comments

Comments
 (0)