Skip to content

Commit

Permalink
Set nodata values in raster block
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Dec 14, 2012
1 parent 7505792 commit 968c6d8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 34 deletions.
18 changes: 18 additions & 0 deletions src/core/raster/qgsrasterblock.cpp
Expand Up @@ -410,6 +410,24 @@ bool QgsRasterBlock::convert( QgsRasterBlock::DataType destDataType )
return true;
}

void QgsRasterBlock::applyNodataValues( const QList<Range>& rangeList )
{
if ( rangeList.isEmpty() )
{
return;
}

size_t size = mWidth * mHeight;
for ( size_t i = 0; i < size; ++i )
{
double val = value( i );
if ( valueInRange( val, rangeList ) )
{
setValue( i, mNoDataValue );
}
}
}

QImage QgsRasterBlock::image() const
{
if ( mImage )
Expand Down
2 changes: 2 additions & 0 deletions src/core/raster/qgsrasterblock.h
Expand Up @@ -304,6 +304,8 @@ class CORE_EXPORT QgsRasterBlock

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

void applyNodataValues( const QList<Range>& rangeList );

private:

static QImage::Format imageFormat( QgsRasterBlock::DataType theDataType );
Expand Down
17 changes: 1 addition & 16 deletions src/core/raster/qgsrasterdataprovider.cpp
Expand Up @@ -194,22 +194,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
QList<QgsRasterBlock::Range> myNoDataRangeList = userNoDataValue( theBandNo );
if ( !myNoDataRangeList.isEmpty() )
{
double myNoDataValue = noDataValue( theBandNo );
size_t size = theWidth * theHeight;
for ( size_t i = 0; i < size; i++ )
{
double value = block->value( i );

if ( QgsRasterBlock::valueInRange( value, myNoDataRangeList ) )
{
block->setValue( i, myNoDataValue );
}
}
}

block->applyNodataValues( userNoDataValue( theBandNo ) );
return block;
}

Expand Down
19 changes: 1 addition & 18 deletions src/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -373,27 +373,10 @@ QgsRasterBlock* QgsGdalProvider::block( int theBandNo, const QgsRectangle &theEx
}

readBlock( theBandNo, theExtent, theWidth, theHeight, block->data() );

// apply user no data values
QList<QgsRasterBlock::Range> myNoDataRangeList = userNoDataValue( theBandNo );
if ( !myNoDataRangeList.isEmpty() )
{
double myNoDataValue = noDataValue( theBandNo );
size_t size = theWidth * theHeight;
for ( size_t i = 0; i < size; i++ )
{
double value = block->value( i );

if ( QgsRasterBlock::valueInRange( value, myNoDataRangeList ) )
{
block->setValue( i, myNoDataValue );
}
}
}
block->applyNodataValues( userNoDataValue( theBandNo ) );
return block;
}


void QgsGdalProvider::readBlock( int theBandNo, int xBlock, int yBlock, void *block )
{
// TODO!!!: Check data alignment!!! May it happen that nearest value which
Expand Down

0 comments on commit 968c6d8

Please sign in to comment.