Skip to content
Permalink
Browse files

convert GDAL no data value to a value representable by data type, fixes

  • Loading branch information
blazek committed Dec 14, 2013
1 parent 402b397 commit c4b248066da828c8f00f068053e50eff301ae663
@@ -53,4 +53,24 @@ QgsRaster::ContrastEnhancementLimits QgsRaster::contrastEnhancementLimitsFromStr
return ContrastEnhancementNone;
}


double QgsRaster::representableValue( double value, QGis::DataType dataType )
{
switch ( dataType )
{
case QGis::Byte:
return static_cast<quint8>( value );
case QGis::UInt16:
return static_cast<quint16>( value );
case QGis::Int16:
return static_cast<qint16>( value );
case QGis::UInt32:
return static_cast<quint32>( value );
case QGis::Int32:
return static_cast<qint32>( value );
case QGis::Float32:
return static_cast<float>( value );
default:
break;
}
return value;
}
@@ -20,6 +20,8 @@

#include <QString>

#include "qgis.h"

/** \ingroup core
* Raster namespace.
*/
@@ -108,6 +110,12 @@ class CORE_EXPORT QgsRaster
static QString contrastEnhancementLimitsAsString( QgsRaster::ContrastEnhancementLimits theLimits );
static ContrastEnhancementLimits contrastEnhancementLimitsFromString( QString theLimits );

/** Get value representable by given data type.
* Supported are numerical types Byte, UInt16, Int16, UInt32, Int32, Float32, Float64.
* @param value
* @param dataType
* @note added in version 2.1 */
static double representableValue( double value, QGis::DataType dataType );
};

#endif
@@ -2411,6 +2411,10 @@ void QgsGdalProvider::initBaseDataset()
if ( isValid )
{
QgsDebugMsg( QString( "GDALGetRasterNoDataValue = %1" ).arg( myNoDataValue ) ) ;
// The no data value double may be non representable by data type, it can result
// in problems if that value is used to represent additional user defined no data
// see #3840
myNoDataValue = QgsRaster::representableValue( myNoDataValue, dataTypeFromGdal( myGdalDataType ) );
mSrcNoDataValue.append( myNoDataValue );
mSrcHasNoDataValue.append( true );
mUseSrcNoDataValue.append( true );
@@ -303,6 +303,7 @@ QgsWcsProvider::QgsWcsProvider( QString const &uri )
if ( isValid )
{
QgsDebugMsg( QString( "GDALGetRasterNoDataValue = %1" ).arg( myNoDataValue ) ) ;
myNoDataValue = QgsRaster::representableValue( myNoDataValue, dataTypeFromGdal( myGdalDataType ) );
mSrcNoDataValue.append( myNoDataValue );
mSrcHasNoDataValue.append( true );
mUseSrcNoDataValue.append( true );

0 comments on commit c4b2480

Please sign in to comment.
You can’t perform that action at this time.