Skip to content
Permalink
Browse files
Set nodata values in raster block
  • 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.
@@ -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 )
@@ -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 );
@@ -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;
}

@@ -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

0 comments on commit 968c6d8

Please sign in to comment.