19 #include "cpl_string.h"
20 #include <QProgressDialog>
23 #if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
24 #define TO8F(x) (x).toUtf8().constData()
26 #define TO8F(x) QFile::encodeName( x ).constData()
30 : mInputFile( inputFile ), mOutputFile( outputFile ), mOutputFormat( outputFormat ), mCellSizeX( -1 ), mCellSizeY( -1 ),
31 mInputNodataValue( -1 ), mOutputNodataValue( -1 ), mZFactor( 1.0 )
53 if ( inputDataset == NULL )
60 if ( outputDriver == 0 )
65 GDALDatasetH outputDataset =
openOutputFile( inputDataset, outputDriver );
66 if ( outputDataset == NULL )
72 GDALRasterBandH rasterBand = GDALGetRasterBand( inputDataset, 1 );
73 if ( rasterBand == NULL )
75 GDALClose( inputDataset );
76 GDALClose( outputDataset );
81 GDALRasterBandH outputRasterBand = GDALGetRasterBand( outputDataset, 1 );
82 if ( outputRasterBand == NULL )
84 GDALClose( inputDataset );
85 GDALClose( outputDataset );
89 GDALSetRasterNoDataValue( outputRasterBand, -9999 );
94 GDALClose( inputDataset );
95 GDALClose( outputDataset );
100 float* scanLine1 = (
float * ) CPLMalloc(
sizeof(
float ) * xSize );
101 float* scanLine2 = (
float * ) CPLMalloc(
sizeof(
float ) * xSize );
102 float* scanLine3 = (
float * ) CPLMalloc(
sizeof(
float ) * xSize );
104 float* resultLine = (
float * ) CPLMalloc(
sizeof(
float ) * xSize );
108 p->setMaximum( ySize );
112 for (
int i = 0; i < ySize; ++i )
119 if ( p && p->wasCanceled() )
127 for (
int a = 0; a < xSize; ++a )
131 GDALRasterIO( rasterBand, GF_Read, 0, 0, xSize, 1, scanLine2, xSize, 1, GDT_Float32, 0, 0 );
136 CPLFree( scanLine1 );
137 scanLine1 = scanLine2;
138 scanLine2 = scanLine3;
139 scanLine3 = (
float * ) CPLMalloc(
sizeof(
float ) * xSize );
142 if ( i == ySize - 1 )
144 for (
int a = 0; a < xSize; ++a )
151 GDALRasterIO( rasterBand, GF_Read, 0, i + 1, xSize, 1, scanLine3, xSize, 1, GDT_Float32, 0, 0 );
154 for (
int j = 0; j < xSize; ++j )
161 else if ( j == xSize - 1 )
168 resultLine[j] =
processNineCellWindow( &scanLine1[j-1], &scanLine1[j], &scanLine1[j+1], &scanLine2[j-1], &scanLine2[j],
169 &scanLine2[j+1], &scanLine3[j-1], &scanLine3[j], &scanLine3[j+1] );
173 GDALRasterIO( outputRasterBand, GF_Write, 0, i, xSize, 1, resultLine, xSize, 1, GDT_Float32, 0, 0 );
178 p->setValue( ySize );
181 CPLFree( resultLine );
182 CPLFree( scanLine1 );
183 CPLFree( scanLine2 );
184 CPLFree( scanLine3 );
186 GDALClose( inputDataset );
188 if ( p && p->wasCanceled() )
194 GDALClose( outputDataset );
201 GDALDatasetH inputDataset = GDALOpen(
TO8F(
mInputFile ), GA_ReadOnly );
202 if ( inputDataset != NULL )
204 nCellsX = GDALGetRasterXSize( inputDataset );
205 nCellsY = GDALGetRasterYSize( inputDataset );
208 if ( GDALGetRasterCount( inputDataset ) < 1 )
210 GDALClose( inputDataset );
219 char **driverMetadata;
222 GDALDriverH outputDriver = GDALGetDriverByName(
mOutputFormat.toLocal8Bit().data() );
224 if ( outputDriver == NULL )
229 driverMetadata = GDALGetMetadata( outputDriver, NULL );
230 if ( !CSLFetchBoolean( driverMetadata, GDAL_DCAP_CREATE,
false ) )
240 if ( inputDataset == NULL )
245 int xSize = GDALGetRasterXSize( inputDataset );
246 int ySize = GDALGetRasterYSize( inputDataset );;
249 char **papszOptions = NULL;
250 GDALDatasetH outputDataset = GDALCreate( outputDriver,
TO8F(
mOutputFile ), xSize, ySize, 1, GDT_Float32, papszOptions );
251 if ( outputDataset == NULL )
253 return outputDataset;
257 double geotransform[6];
258 if ( GDALGetGeoTransform( inputDataset, geotransform ) != CE_None )
260 GDALClose( outputDataset );
263 GDALSetGeoTransform( outputDataset, geotransform );
277 const char* projection = GDALGetProjectionRef( inputDataset );
278 GDALSetProjection( outputDataset, projection );
280 return outputDataset;