[QGIS Commit] r13297 - trunk/qgis/src/plugins/georeferencer

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun Apr 11 08:44:20 EDT 2010


Author: mmassing
Date: 2010-04-11 08:44:20 -0400 (Sun, 11 Apr 2010)
New Revision: 13297

Modified:
   trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.cpp
   trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.h
Log:
Disable world-file in command line generator. Remove some code duplication.

Modified: trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.cpp
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.cpp	2010-04-11 12:44:10 UTC (rev 13296)
+++ trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.cpp	2010-04-11 12:44:20 UTC (rev 13297)
@@ -294,33 +294,33 @@
   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 )
+    case QgsGeorefTransform::PolynomialOrder1:
+    case QgsGeorefTransform::PolynomialOrder2:
+    case QgsGeorefTransform::PolynomialOrder3:
+    case QgsGeorefTransform::ThinPlateSpline:
     {
-      gdalwarpCommand = gdalwarpCommandTPS( resamplingStr, mCompressionMethod, mUseZeroForTrans,
-                                            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;
+      }
     }
-    else
-    {
-      gdalwarpCommand = gdalwarpCommandGCP( resamplingStr, mCompressionMethod, mUseZeroForTrans,
-                                            polynomeOrder( mTransformParam ),
-                                            mUserResX, mUserResY );
-    }
-    showGDALScript( 2, translateCommand.toAscii().data(), gdalwarpCommand.toAscii().data() );
+    default:
+      QMessageBox::information( this, tr( "Info" ), tr( "GDAL scripting is not supported for %1 transformation" )
+                                .arg( convertTransformEnumToString( mTransformParam ) ) );
   }
-  else
-  {
-    QMessageBox::information( this, tr( "Info" ), tr( "GDAL scripting is not supported for %1 transformation" )
-                              .arg( convertTransformEnumToString( mTransformParam ) ) );
-  }
 }
 
 // Edit slots
@@ -1163,7 +1163,7 @@
   }
 }
 
-QString QgsGeorefPluginGui::gdal_translateCommand( bool generateTFW )
+QString QgsGeorefPluginGui::generateGDALtranslateCommand( bool generateTFW )
 {
   QStringList gdalCommand;
   gdalCommand << "gdal_translate" << "-of GTiff";
@@ -1186,31 +1186,24 @@
   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 );
   }
+  else
+  {
+    // Otherwise, use thin plate spline interpolation
+    gdalCommand << "-tps";
+  }
+  gdalCommand<< "-co COMPRESS=" + compress << ( useZeroForTrans ? "-dstalpha" : "" );
 
-  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" : "" );
-
   if ( targetResX != 0.0 && targetResY != 0.0 )
   {
     gdalCommand << "-tr" << QString::number( targetResX, 'f' ) << QString::number( targetResY, 'f' );
@@ -1387,7 +1380,7 @@
   return "";
 }
 
-int QgsGeorefPluginGui::polynomeOrder( QgsGeorefTransform::TransformParametrisation transform )
+int QgsGeorefPluginGui::polynomialOrder( QgsGeorefTransform::TransformParametrisation transform )
 {
   switch ( transform )
   {
@@ -1397,8 +1390,11 @@
       return 2;
     case QgsGeorefTransform::PolynomialOrder3:
       return 3;
-    default:
+    case QgsGeorefTransform::ThinPlateSpline:
       return -1;
+
+    default:
+      return 0;
   }
 }
 

Modified: trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.h
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.h	2010-04-11 12:44:10 UTC (rev 13296)
+++ trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.h	2010-04-11 12:44:20 UTC (rev 13297)
@@ -135,16 +135,13 @@
 
     // 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 );
+    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 );
 
-    // log
-    void showMessageInLog( const QString &description, const QString &msg );
-    void clearLog();
-
     // utils
     bool checkReadyGeoref();
     bool updateGeorefTransform();
@@ -152,7 +149,7 @@
         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 );
@@ -165,7 +162,6 @@
     QMenu *mPanelMenu;
     QMenu *mToolbarMenu;
 
-//  QPlainTextEdit *mLogViewer;
     QAction *mActionHelp;
 
     QgsGCPListWidget *mGCPListWidget;



More information about the QGIS-commit mailing list