@@ -294,32 +294,32 @@ void QgsGeorefPluginGui::generateGDALScript()
294
294
if ( !checkReadyGeoref () )
295
295
return ;
296
296
297
- if ( QgsGeorefTransform::Linear != mTransformParam
298
- && QgsGeorefTransform::Helmert != mTransformParam )
297
+ switch (mTransformParam )
299
298
{
300
- // CAVEAT: gdalwarpCommand*() rely on some member variables being set
301
- // by gdal_translateCommand(), so this method must be called before
302
- // gdalwarpCommand*()!
303
- QString translateCommand = gdal_translateCommand ();
304
- QString gdalwarpCommand;
305
- QString resamplingStr = convertResamplingEnumToString ( mResamplingMethod );
306
- if ( QgsGeorefTransform::ThinPlateSpline == mTransformParam )
307
- {
308
- gdalwarpCommand = gdalwarpCommandTPS ( resamplingStr, mCompressionMethod , mUseZeroForTrans ,
309
- mUserResX , mUserResY );
310
- }
311
- else
299
+ case QgsGeorefTransform::PolynomialOrder1:
300
+ case QgsGeorefTransform::PolynomialOrder2:
301
+ case QgsGeorefTransform::PolynomialOrder3:
302
+ case QgsGeorefTransform::ThinPlateSpline:
312
303
{
313
- gdalwarpCommand = gdalwarpCommandGCP ( resamplingStr, mCompressionMethod , mUseZeroForTrans ,
314
- polynomeOrder ( mTransformParam ),
315
- mUserResX , mUserResY );
304
+ // CAVEAT: generateGDALwarpCommand() relies on some member variables being set
305
+ // by generateGDALtranslateCommand(), so this method must be called before
306
+ // gdalwarpCommand*()!
307
+ QString translateCommand = generateGDALtranslateCommand ( false );
308
+ QString gdalwarpCommand;
309
+ QString resamplingStr = convertResamplingEnumToString ( mResamplingMethod );
310
+
311
+ int order = polynomialOrder ( mTransformParam );
312
+ if (order != 0 )
313
+ {
314
+ gdalwarpCommand = generateGDALwarpCommand ( resamplingStr, mCompressionMethod , mUseZeroForTrans , order,
315
+ mUserResX , mUserResY );
316
+ showGDALScript ( 2 , translateCommand.toAscii ().data (), gdalwarpCommand.toAscii ().data () );
317
+ break ;
318
+ }
316
319
}
317
- showGDALScript ( 2 , translateCommand.toAscii ().data (), gdalwarpCommand.toAscii ().data () );
318
- }
319
- else
320
- {
321
- QMessageBox::information ( this , tr ( " Info" ), tr ( " GDAL scripting is not supported for %1 transformation" )
322
- .arg ( convertTransformEnumToString ( mTransformParam ) ) );
320
+ default :
321
+ QMessageBox::information ( this , tr ( " Info" ), tr ( " GDAL scripting is not supported for %1 transformation" )
322
+ .arg ( convertTransformEnumToString ( mTransformParam ) ) );
323
323
}
324
324
}
325
325
@@ -1163,7 +1163,7 @@ void QgsGeorefPluginGui::showGDALScript( int argNum... )
1163
1163
}
1164
1164
}
1165
1165
1166
- QString QgsGeorefPluginGui::gdal_translateCommand ( bool generateTFW )
1166
+ QString QgsGeorefPluginGui::generateGDALtranslateCommand ( bool generateTFW )
1167
1167
{
1168
1168
QStringList gdalCommand;
1169
1169
gdalCommand << " gdal_translate" << " -of GTiff" ;
@@ -1186,30 +1186,23 @@ QString QgsGeorefPluginGui::gdal_translateCommand( bool generateTFW )
1186
1186
return gdalCommand.join ( " " );
1187
1187
}
1188
1188
1189
- QString QgsGeorefPluginGui::gdalwarpCommandGCP ( QString resampling, QString compress,
1190
- bool useZeroForTrans, int order,
1191
- double targetResX, double targetResY )
1189
+ QString QgsGeorefPluginGui::generateGDALwarpCommand ( QString resampling, QString compress,
1190
+ bool useZeroForTrans, int order, double targetResX, double targetResY )
1192
1191
{
1193
1192
QStringList gdalCommand;
1194
- gdalCommand << " gdalwarp" << " -r" << resampling << " -order" << QString::number ( order )
1195
- << " -co COMPRESS=" + compress << ( useZeroForTrans ? " -dstalpha" : " " );
1196
-
1197
- if ( targetResX != 0.0 && targetResY != 0.0 )
1193
+ gdalCommand << " gdalwarp" << " -r" << resampling;
1194
+
1195
+ if (order > 0 && order <= 3 )
1198
1196
{
1199
- gdalCommand << " -tr" << QString::number ( targetResX, ' f' ) << QString::number ( targetResY, ' f' );
1197
+ // Let gdalwarp use polynomial warp with the given degree
1198
+ gdalCommand << " -order" << QString::number ( order );
1200
1199
}
1201
-
1202
- gdalCommand << QString (" \" %1\" " ).arg (mTranslatedRasterFileName ) << QString (" \" %1\" " ).arg (mModifiedRasterFileName );
1203
-
1204
- return gdalCommand.join ( " " );
1205
- }
1206
-
1207
- QString QgsGeorefPluginGui::gdalwarpCommandTPS ( QString resampling, QString compress, bool useZeroForTrans,
1208
- double targetResX, double targetResY )
1209
- {
1210
- QStringList gdalCommand;
1211
- gdalCommand << " gdalwarp" << " -r" << resampling << " -tps"
1212
- << " -co COMPRESS=" + compress << ( useZeroForTrans ? " -dstalpha" : " " );
1200
+ else
1201
+ {
1202
+ // Otherwise, use thin plate spline interpolation
1203
+ gdalCommand << " -tps" ;
1204
+ }
1205
+ gdalCommand<< " -co COMPRESS=" + compress << ( useZeroForTrans ? " -dstalpha" : " " );
1213
1206
1214
1207
if ( targetResX != 0.0 && targetResY != 0.0 )
1215
1208
{
@@ -1387,7 +1380,7 @@ QString QgsGeorefPluginGui::convertResamplingEnumToString( QgsImageWarper::Resam
1387
1380
return " " ;
1388
1381
}
1389
1382
1390
- int QgsGeorefPluginGui::polynomeOrder ( QgsGeorefTransform::TransformParametrisation transform )
1383
+ int QgsGeorefPluginGui::polynomialOrder ( QgsGeorefTransform::TransformParametrisation transform )
1391
1384
{
1392
1385
switch ( transform )
1393
1386
{
@@ -1397,8 +1390,11 @@ int QgsGeorefPluginGui::polynomeOrder( QgsGeorefTransform::TransformParametrisat
1397
1390
return 2 ;
1398
1391
case QgsGeorefTransform::PolynomialOrder3:
1399
1392
return 3 ;
1400
- default :
1393
+ case QgsGeorefTransform::ThinPlateSpline :
1401
1394
return -1 ;
1395
+
1396
+ default :
1397
+ return 0 ;
1402
1398
}
1403
1399
}
1404
1400
0 commit comments