Skip to content

Commit 968c6d8

Browse files
committed
Set nodata values in raster block
1 parent 7505792 commit 968c6d8

File tree

4 files changed

+22
-34
lines changed

4 files changed

+22
-34
lines changed

src/core/raster/qgsrasterblock.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,24 @@ bool QgsRasterBlock::convert( QgsRasterBlock::DataType destDataType )
410410
return true;
411411
}
412412

413+
void QgsRasterBlock::applyNodataValues( const QList<Range>& rangeList )
414+
{
415+
if ( rangeList.isEmpty() )
416+
{
417+
return;
418+
}
419+
420+
size_t size = mWidth * mHeight;
421+
for ( size_t i = 0; i < size; ++i )
422+
{
423+
double val = value( i );
424+
if ( valueInRange( val, rangeList ) )
425+
{
426+
setValue( i, mNoDataValue );
427+
}
428+
}
429+
}
430+
413431
QImage QgsRasterBlock::image() const
414432
{
415433
if ( mImage )

src/core/raster/qgsrasterblock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ class CORE_EXPORT QgsRasterBlock
304304

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

307+
void applyNodataValues( const QList<Range>& rangeList );
308+
307309
private:
308310

309311
static QImage::Format imageFormat( QgsRasterBlock::DataType theDataType );

src/core/raster/qgsrasterdataprovider.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -194,22 +194,7 @@ QgsRasterBlock * QgsRasterDataProvider::block( int theBandNo, QgsRectangle cons
194194

195195
// apply user no data values
196196
// TODO: there are other readBlock methods where no data are not applied
197-
QList<QgsRasterBlock::Range> myNoDataRangeList = userNoDataValue( theBandNo );
198-
if ( !myNoDataRangeList.isEmpty() )
199-
{
200-
double myNoDataValue = noDataValue( theBandNo );
201-
size_t size = theWidth * theHeight;
202-
for ( size_t i = 0; i < size; i++ )
203-
{
204-
double value = block->value( i );
205-
206-
if ( QgsRasterBlock::valueInRange( value, myNoDataRangeList ) )
207-
{
208-
block->setValue( i, myNoDataValue );
209-
}
210-
}
211-
}
212-
197+
block->applyNodataValues( userNoDataValue( theBandNo ) );
213198
return block;
214199
}
215200

src/providers/gdal/qgsgdalprovider.cpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -373,27 +373,10 @@ QgsRasterBlock* QgsGdalProvider::block( int theBandNo, const QgsRectangle &theEx
373373
}
374374

375375
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-
}
376+
block->applyNodataValues( userNoDataValue( theBandNo ) );
393377
return block;
394378
}
395379

396-
397380
void QgsGdalProvider::readBlock( int theBandNo, int xBlock, int yBlock, void *block )
398381
{
399382
// TODO!!!: Check data alignment!!! May it happen that nearest value which

0 commit comments

Comments
 (0)