|
25 | 25 |
|
26 | 26 | #include <qmath.h>
|
27 | 27 |
|
| 28 | +void QgsRasterDataProvider::setUseSrcNoDataValue( int bandNo, bool use ) |
| 29 | +{ |
| 30 | + if ( mUseSrcNoDataValue.size() < bandNo ) |
| 31 | + { |
| 32 | + for ( int i = mUseSrcNoDataValue.size(); i < bandNo; i++ ) |
| 33 | + { |
| 34 | + mUseSrcNoDataValue.append( false ); |
| 35 | + } |
| 36 | + } |
| 37 | + mUseSrcNoDataValue[bandNo-1] = use; |
| 38 | +} |
| 39 | + |
| 40 | +double QgsRasterDataProvider::noDataValue( int bandNo ) const |
| 41 | +{ |
| 42 | + if ( mSrcHasNoDataValue.value( bandNo - 1 ) && mUseSrcNoDataValue.value( bandNo - 1 ) ) |
| 43 | + { |
| 44 | + return mSrcNoDataValue.value( bandNo -1 ); |
| 45 | + } |
| 46 | + return mInternalNoDataValue.value( bandNo -1 ); |
| 47 | +} |
| 48 | + |
28 | 49 | void QgsRasterDataProvider::readBlock( int bandNo, QgsRectangle
|
29 | 50 | const & viewExtent, int width,
|
30 | 51 | int height,
|
@@ -289,7 +310,7 @@ QByteArray QgsRasterDataProvider::noValueBytes( int theBandNo )
|
289 | 310 | QByteArray ba;
|
290 | 311 | ba.resize(( int )size );
|
291 | 312 | char * data = ba.data();
|
292 |
| - double noval = mNoDataValue[theBandNo-1]; |
| 313 | + double noval = noDataValue( theBandNo - 1 ); |
293 | 314 | unsigned char uc;
|
294 | 315 | unsigned short us;
|
295 | 316 | short s;
|
@@ -616,7 +637,6 @@ QgsRasterBandStats QgsRasterDataProvider::bandStatistics( int theBandNo,
|
616 | 637 | int myWidth = myRasterBandStats.width;
|
617 | 638 | int myHeight = myRasterBandStats.height;
|
618 | 639 |
|
619 |
| - double myNoDataValue = noDataValue(); |
620 | 640 | int myDataType = dataType( theBandNo );
|
621 | 641 |
|
622 | 642 | int myXBlockSize = xBlockSize();
|
@@ -669,7 +689,8 @@ QgsRasterBandStats QgsRasterDataProvider::bandStatistics( int theBandNo,
|
669 | 689 | double myValue = readValue( myData, myDataType, myX + ( myY * myBlockWidth ) );
|
670 | 690 | //QgsDebugMsg ( QString ( "%1 %2 value %3" ).arg (myX).arg(myY).arg( myValue ) );
|
671 | 691 |
|
672 |
| - if ( mValidNoDataValue && ( qAbs( myValue - myNoDataValue ) <= TINY_VALUE ) ) |
| 692 | + // TODO: user nodata |
| 693 | + if ( isNoDataValue( theBandNo, myValue ) ) |
673 | 694 | {
|
674 | 695 | continue; // NULL
|
675 | 696 | }
|
@@ -718,7 +739,6 @@ QgsRasterBandStats QgsRasterDataProvider::bandStatistics( int theBandNo,
|
718 | 739 | myRasterBandStats.stdDev = sqrt( mySumOfSquares / ( myRasterBandStats.elementCount - 1 ) );
|
719 | 740 |
|
720 | 741 | QgsDebugMsg( "************ STATS **************" );
|
721 |
| - QgsDebugMsg( QString( "VALID NODATA %1" ).arg( mValidNoDataValue ) ); |
722 | 742 | QgsDebugMsg( QString( "MIN %1" ).arg( myRasterBandStats.minimumValue ) );
|
723 | 743 | QgsDebugMsg( QString( "MAX %1" ).arg( myRasterBandStats.maximumValue ) );
|
724 | 744 | QgsDebugMsg( QString( "RANGE %1" ).arg( myRasterBandStats.range ) );
|
@@ -893,7 +913,6 @@ QgsRasterHistogram QgsRasterDataProvider::histogram( int theBandNo,
|
893 | 913 | QgsRectangle myExtent = myHistogram.extent;
|
894 | 914 | myHistogram.histogramVector.resize( myBinCount );
|
895 | 915 |
|
896 |
| - double myNoDataValue = noDataValue(); |
897 | 916 | int myDataType = dataType( theBandNo );
|
898 | 917 |
|
899 | 918 | int myXBlockSize = xBlockSize();
|
@@ -953,7 +972,8 @@ QgsRasterHistogram QgsRasterDataProvider::histogram( int theBandNo,
|
953 | 972 | double myValue = readValue( myData, myDataType, myX + ( myY * myBlockWidth ) );
|
954 | 973 | //QgsDebugMsg ( QString ( "%1 %2 value %3" ).arg (myX).arg(myY).arg( myValue ) );
|
955 | 974 |
|
956 |
| - if ( mValidNoDataValue && ( qAbs( myValue - myNoDataValue ) <= TINY_VALUE ) ) |
| 975 | + // TODO: user defined nodata values |
| 976 | + if ( isNoDataValue( theBandNo, myValue ) ) |
957 | 977 | {
|
958 | 978 | continue; // NULL
|
959 | 979 | }
|
@@ -1034,7 +1054,7 @@ void QgsRasterDataProvider::cumulativeCut( int theBandNo,
|
1034 | 1054 | double QgsRasterDataProvider::readValue( void *data, int type, int index )
|
1035 | 1055 | {
|
1036 | 1056 | if ( !data )
|
1037 |
| - return mValidNoDataValue ? noDataValue() : 0.0; |
| 1057 | + return std::numeric_limits<double>::quiet_NaN(); |
1038 | 1058 |
|
1039 | 1059 | switch ( type )
|
1040 | 1060 | {
|
@@ -1063,7 +1083,7 @@ double QgsRasterDataProvider::readValue( void *data, int type, int index )
|
1063 | 1083 | QgsLogger::warning( "GDAL data type is not supported" );
|
1064 | 1084 | }
|
1065 | 1085 |
|
1066 |
| - return mValidNoDataValue ? noDataValue() : 0.0; |
| 1086 | + return std::numeric_limits<double>::quiet_NaN(); |
1067 | 1087 | }
|
1068 | 1088 |
|
1069 | 1089 | void QgsRasterDataProvider::setUserNoDataValue( int bandNo, QList<QgsRasterInterface::Range> noData )
|
|
0 commit comments