11#include " qgsrastercalcnode.h"
2+ #include < cfloat>
23
34QgsRasterCalcNode::QgsRasterCalcNode (): mLeft( 0 ), mRight( 0 ), mRasterMatrix( 0 ), mNumber( 0 )
45{
@@ -18,11 +19,11 @@ QgsRasterCalcNode::QgsRasterCalcNode( const QString& rasterName ): mType( tRaste
1819
1920QgsRasterCalcNode::~QgsRasterCalcNode ()
2021{
21- if ( mLeft )
22+ if ( mLeft )
2223 {
2324 delete mLeft ;
2425 }
25- if ( mRight )
26+ if ( mRight )
2627 {
2728 delete mRight ;
2829 }
@@ -33,34 +34,34 @@ bool QgsRasterCalcNode::calculate( QMap<QString, QgsRasterMatrix*>& rasterData,
3334 // if type is raster ref: return a copy of the corresponding matrix
3435
3536 // if type is operator, call the proper matrix operations
36- if ( mType == tRasterRef )
37+ if ( mType == tRasterRef )
3738 {
3839 QMap<QString, QgsRasterMatrix*>::iterator it = rasterData.find ( mRasterName );
39- if ( it == rasterData.end () )
40+ if ( it == rasterData.end () )
4041 {
4142 return false ;
4243 }
4344
4445 int nEntries = ( *it )->nColumns () * ( *it )->nRows ();
4546 float * data = new float [nEntries];
4647 memcpy ( data, ( *it )->data (), nEntries * sizeof ( float ) );
47- result.setData (( *it )->nColumns (), ( *it )->nRows (), data );
48+ result.setData (( *it )->nColumns (), ( *it )->nRows (), data, ( *it )-> nodataValue () );
4849 return true ;
4950 }
50- else if ( mType == tOperator )
51+ else if ( mType == tOperator )
5152 {
5253 QgsRasterMatrix leftMatrix, rightMatrix;
5354 QgsRasterMatrix resultMatrix;
54- if ( !mLeft || !mLeft ->calculate ( rasterData, leftMatrix ) )
55+ if ( !mLeft || !mLeft ->calculate ( rasterData, leftMatrix ) )
5556 {
5657 return false ;
5758 }
58- if ( mRight && !mRight ->calculate ( rasterData, rightMatrix ) )
59+ if ( mRight && !mRight ->calculate ( rasterData, rightMatrix ) )
5960 {
6061 return false ;
6162 }
6263
63- switch ( mOperator )
64+ switch ( mOperator )
6465 {
6566 case opPLUS:
6667 leftMatrix.add ( rightMatrix );
@@ -121,14 +122,14 @@ bool QgsRasterCalcNode::calculate( QMap<QString, QgsRasterMatrix*>& rasterData,
121122 }
122123 int newNColumns = leftMatrix.nColumns ();
123124 int newNRows = leftMatrix.nRows ();
124- result.setData ( newNColumns, newNRows, leftMatrix.takeData () );
125+ result.setData ( newNColumns, newNRows, leftMatrix.takeData (), leftMatrix. nodataValue () );
125126 return true ;
126127 }
127- else if ( mType == tNumber )
128+ else if ( mType == tNumber )
128129 {
129130 float * data = new float [1 ];
130131 data[0 ] = mNumber ;
131- result.setData ( 1 , 1 , data );
132+ result.setData ( 1 , 1 , data, -FLT_MAX );
132133 return true ;
133134 }
134135 return false ;
0 commit comments