Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Disable world-file in command line generator. Remove some code duplic…
…ation.

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13297 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mmassing committed Apr 11, 2010
1 parent 845db57 commit 4bdc03a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 57 deletions.
88 changes: 42 additions & 46 deletions src/plugins/georeferencer/qgsgeorefplugingui.cpp
Expand Up @@ -294,32 +294,32 @@ void QgsGeorefPluginGui::generateGDALScript()
if ( !checkReadyGeoref() )
return;

if ( QgsGeorefTransform::Linear != mTransformParam
&& QgsGeorefTransform::Helmert != mTransformParam )
switch (mTransformParam)
{
// CAVEAT: gdalwarpCommand*() rely on some member variables being set
// by gdal_translateCommand(), so this method must be called before
// gdalwarpCommand*()!
QString translateCommand = gdal_translateCommand();
QString gdalwarpCommand;
QString resamplingStr = convertResamplingEnumToString( mResamplingMethod );
if ( QgsGeorefTransform::ThinPlateSpline == mTransformParam )
{
gdalwarpCommand = gdalwarpCommandTPS( resamplingStr, mCompressionMethod, mUseZeroForTrans,
mUserResX, mUserResY );
}
else
case QgsGeorefTransform::PolynomialOrder1:
case QgsGeorefTransform::PolynomialOrder2:
case QgsGeorefTransform::PolynomialOrder3:
case QgsGeorefTransform::ThinPlateSpline:
{
gdalwarpCommand = gdalwarpCommandGCP( resamplingStr, mCompressionMethod, mUseZeroForTrans,
polynomeOrder( mTransformParam ),
mUserResX, mUserResY );
// CAVEAT: generateGDALwarpCommand() relies on some member variables being set
// by generateGDALtranslateCommand(), so this method must be called before
// gdalwarpCommand*()!
QString translateCommand = generateGDALtranslateCommand( false );
QString gdalwarpCommand;
QString resamplingStr = convertResamplingEnumToString( mResamplingMethod );

int order = polynomialOrder( mTransformParam );
if (order != 0)
{
gdalwarpCommand = generateGDALwarpCommand( resamplingStr, mCompressionMethod, mUseZeroForTrans, order,
mUserResX, mUserResY );
showGDALScript( 2, translateCommand.toAscii().data(), gdalwarpCommand.toAscii().data() );
break;
}
}
showGDALScript( 2, translateCommand.toAscii().data(), gdalwarpCommand.toAscii().data() );
}
else
{
QMessageBox::information( this, tr( "Info" ), tr( "GDAL scripting is not supported for %1 transformation" )
.arg( convertTransformEnumToString( mTransformParam ) ) );
default:
QMessageBox::information( this, tr( "Info" ), tr( "GDAL scripting is not supported for %1 transformation" )
.arg( convertTransformEnumToString( mTransformParam ) ) );
}
}

Expand Down Expand Up @@ -1163,7 +1163,7 @@ void QgsGeorefPluginGui::showGDALScript( int argNum... )
}
}

QString QgsGeorefPluginGui::gdal_translateCommand( bool generateTFW )
QString QgsGeorefPluginGui::generateGDALtranslateCommand( bool generateTFW )
{
QStringList gdalCommand;
gdalCommand << "gdal_translate" << "-of GTiff";
Expand All @@ -1186,30 +1186,23 @@ QString QgsGeorefPluginGui::gdal_translateCommand( bool generateTFW )
return gdalCommand.join( " " );
}

QString QgsGeorefPluginGui::gdalwarpCommandGCP( QString resampling, QString compress,
bool useZeroForTrans, int order,
double targetResX, double targetResY )
QString QgsGeorefPluginGui::generateGDALwarpCommand( QString resampling, QString compress,
bool useZeroForTrans, int order, double targetResX, double targetResY )
{
QStringList gdalCommand;
gdalCommand << "gdalwarp" << "-r" << resampling << "-order" << QString::number( order )
<< "-co COMPRESS=" + compress << ( useZeroForTrans ? "-dstalpha" : "" );

if ( targetResX != 0.0 && targetResY != 0.0 )
gdalCommand << "gdalwarp" << "-r" << resampling;

if (order > 0 && order <= 3)
{
gdalCommand << "-tr" << QString::number( targetResX, 'f' ) << QString::number( targetResY, 'f' );
// Let gdalwarp use polynomial warp with the given degree
gdalCommand << "-order" << QString::number( order );
}

gdalCommand << QString("\"%1\"").arg(mTranslatedRasterFileName) << QString("\"%1\"").arg(mModifiedRasterFileName);

return gdalCommand.join( " " );
}

QString QgsGeorefPluginGui::gdalwarpCommandTPS( QString resampling, QString compress, bool useZeroForTrans,
double targetResX, double targetResY )
{
QStringList gdalCommand;
gdalCommand << "gdalwarp" << "-r" << resampling << "-tps"
<< "-co COMPRESS=" + compress << ( useZeroForTrans ? "-dstalpha" : "" );
else
{
// Otherwise, use thin plate spline interpolation
gdalCommand << "-tps";
}
gdalCommand<< "-co COMPRESS=" + compress << ( useZeroForTrans ? "-dstalpha" : "" );

if ( targetResX != 0.0 && targetResY != 0.0 )
{
Expand Down Expand Up @@ -1387,7 +1380,7 @@ QString QgsGeorefPluginGui::convertResamplingEnumToString( QgsImageWarper::Resam
return "";
}

int QgsGeorefPluginGui::polynomeOrder( QgsGeorefTransform::TransformParametrisation transform )
int QgsGeorefPluginGui::polynomialOrder( QgsGeorefTransform::TransformParametrisation transform )
{
switch ( transform )
{
Expand All @@ -1397,8 +1390,11 @@ int QgsGeorefPluginGui::polynomeOrder( QgsGeorefTransform::TransformParametrisat
return 2;
case QgsGeorefTransform::PolynomialOrder3:
return 3;
default:
case QgsGeorefTransform::ThinPlateSpline:
return -1;

default:
return 0;
}
}

Expand Down
18 changes: 7 additions & 11 deletions src/plugins/georeferencer/qgsgeorefplugingui.h
Expand Up @@ -135,15 +135,12 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas

// gdal script
void showGDALScript( int argNum... );
QString gdal_translateCommand( bool generateTFW = true );
QString gdalwarpCommandGCP( QString resampling, QString compress, bool useZeroForTrans, int order,
double targetResX, double targetResY );
QString gdalwarpCommandTPS( QString resampling, QString compress, bool useZeroForTrans,
double targetResX, double targetResY );

// log
void showMessageInLog( const QString &description, const QString &msg );
void clearLog();
QString generateGDALtranslateCommand( bool generateTFW = true);
/* Generate command-line for gdalwarp based on current GCPs and given parameters.
* For values in the range 1 to 3, the parameter "order" prescribes the degree of the interpolating polynomials to use,
* a value of -1 indicates that thin plate spline interpolation should be used for warping.*/
QString generateGDALwarpCommand( QString resampling, QString compress, bool useZeroForTrans, int order,
double targetResX, double targetResY );

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

// QPlainTextEdit *mLogViewer;
QAction *mActionHelp;

QgsGCPListWidget *mGCPListWidget;
Expand Down

0 comments on commit 4bdc03a

Please sign in to comment.