Skip to content

Commit a36008f

Browse files
author
mmassing
committed
Disable world-file in command line generator. Remove some code duplication.
git-svn-id: http://svn.osgeo.org/qgis/trunk@13297 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 3a4b119 commit a36008f

File tree

2 files changed

+49
-57
lines changed

2 files changed

+49
-57
lines changed

src/plugins/georeferencer/qgsgeorefplugingui.cpp

+42-46
Original file line numberDiff line numberDiff line change
@@ -294,32 +294,32 @@ void QgsGeorefPluginGui::generateGDALScript()
294294
if ( !checkReadyGeoref() )
295295
return;
296296

297-
if ( QgsGeorefTransform::Linear != mTransformParam
298-
&& QgsGeorefTransform::Helmert != mTransformParam )
297+
switch (mTransformParam)
299298
{
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:
312303
{
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+
}
316319
}
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 ) ) );
323323
}
324324
}
325325

@@ -1163,7 +1163,7 @@ void QgsGeorefPluginGui::showGDALScript( int argNum... )
11631163
}
11641164
}
11651165

1166-
QString QgsGeorefPluginGui::gdal_translateCommand( bool generateTFW )
1166+
QString QgsGeorefPluginGui::generateGDALtranslateCommand( bool generateTFW )
11671167
{
11681168
QStringList gdalCommand;
11691169
gdalCommand << "gdal_translate" << "-of GTiff";
@@ -1186,30 +1186,23 @@ QString QgsGeorefPluginGui::gdal_translateCommand( bool generateTFW )
11861186
return gdalCommand.join( " " );
11871187
}
11881188

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 )
11921191
{
11931192
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)
11981196
{
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 );
12001199
}
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" : "" );
12131206

12141207
if ( targetResX != 0.0 && targetResY != 0.0 )
12151208
{
@@ -1387,7 +1380,7 @@ QString QgsGeorefPluginGui::convertResamplingEnumToString( QgsImageWarper::Resam
13871380
return "";
13881381
}
13891382

1390-
int QgsGeorefPluginGui::polynomeOrder( QgsGeorefTransform::TransformParametrisation transform )
1383+
int QgsGeorefPluginGui::polynomialOrder( QgsGeorefTransform::TransformParametrisation transform )
13911384
{
13921385
switch ( transform )
13931386
{
@@ -1397,8 +1390,11 @@ int QgsGeorefPluginGui::polynomeOrder( QgsGeorefTransform::TransformParametrisat
13971390
return 2;
13981391
case QgsGeorefTransform::PolynomialOrder3:
13991392
return 3;
1400-
default:
1393+
case QgsGeorefTransform::ThinPlateSpline:
14011394
return -1;
1395+
1396+
default:
1397+
return 0;
14021398
}
14031399
}
14041400

src/plugins/georeferencer/qgsgeorefplugingui.h

+7-11
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,12 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
135135

136136
// gdal script
137137
void showGDALScript( int argNum... );
138-
QString gdal_translateCommand( bool generateTFW = true );
139-
QString gdalwarpCommandGCP( QString resampling, QString compress, bool useZeroForTrans, int order,
140-
double targetResX, double targetResY );
141-
QString gdalwarpCommandTPS( QString resampling, QString compress, bool useZeroForTrans,
142-
double targetResX, double targetResY );
143-
144-
// log
145-
void showMessageInLog( const QString &description, const QString &msg );
146-
void clearLog();
138+
QString generateGDALtranslateCommand( bool generateTFW = true);
139+
/* Generate command-line for gdalwarp based on current GCPs and given parameters.
140+
* For values in the range 1 to 3, the parameter "order" prescribes the degree of the interpolating polynomials to use,
141+
* a value of -1 indicates that thin plate spline interpolation should be used for warping.*/
142+
QString generateGDALwarpCommand( QString resampling, QString compress, bool useZeroForTrans, int order,
143+
double targetResX, double targetResY );
147144

148145
// utils
149146
bool checkReadyGeoref();
@@ -152,7 +149,7 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
152149
bool rasterToWorld = true, uint numSamples = 4 );
153150
QString convertTransformEnumToString( QgsGeorefTransform::TransformParametrisation transform );
154151
QString convertResamplingEnumToString( QgsImageWarper::ResamplingMethod resampling );
155-
int polynomeOrder( QgsGeorefTransform::TransformParametrisation transform );
152+
int polynomialOrder( QgsGeorefTransform::TransformParametrisation transform );
156153
QString guessWorldFileName( const QString &rasterFileName );
157154
QIcon getThemeIcon( const QString &theName );
158155
bool checkFileExisting( QString fileName, QString title, QString question );
@@ -165,7 +162,6 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
165162
QMenu *mPanelMenu;
166163
QMenu *mToolbarMenu;
167164

168-
// QPlainTextEdit *mLogViewer;
169165
QAction *mActionHelp;
170166

171167
QgsGCPListWidget *mGCPListWidget;

0 commit comments

Comments
 (0)