Skip to content

Commit efde7ad

Browse files
committedJun 10, 2015
[rastercalc] Remove some redundant private methods
1 parent f28755f commit efde7ad

File tree

2 files changed

+0
-131
lines changed

2 files changed

+0
-131
lines changed
 

‎src/analysis/raster/qgsrastercalculator.cpp

Lines changed: 0 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
#include <cpl_string.h>
2727
#include <gdalwarper.h>
28-
#include <ogr_srs_api.h>
2928

3029
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
3130
#define TO8(x) (x).toUtf8().constData()
@@ -231,115 +230,6 @@ GDALDatasetH QgsRasterCalculator::openOutputFile( GDALDriverH outputDriver )
231230
return outputDataset;
232231
}
233232

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-
343233
void QgsRasterCalculator::outputGeoTransform( double* transform ) const
344234
{
345235
transform[0] = mOutputRectangle.xMinimum();

‎src/analysis/raster/qgsrastercalculator.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,6 @@ class ANALYSIS_EXPORT QgsRasterCalculator
8787
@return the output dataset or NULL in case of error*/
8888
GDALDatasetH openOutputFile( GDALDriverH outputDriver );
8989

90-
/**Reads raster pixels from a dataset/band
91-
@param targetGeotransform transformation parameters of the requested raster array
92-
(not necessarily the same as the transform of the source dataset)
93-
@param xOffset x offset
94-
@param yOffset y offset
95-
@param nCols number of columns
96-
@param nRows number of rows
97-
@param sourceTransform source transformation
98-
@param sourceBand source band
99-
@param rasterBuffer raster buffer
100-
*/
101-
void readRasterPart( double* targetGeotransform,
102-
int xOffset, int yOffset,
103-
int nCols, int nRows,
104-
double* sourceTransform,
105-
GDALRasterBandH sourceBand,
106-
float* rasterBuffer );
107-
108-
/**Compares two geotransformations (six parameter double arrays*/
109-
bool transformationsEqual( double* t1, double* t2 ) const;
110-
11190
/**Sets gdal 6 parameters array from mOutputRectangle, mNumOutputColumns, mNumOutputRows
11291
@param transform double[6] array that receives the GDAL parameters*/
11392
void outputGeoTransform( double* transform ) const;

0 commit comments

Comments
 (0)
Please sign in to comment.