Skip to content

Commit 19377fb

Browse files
committedApr 12, 2013
raster no data value made optional
1 parent 377b451 commit 19377fb

29 files changed

+374
-215
lines changed
 

‎python/core/raster/qgsrasterblock.sip

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ class QgsRasterBlock
3232
/** For given data type returns wider type and sets no data value */
3333
static QGis::DataType typeWithNoDataValue( QGis::DataType dataType, double *noDataValue );
3434

35+
bool hasNoDataValue() const;
36+
3537
double noDataValue( ) const;
3638

37-
void setNoDataValue( double noDataValue );
39+
//void setNoDataValue( double noDataValue );
3840

39-
static bool isNoDataValue( double value, double noDataValue );
41+
//static bool isNoDataValue( double value, double noDataValue );
4042

41-
bool isNoDataValue( double value ) const;
43+
//bool isNoDataValue( double value ) const;
4244

4345
double value( int row, int column ) const;
4446
double value( size_t index) const;

‎python/core/raster/qgsrasterdataprovider.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
151151
/** Value representing currentno data.
152152
* WARNING: this value returned by this method is not constant. It may change
153153
* for example if user disable use of source no data value. */
154-
virtual double noDataValue( int bandNo ) const;
154+
//virtual double noDataValue( int bandNo ) const;
155155

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

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

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

201201
/**
202202
* \brief Returns the caption error text for the last error in this provider

‎python/core/raster/qgsrasterinterface.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ class QgsRasterInterface
9595
* possibly using wider data type.
9696
* @param bandNo band number
9797
* @return No data value */
98-
virtual double noDataValue( int bandNo ) const;
98+
//virtual double noDataValue( int bandNo ) const;
9999

100100
/** Test if value is nodata for specific band
101101
* @param bandNo band number
102102
* @param value tested value
103103
* @return true if value is nodata */
104-
virtual bool isNoDataValue( int bandNo, double value ) const;
104+
//virtual bool isNoDataValue( int bandNo, double value ) const;
105105

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

‎python/core/raster/qgsrastertransparency.sip

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ class QgsRasterTransparency
5353
/** \brief Return the transparency value for a RGB Pixel */
5454
int alphaValue( double, double, double, int theGlobalTransparency = 255 ) const;
5555

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

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

‎src/app/qgsrasterlayerproperties.cpp

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ void QgsRasterLayerProperties::sync()
676676
// TODO: all bands
677677
if ( mRasterLayer->dataProvider()->srcHasNoDataValue( 1 ) )
678678
{
679-
lblNoData->setText( tr( "No-Data Value: %1" ).arg( mRasterLayer->dataProvider()->noDataValue( 1 ) ) );
679+
lblNoData->setText( tr( "No-Data Value: %1" ).arg( mRasterLayer->dataProvider()->srcNoDataValue( 1 ) ) );
680680
}
681681
else
682682
{
@@ -1080,31 +1080,6 @@ void QgsRasterLayerProperties::on_pbnDefaultValues_clicked()
10801080

10811081
setupTransparencyTable( nBands );
10821082

1083-
// I don't think that noDataValue should be added to transparency list
1084-
#if 0
1085-
if ( nBands == 3 )
1086-
{
1087-
if ( mRasterLayer->isNoDataValueValid() )
1088-
{
1089-
tableTransparency->insertRow( tableTransparency->rowCount() );
1090-
setTransparencyCell( 0, 0, mRasterLayer->noDataValue() );
1091-
setTransparencyCell( 0, 1, mRasterLayer->noDataValue() );
1092-
setTransparencyCell( 0, 2, mRasterLayer->noDataValue() );
1093-
setTransparencyCell( 0, 1, 100 );
1094-
}
1095-
}
1096-
else //1 band
1097-
{
1098-
if ( mRasterLayer->isNoDataValueValid() )
1099-
{
1100-
tableTransparency->insertRow( tableTransparency->rowCount() );
1101-
setTransparencyCell( 0, 0, mRasterLayer->noDataValue() );
1102-
setTransparencyCell( 0, 1, mRasterLayer->noDataValue() );
1103-
setTransparencyCell( 0, 1, 100 );
1104-
}
1105-
}
1106-
#endif
1107-
11081083
tableTransparency->resizeColumnsToContents(); // works only with values
11091084
tableTransparency->resizeRowsToContents();
11101085
}
@@ -1458,20 +1433,18 @@ void QgsRasterLayerProperties::pixelSelected( const QgsPoint& canvasPoint )
14581433

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

1461-
QgsRasterDataProvider * provider = mRasterLayer->dataProvider();
14621436
QList<double> values;
14631437
for ( int i = 0; i < bands.size(); ++i )
14641438
{
14651439
int bandNo = bands.value( i );
14661440
if ( myPixelMap.count( bandNo ) == 1 )
14671441
{
1468-
double value = myPixelMap.value( bandNo ).toDouble();
1469-
QgsDebugMsg( QString( "value = %1" ).arg( value, 0, 'g', 17 ) );
1470-
1471-
if ( provider->isNoDataValue( bandNo, value ) )
1442+
if ( myPixelMap.value( bandNo ).isNull() )
14721443
{
14731444
return; // Don't add nodata, transparent anyway
14741445
}
1446+
double value = myPixelMap.value( bandNo ).toDouble();
1447+
QgsDebugMsg( QString( "value = %1" ).arg( value, 0, 'g', 17 ) );
14751448
values.append( value );
14761449
}
14771450
}
@@ -1691,22 +1664,6 @@ void QgsRasterLayerProperties::on_pbnSaveStyleAs_clicked()
16911664
settings.setValue( "style/lastStyleDir", QFileInfo( outputFileName ).absolutePath() );
16921665
}
16931666

1694-
#if 0
1695-
void QgsRasterLayerProperties::on_btnResetNull_clicked( )
1696-
{
1697-
//If reset NoDataValue is checked do this first, will ignore what ever is in the LineEdit
1698-
mRasterLayer->resetNoDataValue();
1699-
if ( mRasterLayer->isNoDataValueValid() )
1700-
{
1701-
leNoDataValue->setText( QString::number( mRasterLayer->noDataValue(), 'g' ) );
1702-
}
1703-
else
1704-
{
1705-
leNoDataValue->clear();
1706-
}
1707-
}
1708-
#endif
1709-
17101667
void QgsRasterLayerProperties::toggleBuildPyramidsButton()
17111668
{
17121669
if ( lbxPyramidResolutions->selectedItems().empty() )

‎src/core/raster/qgsmultibandcolorrenderer.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,17 @@ QgsRasterBlock* QgsMultiBandColorRenderer::block( int bandNo, QgsRectangle cons
224224
{
225225
if ( fastDraw ) //fast rendering if no transparency, stretching, color inversion, etc.
226226
{
227-
int redVal = ( int )redBlock->value( i );
228-
int greenVal = ( int )greenBlock->value( i );
229-
int blueVal = ( int )blueBlock->value( i );
230-
if ( redBlock->isNoDataValue( redVal ) ||
231-
greenBlock->isNoDataValue( greenVal ) ||
232-
blueBlock->isNoDataValue( blueVal ) )
227+
if ( redBlock->isNoData( i ) ||
228+
greenBlock->isNoData( i ) ||
229+
blueBlock->isNoData( i ) )
233230
{
234231
outputBlock->setColor( i, myDefaultColor );
235232
}
236233
else
237234
{
235+
int redVal = ( int )redBlock->value( i );
236+
int greenVal = ( int )greenBlock->value( i );
237+
int blueVal = ( int )blueBlock->value( i );
238238
outputBlock->setColor( i, qRgba( redVal, greenVal, blueVal, 255 ) );
239239
}
240240
continue;
@@ -247,17 +247,17 @@ QgsRasterBlock* QgsMultiBandColorRenderer::block( int bandNo, QgsRectangle cons
247247
if ( mRedBand > 0 )
248248
{
249249
redVal = redBlock->value( i );
250-
if ( redBlock->isNoDataValue( redVal ) ) isNoData = true;
250+
if ( redBlock->isNoData( i ) ) isNoData = true;
251251
}
252252
if ( !isNoData && mGreenBand > 0 )
253253
{
254254
greenVal = greenBlock->value( i );
255-
if ( greenBlock->isNoDataValue( greenVal ) ) isNoData = true;
255+
if ( greenBlock->isNoData( i ) ) isNoData = true;
256256
}
257257
if ( !isNoData && mBlueBand > 0 )
258258
{
259259
blueVal = ( int )blueBlock->value( i );
260-
if ( blueBlock->isNoDataValue( blueVal ) ) isNoData = true;
260+
if ( blueBlock->isNoData( i ) ) isNoData = true;
261261
}
262262
if ( isNoData )
263263
{

‎src/core/raster/qgspalettedrasterrenderer.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ QgsRasterBlock * QgsPalettedRasterRenderer::block( int bandNo, QgsRectangle con
190190
}
191191

192192
//create copy of color table with nodata values replaced by fully transparent color
193+
// We dont have no data value anymore
194+
#if 0
193195
QVector<QRgb> colorTable( mNColors );
194196
for ( int i = 0; i < mNColors; ++i )
195197
{
@@ -202,6 +204,9 @@ QgsRasterBlock * QgsPalettedRasterRenderer::block( int bandNo, QgsRectangle con
202204
colorTable[i] = mColors[i];
203205
}
204206
}
207+
#endif
208+
209+
QRgb myDefaultColor = NODATA_COLOR;
205210

206211
//use direct data access instead of QgsRasterBlock::setValue
207212
//because of performance
@@ -210,10 +215,14 @@ QgsRasterBlock * QgsPalettedRasterRenderer::block( int bandNo, QgsRectangle con
210215
size_t rasterSize = ( size_t )width * height;
211216
for ( size_t i = 0; i < rasterSize; ++i )
212217
{
218+
if ( inputBlock->isNoData( i ) )
219+
{
220+
outputData[i] = myDefaultColor;
221+
}
213222
int val = ( int ) inputBlock->value( i );
214223
if ( !hasTransparency )
215224
{
216-
outputData[i] = colorTable.value( val );
225+
outputData[i] = mColors[val];
217226
}
218227
else
219228
{
@@ -226,7 +235,7 @@ QgsRasterBlock * QgsPalettedRasterRenderer::block( int bandNo, QgsRectangle con
226235
{
227236
currentOpacity *= alphaBlock->value( i ) / 255.0;
228237
}
229-
QColor currentColor = QColor( colorTable.value( val ) );
238+
QColor currentColor = QColor( mColors[val] );
230239
outputData[i] = qRgba( currentOpacity * currentColor.red(), currentOpacity * currentColor.green(), currentOpacity * currentColor.blue(), currentOpacity * 255 );
231240
}
232241
}

1 commit comments

Comments
 (1)

dakcarto commented on Apr 13, 2013

@dakcarto
Member

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.