Skip to content

Commit

Permalink
No data values fix. Very small numbers were used instead of very big …
Browse files Browse the repository at this point in the history
…numbers for FCELL and DCELL - 0 values were rendered as null. Better looking values used because are shown in GUI
  • Loading branch information
blazek authored and alexbruy committed Dec 21, 2011
1 parent 194c44e commit 90f42b4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/app/qgsrasterlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
leMinimumScale->setValidator( new QDoubleValidator( 0, std::numeric_limits<float>::max(), 1000, this ) );
leMaximumScale->setText( QString::number( lyr->maximumScale(), 'f' ) );
leMaximumScale->setValidator( new QDoubleValidator( 0, std::numeric_limits<float>::max(), 1000, this ) );
leNoDataValue->setValidator( new QDoubleValidator( -std::numeric_limits<float>::max(), std::numeric_limits<float>::max(), 1000, this ) );
leNoDataValue->setValidator( new QDoubleValidator( -std::numeric_limits<double>::max(), std::numeric_limits<double>::max(), 1000, this ) );

leRedMin->setValidator( new QDoubleValidator( this ) );
leRedMax->setValidator( new QDoubleValidator( this ) );
Expand Down Expand Up @@ -384,7 +384,7 @@ void QgsRasterLayerProperties::populateTransparencyTable()
for ( int myListRunner = 0; myListRunner < myTransparentSingleValuePixelList.count(); myListRunner++ )
{
tableTransparency->insertRow( myListRunner );
QTableWidgetItem* myGrayItem = new QTableWidgetItem( myNumberFormatter.sprintf( "%.2f", myTransparentSingleValuePixelList[myListRunner].pixelValue ) );
QTableWidgetItem* myGrayItem = new QTableWidgetItem( myNumberFormatter.sprintf( "%g", myTransparentSingleValuePixelList[myListRunner].pixelValue ) );
QTableWidgetItem* myPercentTransparentItem = new QTableWidgetItem( myNumberFormatter.sprintf( "%.2f", myTransparentSingleValuePixelList[myListRunner].percentTransparent ) );

tableTransparency->setItem( myListRunner, 0, myGrayItem );
Expand Down Expand Up @@ -784,7 +784,7 @@ void QgsRasterLayerProperties::sync()
//add current NoDataValue to NoDataValue line edit
if ( mRasterLayer->isNoDataValueValid() )
{
leNoDataValue->insert( QString::number( mRasterLayer->noDataValue(), 'f' ) );
leNoDataValue->insert( QString::number( mRasterLayer->noDataValue(), 'g' ) );
}
else
{
Expand Down Expand Up @@ -3047,7 +3047,7 @@ void QgsRasterLayerProperties::on_btnResetNull_clicked( )
mRasterLayer->resetNoDataValue();
if ( mRasterLayer->isNoDataValueValid() )
{
leNoDataValue->setText( QString::number( mRasterLayer->noDataValue(), 'f' ) );
leNoDataValue->setText( QString::number( mRasterLayer->noDataValue(), 'g' ) );
}
else
{
Expand Down
7 changes: 4 additions & 3 deletions src/providers/grass/qgis.d.rast.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,20 @@ static int cell_draw( char *name,
}
if ( G_is_null_value( ptr, data_type ) )
{
// see comments in QgsGrassRasterProvider::noDataValue()
if ( data_type == CELL_TYPE )
{
int nul = -2147483647;
int nul = -2000000000;
fwrite( &nul , 4, 1, fo );
}
else if ( data_type == DCELL_TYPE )
{
double nul = 2.2250738585072014e-308;
double nul = -1e+300;
fwrite( &nul , 8, 1, fo );
}
else if ( data_type == FCELL_TYPE )
{
double nul = 1.17549435e-38F;
double nul = -1e+30;
fwrite( &nul , 4, 1, fo );
}
}
Expand Down
16 changes: 13 additions & 3 deletions src/providers/grass/qgsgrassrasterprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,27 @@ void QgsGrassRasterProvider::readBlock( int bandNo, QgsRectangle const & viewEx
double QgsGrassRasterProvider::noDataValue() const
{
double nul;
// TODO: avoid showing these strange numbers in GUI
// TODO: don't save no data values in project file, add a flag if value was defined by user
if ( mGrassDataType == CELL_TYPE )
{
nul = -2147483647;
//limit: -2147483647;
nul = -2000000000;
}
else if ( mGrassDataType == DCELL_TYPE )
{
nul = 2.2250738585072014e-308;
// Don't use numeric limits, raster layer is using
// qAbs( myValue - mNoDataValue ) <= TINY_VALUE
// if the mNoDataValue would be a limit, the subtraction could overflow.
// No data value is shown in GUI, use some nice number.
// Choose values with small representation error.
// limit: 1.7976931348623157e+308
nul = -1e+300;
}
else if ( mGrassDataType == FCELL_TYPE )
{
nul = 1.17549435e-38F;
// limit: 3.40282347e+38
nul = -1e+30;
}
QgsDebugMsg( QString( "noDataValue = %1" ).arg( nul ) );
return nul;
Expand Down

0 comments on commit 90f42b4

Please sign in to comment.