@@ -111,7 +111,7 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
111
111
double nodataValue = GDALGetRasterNoDataValue ( inputRasterBand, &nodataSuccess );
112
112
113
113
mInputRasterBands .insert ( it->ref , inputRasterBand );
114
- inputScanLineData.insert ( it->ref , new QgsRasterMatrix ( mNumOutputColumns , 1 , new float [mNumOutputColumns ], nodataValue ) );
114
+ inputScanLineData.insert ( it->ref , new QgsRasterMatrix ( mNumOutputColumns , 1 , new double [mNumOutputColumns ], nodataValue ) );
115
115
}
116
116
117
117
// open output dataset for writing
@@ -183,35 +183,25 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
183
183
qWarning ( " GDALGetGeoTransform failed!" );
184
184
}
185
185
186
+ float * inputScanLine = ( float * ) CPLMalloc ( sizeof ( float ) * mNumOutputColumns );
187
+
186
188
// the function readRasterPart calls GDALRasterIO (and ev. does some conversion if raster transformations are not the same)
187
- readRasterPart ( targetGeoTransform, 0 , i, mNumOutputColumns , 1 , sourceTransformation, sourceRasterBand, bufferIt.value ()->data () );
189
+ readRasterPart ( targetGeoTransform, 0 , i, mNumOutputColumns , 1 , sourceTransformation, sourceRasterBand, inputScanLine );
190
+ for ( int col = 0 ; col < mNumOutputColumns ; ++col )
191
+ {
192
+ bufferIt.value ()->data ()[col] = ( double )inputScanLine[col];
193
+ }
188
194
}
189
195
190
196
if ( calcNode->calculate ( inputScanLineData, resultMatrix ) )
191
197
{
192
198
bool resultIsNumber = resultMatrix.isNumber ();
193
- float * calcData;
194
-
195
- if ( resultIsNumber ) // scalar result. Insert number for every pixel
196
- {
197
- calcData = new float [mNumOutputColumns ];
198
- for ( int j = 0 ; j < mNumOutputColumns ; ++j )
199
- {
200
- calcData[j] = resultMatrix.number ();
201
- }
202
- }
203
- else // result is real matrix
204
- {
205
- calcData = resultMatrix.data ();
206
- }
199
+ float * calcData = new float [mNumOutputColumns ];
207
200
208
- // replace all matrix nodata values with output nodatas
209
201
for ( int j = 0 ; j < mNumOutputColumns ; ++j )
210
202
{
211
- if ( calcData[j] == resultMatrix.nodataValue () )
212
- {
213
- calcData[j] = outputNodataValue;
214
- }
203
+ double result = resultIsNumber ? resultMatrix.number () : resultMatrix.data ()[j];
204
+ calcData[j] = ( calcData[j] == resultMatrix.nodataValue () ? outputNodataValue : ( float ) result );
215
205
}
216
206
217
207
// write scanline to the dataset
0 commit comments