Skip to content

Commit

Permalink
raster no data speed up
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Apr 13, 2013
1 parent 7d425bf commit 5280e21
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/core/raster/qgsrasterblock.cpp
Expand Up @@ -269,6 +269,11 @@ QGis::DataType QgsRasterBlock::typeWithNoDataValue( QGis::DataType dataType, dou
return newDataType;
}

bool QgsRasterBlock::hasNoData() const
{
return mHasNoDataValue || mNoDataBitmap != 0;
}

bool QgsRasterBlock::isNoDataValue( double value, double noDataValue )
{
// More precise would be qIsNaN(value) && qIsNaN(noDataValue(bandNo)), but probably
Expand Down Expand Up @@ -302,6 +307,7 @@ QRgb QgsRasterBlock::color( int row, int column ) const

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

void QgsRasterBlock::applyNodataValues( const QgsRasterRangeList & rangeList )
void QgsRasterBlock::applyNoDataValues( const QgsRasterRangeList & rangeList )
{
if ( rangeList.isEmpty() )
{
Expand Down
8 changes: 7 additions & 1 deletion src/core/raster/qgsrasterblock.h
Expand Up @@ -144,6 +144,12 @@ class CORE_EXPORT QgsRasterBlock
* @return true if the block has no data value */
bool hasNoDataValue() const { return mHasNoDataValue; }

/** Returns true if thee block may contain no data. It does not guarantee
* that it really contains any no data. It can be used to speed up processing.
* Not the difference between this method and hasNoDataValue().
* @return true if the block may contain no data */
bool hasNoData() const;

/** Return no data value.
* @return No data value */
double noDataValue() const { return mNoDataValue; }
Expand Down Expand Up @@ -292,7 +298,7 @@ class CORE_EXPORT QgsRasterBlock

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

void applyNodataValues( const QgsRasterRangeList & rangeList );
void applyNoDataValues( const QgsRasterRangeList & rangeList );

/** \brief Get error */
QgsError error() const { return mError; }
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgsrasterdataprovider.cpp
Expand Up @@ -233,7 +233,7 @@ QgsRasterBlock * QgsRasterDataProvider::block( int theBandNo, QgsRectangle cons

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

Expand Down
2 changes: 1 addition & 1 deletion src/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -386,7 +386,7 @@ QgsRasterBlock* QgsGdalProvider::block( int theBandNo, const QgsRectangle &theEx
block->setIsNoDataExcept( subRect );
}
readBlock( theBandNo, theExtent, theWidth, theHeight, block->data() );
block->applyNodataValues( userNoDataValue( theBandNo ) );
block->applyNoDataValues( userNoDataValue( theBandNo ) );
return block;
}

Expand Down

0 comments on commit 5280e21

Please sign in to comment.