1
1
#include " qgsrastercalcnode.h"
2
+ #include < cfloat>
2
3
3
4
QgsRasterCalcNode::QgsRasterCalcNode (): mLeft( 0 ), mRight( 0 ), mRasterMatrix( 0 ), mNumber( 0 )
4
5
{
@@ -18,11 +19,11 @@ QgsRasterCalcNode::QgsRasterCalcNode( const QString& rasterName ): mType( tRaste
18
19
19
20
QgsRasterCalcNode::~QgsRasterCalcNode ()
20
21
{
21
- if ( mLeft )
22
+ if ( mLeft )
22
23
{
23
24
delete mLeft ;
24
25
}
25
- if ( mRight )
26
+ if ( mRight )
26
27
{
27
28
delete mRight ;
28
29
}
@@ -33,34 +34,34 @@ bool QgsRasterCalcNode::calculate( QMap<QString, QgsRasterMatrix*>& rasterData,
33
34
// if type is raster ref: return a copy of the corresponding matrix
34
35
35
36
// if type is operator, call the proper matrix operations
36
- if ( mType == tRasterRef )
37
+ if ( mType == tRasterRef )
37
38
{
38
39
QMap<QString, QgsRasterMatrix*>::iterator it = rasterData.find ( mRasterName );
39
- if ( it == rasterData.end () )
40
+ if ( it == rasterData.end () )
40
41
{
41
42
return false ;
42
43
}
43
44
44
45
int nEntries = ( *it )->nColumns () * ( *it )->nRows ();
45
46
float * data = new float [nEntries];
46
47
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 () );
48
49
return true ;
49
50
}
50
- else if ( mType == tOperator )
51
+ else if ( mType == tOperator )
51
52
{
52
53
QgsRasterMatrix leftMatrix, rightMatrix;
53
54
QgsRasterMatrix resultMatrix;
54
- if ( !mLeft || !mLeft ->calculate ( rasterData, leftMatrix ) )
55
+ if ( !mLeft || !mLeft ->calculate ( rasterData, leftMatrix ) )
55
56
{
56
57
return false ;
57
58
}
58
- if ( mRight && !mRight ->calculate ( rasterData, rightMatrix ) )
59
+ if ( mRight && !mRight ->calculate ( rasterData, rightMatrix ) )
59
60
{
60
61
return false ;
61
62
}
62
63
63
- switch ( mOperator )
64
+ switch ( mOperator )
64
65
{
65
66
case opPLUS:
66
67
leftMatrix.add ( rightMatrix );
@@ -121,14 +122,14 @@ bool QgsRasterCalcNode::calculate( QMap<QString, QgsRasterMatrix*>& rasterData,
121
122
}
122
123
int newNColumns = leftMatrix.nColumns ();
123
124
int newNRows = leftMatrix.nRows ();
124
- result.setData ( newNColumns, newNRows, leftMatrix.takeData () );
125
+ result.setData ( newNColumns, newNRows, leftMatrix.takeData (), leftMatrix. nodataValue () );
125
126
return true ;
126
127
}
127
- else if ( mType == tNumber )
128
+ else if ( mType == tNumber )
128
129
{
129
130
float * data = new float [1 ];
130
131
data[0 ] = mNumber ;
131
- result.setData ( 1 , 1 , data );
132
+ result.setData ( 1 , 1 , data, -FLT_MAX );
132
133
return true ;
133
134
}
134
135
return false ;
0 commit comments