|
25 | 25 |
|
26 | 26 | #include <cpl_string.h>
|
27 | 27 | #include <gdalwarper.h>
|
28 |
| -#include <ogr_srs_api.h> |
29 | 28 |
|
30 | 29 | #if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
|
31 | 30 | #define TO8(x) (x).toUtf8().constData()
|
@@ -231,115 +230,6 @@ GDALDatasetH QgsRasterCalculator::openOutputFile( GDALDriverH outputDriver )
|
231 | 230 | return outputDataset;
|
232 | 231 | }
|
233 | 232 |
|
234 |
| -void QgsRasterCalculator::readRasterPart( double* targetGeotransform, int xOffset, int yOffset, int nCols, int nRows, double* sourceTransform, GDALRasterBandH sourceBand, float* rasterBuffer ) |
235 |
| -{ |
236 |
| - //If dataset transform is the same as the requested transform, do a normal GDAL raster io |
237 |
| - if ( transformationsEqual( targetGeotransform, sourceTransform ) ) |
238 |
| - { |
239 |
| - GDALRasterIO( sourceBand, GF_Read, xOffset, yOffset, nCols, nRows, rasterBuffer, nCols, nRows, GDT_Float32, 0, 0 ); |
240 |
| - return; |
241 |
| - } |
242 |
| - |
243 |
| - int sourceBandXSize = GDALGetRasterBandXSize( sourceBand ); |
244 |
| - int sourceBandYSize = GDALGetRasterBandYSize( sourceBand ); |
245 |
| - |
246 |
| - //pixel calculation needed because of different raster position / resolution |
247 |
| - int nodataSuccess; |
248 |
| - double nodataValue = GDALGetRasterNoDataValue( sourceBand, &nodataSuccess ); |
249 |
| - QgsRectangle targetRect( targetGeotransform[0] + targetGeotransform[1] * xOffset, targetGeotransform[3] + yOffset * targetGeotransform[5] + nRows * targetGeotransform[5] |
250 |
| - , targetGeotransform[0] + targetGeotransform[1] * xOffset + targetGeotransform[1] * nCols, targetGeotransform[3] + yOffset * targetGeotransform[5] ); |
251 |
| - QgsRectangle sourceRect( sourceTransform[0], sourceTransform[3] + GDALGetRasterBandYSize( sourceBand ) * sourceTransform[5], |
252 |
| - sourceTransform[0] + GDALGetRasterBandXSize( sourceBand )* sourceTransform[1], sourceTransform[3] ); |
253 |
| - QgsRectangle intersection = targetRect.intersect( &sourceRect ); |
254 |
| - |
255 |
| - //no intersection, fill all the pixels with nodata values |
256 |
| - if ( intersection.isEmpty() ) |
257 |
| - { |
258 |
| - int nPixels = nCols * nRows; |
259 |
| - for ( int i = 0; i < nPixels; ++i ) |
260 |
| - { |
261 |
| - rasterBuffer[i] = nodataValue; |
262 |
| - } |
263 |
| - return; |
264 |
| - } |
265 |
| - |
266 |
| - //do raster io in source resolution |
267 |
| - int sourcePixelOffsetXMin = floor(( intersection.xMinimum() - sourceTransform[0] ) / sourceTransform[1] ); |
268 |
| - int sourcePixelOffsetXMax = ceil(( intersection.xMaximum() - sourceTransform[0] ) / sourceTransform[1] ); |
269 |
| - if ( sourcePixelOffsetXMax > sourceBandXSize ) |
270 |
| - { |
271 |
| - sourcePixelOffsetXMax = sourceBandXSize; |
272 |
| - } |
273 |
| - int nSourcePixelsX = sourcePixelOffsetXMax - sourcePixelOffsetXMin; |
274 |
| - |
275 |
| - int sourcePixelOffsetYMax = floor(( intersection.yMaximum() - sourceTransform[3] ) / sourceTransform[5] ); |
276 |
| - int sourcePixelOffsetYMin = ceil(( intersection.yMinimum() - sourceTransform[3] ) / sourceTransform[5] ); |
277 |
| - if ( sourcePixelOffsetYMin > sourceBandYSize ) |
278 |
| - { |
279 |
| - sourcePixelOffsetYMin = sourceBandYSize; |
280 |
| - } |
281 |
| - int nSourcePixelsY = sourcePixelOffsetYMin - sourcePixelOffsetYMax; |
282 |
| - float* sourceRaster = ( float * ) CPLMalloc( sizeof( float ) * nSourcePixelsX * nSourcePixelsY ); |
283 |
| - double sourceRasterXMin = sourceRect.xMinimum() + sourcePixelOffsetXMin * sourceTransform[1]; |
284 |
| - double sourceRasterYMax = sourceRect.yMaximum() + sourcePixelOffsetYMax * sourceTransform[5]; |
285 |
| - if ( GDALRasterIO( sourceBand, GF_Read, sourcePixelOffsetXMin, sourcePixelOffsetYMax, nSourcePixelsX, nSourcePixelsY, |
286 |
| - sourceRaster, nSourcePixelsX, nSourcePixelsY, GDT_Float32, 0, 0 ) != CE_None ) |
287 |
| - { |
288 |
| - //IO error, fill array with nodata values |
289 |
| - CPLFree( sourceRaster ); |
290 |
| - int npixels = nRows * nCols; |
291 |
| - for ( int i = 0; i < npixels; ++i ) |
292 |
| - { |
293 |
| - rasterBuffer[i] = nodataValue; |
294 |
| - } |
295 |
| - return; |
296 |
| - } |
297 |
| - |
298 |
| - |
299 |
| - double targetPixelX; |
300 |
| - double targetPixelXMin = targetGeotransform[0] + targetGeotransform[1] * xOffset + targetGeotransform[1] / 2.0; |
301 |
| - double targetPixelY = targetGeotransform[3] + targetGeotransform[5] * yOffset + targetGeotransform[5] / 2.0; //coordinates of current target pixel |
302 |
| - int sourceIndexX, sourceIndexY; //current raster index in source pixels |
303 |
| - double sx, sy; |
304 |
| - for ( int i = 0; i < nRows; ++i ) |
305 |
| - { |
306 |
| - targetPixelX = targetPixelXMin; |
307 |
| - for ( int j = 0; j < nCols; ++j ) |
308 |
| - { |
309 |
| - sx = ( targetPixelX - sourceRasterXMin ) / sourceTransform[1]; |
310 |
| - sourceIndexX = sx > 0 ? sx : floor( sx ); |
311 |
| - sy = ( targetPixelY - sourceRasterYMax ) / sourceTransform[5]; |
312 |
| - sourceIndexY = sy > 0 ? sy : floor( sy ); |
313 |
| - if ( sourceIndexX >= 0 && sourceIndexX < nSourcePixelsX |
314 |
| - && sourceIndexY >= 0 && sourceIndexY < nSourcePixelsY ) |
315 |
| - { |
316 |
| - rasterBuffer[j + i*nRows] = sourceRaster[ sourceIndexX + nSourcePixelsX * sourceIndexY ]; |
317 |
| - } |
318 |
| - else |
319 |
| - { |
320 |
| - rasterBuffer[j + i*j] = nodataValue; |
321 |
| - } |
322 |
| - targetPixelX += targetGeotransform[1]; |
323 |
| - } |
324 |
| - targetPixelY += targetGeotransform[5]; |
325 |
| - } |
326 |
| - |
327 |
| - CPLFree( sourceRaster ); |
328 |
| - return; |
329 |
| -} |
330 |
| - |
331 |
| -bool QgsRasterCalculator::transformationsEqual( double* t1, double* t2 ) const |
332 |
| -{ |
333 |
| - for ( int i = 0; i < 6; ++i ) |
334 |
| - { |
335 |
| - if ( !qgsDoubleNear( t1[i], t2[i], 0.00001 ) ) |
336 |
| - { |
337 |
| - return false; |
338 |
| - } |
339 |
| - } |
340 |
| - return true; |
341 |
| -} |
342 |
| - |
343 | 233 | void QgsRasterCalculator::outputGeoTransform( double* transform ) const
|
344 | 234 | {
|
345 | 235 | transform[0] = mOutputRectangle.xMinimum();
|
|
0 commit comments