Skip to content
Permalink
Browse files

raster no data value made optional

  • Loading branch information
blazek committed Apr 12, 2013
1 parent 377b451 commit 19377fbb8dc11c7c4514c0bc3acdb01c0c1be4a9
@@ -32,13 +32,15 @@ class QgsRasterBlock
/** For given data type returns wider type and sets no data value */
static QGis::DataType typeWithNoDataValue( QGis::DataType dataType, double *noDataValue );

bool hasNoDataValue() const;

double noDataValue( ) const;

void setNoDataValue( double noDataValue );
//void setNoDataValue( double noDataValue );

static bool isNoDataValue( double value, double noDataValue );
//static bool isNoDataValue( double value, double noDataValue );

bool isNoDataValue( double value ) const;
//bool isNoDataValue( double value ) const;

double value( int row, int column ) const;
double value( size_t index) const;
@@ -151,7 +151,7 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
/** Value representing currentno data.
* WARNING: this value returned by this method is not constant. It may change
* for example if user disable use of source no data value. */
virtual double noDataValue( int bandNo ) const;
//virtual double noDataValue( int bandNo ) const;

/** Value representing no data value. */
virtual double srcNoDataValue( int bandNo ) const;
@@ -196,7 +196,7 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface

virtual QgsRasterIdentifyResult identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );

QMap<QString, QString> identify( const QgsPoint & thePoint, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
//QMap<QString, QString> identify( const QgsPoint & thePoint, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );

/**
* \brief Returns the caption error text for the last error in this provider
@@ -95,13 +95,13 @@ class QgsRasterInterface
* possibly using wider data type.
* @param bandNo band number
* @return No data value */
virtual double noDataValue( int bandNo ) const;
//virtual double noDataValue( int bandNo ) const;

/** Test if value is nodata for specific band
* @param bandNo band number
* @param value tested value
* @return true if value is nodata */
virtual bool isNoDataValue( int bandNo, double value ) const;
//virtual bool isNoDataValue( int bandNo, double value ) const;

virtual QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height ) = 0 / Factory /;

@@ -53,8 +53,7 @@ class QgsRasterTransparency
/** \brief Return the transparency value for a RGB Pixel */
int alphaValue( double, double, double, int theGlobalTransparency = 255 ) const;

/**True if there are no entries in the pixel lists except the nodata value*/
bool isEmpty( double nodataValue ) const;
bool isEmpty( ) const;

void writeXML( QDomDocument& doc, QDomElement& parentElem ) const;

@@ -676,7 +676,7 @@ void QgsRasterLayerProperties::sync()
// TODO: all bands
if ( mRasterLayer->dataProvider()->srcHasNoDataValue( 1 ) )
{
lblNoData->setText( tr( "No-Data Value: %1" ).arg( mRasterLayer->dataProvider()->noDataValue( 1 ) ) );
lblNoData->setText( tr( "No-Data Value: %1" ).arg( mRasterLayer->dataProvider()->srcNoDataValue( 1 ) ) );
}
else
{
@@ -1080,31 +1080,6 @@ void QgsRasterLayerProperties::on_pbnDefaultValues_clicked()

setupTransparencyTable( nBands );

// I don't think that noDataValue should be added to transparency list
#if 0
if ( nBands == 3 )
{
if ( mRasterLayer->isNoDataValueValid() )
{
tableTransparency->insertRow( tableTransparency->rowCount() );
setTransparencyCell( 0, 0, mRasterLayer->noDataValue() );
setTransparencyCell( 0, 1, mRasterLayer->noDataValue() );
setTransparencyCell( 0, 2, mRasterLayer->noDataValue() );
setTransparencyCell( 0, 1, 100 );
}
}
else //1 band
{
if ( mRasterLayer->isNoDataValueValid() )
{
tableTransparency->insertRow( tableTransparency->rowCount() );
setTransparencyCell( 0, 0, mRasterLayer->noDataValue() );
setTransparencyCell( 0, 1, mRasterLayer->noDataValue() );
setTransparencyCell( 0, 1, 100 );
}
}
#endif

tableTransparency->resizeColumnsToContents(); // works only with values
tableTransparency->resizeRowsToContents();
}
@@ -1458,20 +1433,18 @@ void QgsRasterLayerProperties::pixelSelected( const QgsPoint& canvasPoint )

QList<int> bands = renderer->usesBands();

QgsRasterDataProvider * provider = mRasterLayer->dataProvider();
QList<double> values;
for ( int i = 0; i < bands.size(); ++i )
{
int bandNo = bands.value( i );
if ( myPixelMap.count( bandNo ) == 1 )
{
double value = myPixelMap.value( bandNo ).toDouble();
QgsDebugMsg( QString( "value = %1" ).arg( value, 0, 'g', 17 ) );

if ( provider->isNoDataValue( bandNo, value ) )
if ( myPixelMap.value( bandNo ).isNull() )
{
return; // Don't add nodata, transparent anyway
}
double value = myPixelMap.value( bandNo ).toDouble();
QgsDebugMsg( QString( "value = %1" ).arg( value, 0, 'g', 17 ) );
values.append( value );
}
}
@@ -1691,22 +1664,6 @@ void QgsRasterLayerProperties::on_pbnSaveStyleAs_clicked()
settings.setValue( "style/lastStyleDir", QFileInfo( outputFileName ).absolutePath() );
}

#if 0
void QgsRasterLayerProperties::on_btnResetNull_clicked( )
{
//If reset NoDataValue is checked do this first, will ignore what ever is in the LineEdit
mRasterLayer->resetNoDataValue();
if ( mRasterLayer->isNoDataValueValid() )
{
leNoDataValue->setText( QString::number( mRasterLayer->noDataValue(), 'g' ) );
}
else
{
leNoDataValue->clear();
}
}
#endif

void QgsRasterLayerProperties::toggleBuildPyramidsButton()
{
if ( lbxPyramidResolutions->selectedItems().empty() )
@@ -224,17 +224,17 @@ QgsRasterBlock* QgsMultiBandColorRenderer::block( int bandNo, QgsRectangle cons
{
if ( fastDraw ) //fast rendering if no transparency, stretching, color inversion, etc.
{
int redVal = ( int )redBlock->value( i );
int greenVal = ( int )greenBlock->value( i );
int blueVal = ( int )blueBlock->value( i );
if ( redBlock->isNoDataValue( redVal ) ||
greenBlock->isNoDataValue( greenVal ) ||
blueBlock->isNoDataValue( blueVal ) )
if ( redBlock->isNoData( i ) ||
greenBlock->isNoData( i ) ||
blueBlock->isNoData( i ) )
{
outputBlock->setColor( i, myDefaultColor );
}
else
{
int redVal = ( int )redBlock->value( i );
int greenVal = ( int )greenBlock->value( i );
int blueVal = ( int )blueBlock->value( i );
outputBlock->setColor( i, qRgba( redVal, greenVal, blueVal, 255 ) );
}
continue;
@@ -247,17 +247,17 @@ QgsRasterBlock* QgsMultiBandColorRenderer::block( int bandNo, QgsRectangle cons
if ( mRedBand > 0 )
{
redVal = redBlock->value( i );
if ( redBlock->isNoDataValue( redVal ) ) isNoData = true;
if ( redBlock->isNoData( i ) ) isNoData = true;
}
if ( !isNoData && mGreenBand > 0 )
{
greenVal = greenBlock->value( i );
if ( greenBlock->isNoDataValue( greenVal ) ) isNoData = true;
if ( greenBlock->isNoData( i ) ) isNoData = true;
}
if ( !isNoData && mBlueBand > 0 )
{
blueVal = ( int )blueBlock->value( i );
if ( blueBlock->isNoDataValue( blueVal ) ) isNoData = true;
if ( blueBlock->isNoData( i ) ) isNoData = true;
}
if ( isNoData )
{
@@ -190,6 +190,8 @@ QgsRasterBlock * QgsPalettedRasterRenderer::block( int bandNo, QgsRectangle con
}

//create copy of color table with nodata values replaced by fully transparent color
// We dont have no data value anymore
#if 0
QVector<QRgb> colorTable( mNColors );
for ( int i = 0; i < mNColors; ++i )
{
@@ -202,6 +204,9 @@ QgsRasterBlock * QgsPalettedRasterRenderer::block( int bandNo, QgsRectangle con
colorTable[i] = mColors[i];
}
}
#endif

QRgb myDefaultColor = NODATA_COLOR;

//use direct data access instead of QgsRasterBlock::setValue
//because of performance
@@ -210,10 +215,14 @@ QgsRasterBlock * QgsPalettedRasterRenderer::block( int bandNo, QgsRectangle con
size_t rasterSize = ( size_t )width * height;
for ( size_t i = 0; i < rasterSize; ++i )
{
if ( inputBlock->isNoData( i ) )
{
outputData[i] = myDefaultColor;
}
int val = ( int ) inputBlock->value( i );
if ( !hasTransparency )
{
outputData[i] = colorTable.value( val );
outputData[i] = mColors[val];
}
else
{
@@ -226,7 +235,7 @@ QgsRasterBlock * QgsPalettedRasterRenderer::block( int bandNo, QgsRectangle con
{
currentOpacity *= alphaBlock->value( i ) / 255.0;
}
QColor currentColor = QColor( colorTable.value( val ) );
QColor currentColor = QColor( mColors[val] );
outputData[i] = qRgba( currentOpacity * currentColor.red(), currentOpacity * currentColor.green(), currentOpacity * currentColor.blue(), currentOpacity * 255 );
}
}

1 comment on commit 19377fb

@dakcarto

This comment has been minimized.

Copy link
Member

@dakcarto dakcarto commented on 19377fb Apr 13, 2013

Hi Radim,

After this commit (I think), I getting the following build error on Windows (using NMake with jom.exe from Qt Creator, using the VS 2008 compiler):

Q:\Quantum-GIS\src\core\raster\qgsrasterblock.cpp(317) : error C2059: syntax error : 'bad suffix on number'
Q:\Quantum-GIS\src\core\raster\qgsrasterblock.cpp(317) : error C2146: syntax error : missing ';' before identifier 'b10000000'
Q:\Quantum-GIS\src\core\raster\qgsrasterblock.cpp(317) : error C2065: 'b10000000' : undeclared identifier
Q:\Quantum-GIS\src\core\raster\qgsrasterblock.cpp(394) : error C2059: syntax error : 'bad suffix on number'
Q:\Quantum-GIS\src\core\raster\qgsrasterblock.cpp(394) : error C2146: syntax error : missing ';' before identifier 'b10000000'
Q:\Quantum-GIS\src\core\raster\qgsrasterblock.cpp(394) : error C2065: 'b10000000' : undeclared identifier
Q:\Quantum-GIS\src\core\raster\qgsrasterblock.cpp(427) : error C2059: syntax error : 'bad suffix on number'
Q:\Quantum-GIS\src\core\raster\qgsrasterblock.cpp(427) : error C2146: syntax error : missing ')' before identifier 'b11111111'
Q:\Quantum-GIS\src\core\raster\qgsrasterblock.cpp(427) : error C2660: 'memset' : function does not take 2 arguments
Q:\Quantum-GIS\src\core\raster\qgsrasterblock.cpp(427) : error C2059: syntax error : ')'

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