Skip to content

Commit

Permalink
raster no data value made optional
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Apr 12, 2013
1 parent 377b451 commit 19377fb
Show file tree
Hide file tree
Showing 29 changed files with 374 additions and 215 deletions.
8 changes: 5 additions & 3 deletions python/core/raster/qgsrasterblock.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions python/core/raster/qgsrasterdataprovider.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions python/core/raster/qgsrasterinterface.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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 /;

Expand Down
3 changes: 1 addition & 2 deletions python/core/raster/qgsrastertransparency.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
51 changes: 4 additions & 47 deletions src/app/qgsrasterlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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 );
}
}
Expand Down Expand Up @@ -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() )
Expand Down
18 changes: 9 additions & 9 deletions src/core/raster/qgsmultibandcolorrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 )
{
Expand Down
13 changes: 11 additions & 2 deletions src/core/raster/qgspalettedrasterrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand All @@ -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
Expand All @@ -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
{
Expand All @@ -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 );
}
}
Expand Down
Loading

1 comment on commit 19377fb

@dakcarto
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.