Skip to content

Commit 5280e21

Browse files
committedApr 13, 2013
raster no data speed up
1 parent 7d425bf commit 5280e21

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed
 

‎src/core/raster/qgsrasterblock.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@ QGis::DataType QgsRasterBlock::typeWithNoDataValue( QGis::DataType dataType, dou
269269
return newDataType;
270270
}
271271

272+
bool QgsRasterBlock::hasNoData() const
273+
{
274+
return mHasNoDataValue || mNoDataBitmap != 0;
275+
}
276+
272277
bool QgsRasterBlock::isNoDataValue( double value, double noDataValue )
273278
{
274279
// More precise would be qIsNaN(value) && qIsNaN(noDataValue(bandNo)), but probably
@@ -302,6 +307,7 @@ QRgb QgsRasterBlock::color( int row, int column ) const
302307

303308
bool QgsRasterBlock::isNoData( size_t index )
304309
{
310+
if ( !mHasNoDataValue && !mNoDataBitmap ) return false;
305311
if ( index >= ( size_t )mWidth*mHeight )
306312
{
307313
QgsDebugMsg( QString( "Index %1 out of range (%2 x %3)" ).arg( index ).arg( mWidth ).arg( mHeight ) );
@@ -662,7 +668,7 @@ bool QgsRasterBlock::convert( QGis::DataType destDataType )
662668
return true;
663669
}
664670

665-
void QgsRasterBlock::applyNodataValues( const QgsRasterRangeList & rangeList )
671+
void QgsRasterBlock::applyNoDataValues( const QgsRasterRangeList & rangeList )
666672
{
667673
if ( rangeList.isEmpty() )
668674
{

‎src/core/raster/qgsrasterblock.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ class CORE_EXPORT QgsRasterBlock
144144
* @return true if the block has no data value */
145145
bool hasNoDataValue() const { return mHasNoDataValue; }
146146

147+
/** Returns true if thee block may contain no data. It does not guarantee
148+
* that it really contains any no data. It can be used to speed up processing.
149+
* Not the difference between this method and hasNoDataValue().
150+
* @return true if the block may contain no data */
151+
bool hasNoData() const;
152+
147153
/** Return no data value.
148154
* @return No data value */
149155
double noDataValue() const { return mNoDataValue; }
@@ -292,7 +298,7 @@ class CORE_EXPORT QgsRasterBlock
292298

293299
inline static void writeValue( void *data, QGis::DataType type, size_t index, double value );
294300

295-
void applyNodataValues( const QgsRasterRangeList & rangeList );
301+
void applyNoDataValues( const QgsRasterRangeList & rangeList );
296302

297303
/** \brief Get error */
298304
QgsError error() const { return mError; }

‎src/core/raster/qgsrasterdataprovider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ QgsRasterBlock * QgsRasterDataProvider::block( int theBandNo, QgsRectangle cons
233233

234234
// apply user no data values
235235
// TODO: there are other readBlock methods where no data are not applied
236-
block->applyNodataValues( userNoDataValue( theBandNo ) );
236+
block->applyNoDataValues( userNoDataValue( theBandNo ) );
237237
return block;
238238
}
239239

‎src/providers/gdal/qgsgdalprovider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ QgsRasterBlock* QgsGdalProvider::block( int theBandNo, const QgsRectangle &theEx
386386
block->setIsNoDataExcept( subRect );
387387
}
388388
readBlock( theBandNo, theExtent, theWidth, theHeight, block->data() );
389-
block->applyNodataValues( userNoDataValue( theBandNo ) );
389+
block->applyNoDataValues( userNoDataValue( theBandNo ) );
390390
return block;
391391
}
392392

0 commit comments

Comments
 (0)
Please sign in to comment.