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

svn_qgis at osgeo.org svn_qgis at osgeo.org
Mon May 31 06:42:17 EDT 2010


Author: mhugent
Date: 2010-05-31 06:42:17 -0400 (Mon, 31 May 2010)
New Revision: 13606

Modified:
   trunk/qgis/src/plugins/georeferencer/qgsgcplistmodel.cpp
   trunk/qgis/src/plugins/georeferencer/qgsgeorefconfigdialog.cpp
   trunk/qgis/src/plugins/georeferencer/qgsgeorefconfigdialogbase.ui
   trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.cpp
Log:
[FEATURE] georeferencer: possibility to configure if residuals should be showed in pixels or map units

Modified: trunk/qgis/src/plugins/georeferencer/qgsgcplistmodel.cpp
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgsgcplistmodel.cpp	2010-05-31 07:36:43 UTC (rev 13605)
+++ trunk/qgis/src/plugins/georeferencer/qgsgcplistmodel.cpp	2010-05-31 10:42:17 UTC (rev 13606)
@@ -19,6 +19,7 @@
 #include "qgis.h"
 #include "qgsgeorefdatapoint.h"
 #include "qgsgeoreftransform.h"
+#include <QSettings>
 
 #include <cmath>
 using namespace std;
@@ -90,29 +91,25 @@
   double wldScaleX, wldScaleY, rotation;
   QgsPoint origin;
 
-  if ( mGeorefTransform )
-  {
-    vector<QgsPoint> mapCoords, pixelCoords;
-    mGCPList->createGCPVectors( mapCoords, pixelCoords );
+  vector<QgsPoint> mapCoords, pixelCoords;
+  mGCPList->createGCPVectors( mapCoords, pixelCoords );
 
-    // TODO: the parameters should probable be updated externally (by user interaction)
-    bTransformUpdated = mGeorefTransform->updateParametersFromGCPs( mapCoords, pixelCoords );
-    //transformation that involves only scaling and rotation (linear or helmert) ?
-    wldTransform = mGeorefTransform->getOriginScaleRotation( origin, wldScaleX, wldScaleY, rotation );
-    if ( wldTransform && !doubleNear( rotation, 0.0 ) )
-    {
-      wldScaleX *= cos( rotation );
-      wldScaleY *= cos( rotation );
-    }
-    if ( wldTransform )
-    {
+  // TODO: the parameters should probable be updated externally (by user interaction)
+  bTransformUpdated = mGeorefTransform->updateParametersFromGCPs( mapCoords, pixelCoords );
 
-    }
+  //  // Setup table header
+  QStringList itemLabels;
+  QString unitType;
+  QSettings s;
+  if ( s.value( "/Plugin-GeoReferencer/Config/ResidualUnits" ) == "mapUnits" )
+  {
+    unitType = tr( "map units" );
   }
+  else
+  {
+    unitType = tr( "pixels" );
+  }
 
-  //  // Setup table header
-  QStringList itemLabels;
-  QString unitType = wldTransform ? tr( "map units" ) : tr ("pixels");
   itemLabels << "on/off" << "id" << "srcX" << "srcY" << "dstX" << "dstY" << QString( "dX[" ) + unitType + "]" << QString( "dY[" ) + unitType + "]" << "residual[" + unitType + "]";
 
   setHorizontalHeaderLabels( itemLabels );
@@ -140,29 +137,34 @@
     setItem( i, j++, QGSSTANDARDITEM( p->mapCoords().y() ) /*create_item<double>( p->mapCoords().y() )*/ );
 
     double residual;
-    double dX, dY;
+    double dX = 0;
+    double dY = 0;
     // Calculate residual if transform is available and up-to-date
     if ( mGeorefTransform && bTransformUpdated && mGeorefTransform->parametersInitialized() )
     {
       QgsPoint dst;
-      // Transform from world to raster coordinate:
-      // This is the transform direction used by the warp operation.
-      // As transforms of order >=2 are not invertible, we are only
-      // interested in the residual in this direction
-      mGeorefTransform->transformWorldToRaster( p->mapCoords(), dst );
-      dX = ( dst.x() - p->pixelCoords().x() );
-      dY = -( dst.y() - p->pixelCoords().y() );
-      if ( wldTransform )
+      if ( unitType == tr( "pixels" ) )
       {
-        dX *= wldScaleX;
-        dY *= wldScaleY;
+        // Transform from world to raster coordinate:
+        // This is the transform direction used by the warp operation.
+        // As transforms of order >=2 are not invertible, we are only
+        // interested in the residual in this direction
+        if ( mGeorefTransform->transformWorldToRaster( p->mapCoords(), dst ) )
+        {
+          dX = ( dst.x() - p->pixelCoords().x() );
+          dY = -( dst.y() - p->pixelCoords().y() );
+        }
       }
-      residual = sqrt( dX * dX + dY * dY );
+      else if ( unitType == tr( "map units" ) )
+      {
+        if ( mGeorefTransform->transformRasterToWorld( p->pixelCoords(), dst ) )
+        {
+          dX = ( dst.x() - p->mapCoords().x() );
+          dY = ( dst.y() - p->mapCoords().y() );
+        }
+      }
     }
-    else
-    {
-      dX = dY = residual = 0;
-    }
+    residual = sqrt( dX * dX + dY * dY );
 
     if ( p )
     {

Modified: trunk/qgis/src/plugins/georeferencer/qgsgeorefconfigdialog.cpp
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgsgeorefconfigdialog.cpp	2010-05-31 07:36:43 UTC (rev 13605)
+++ trunk/qgis/src/plugins/georeferencer/qgsgeorefconfigdialog.cpp	2010-05-31 10:42:17 UTC (rev 13606)
@@ -79,6 +79,15 @@
   {
     mShowDockedCheckBox->setChecked( false );
   }
+
+  if ( s.value( "/Plugin-GeoReferencer/Config/ResidualUnits" ).toString() == "mapUnits" )
+  {
+    mMapUnitsButton->setChecked( true );
+  }
+  else
+  {
+    mPixelsButton->setChecked( true );
+  }
 }
 
 void QgsGeorefConfigDialog::writeSettings()
@@ -87,4 +96,12 @@
   s.setValue( "/Plugin-GeoReferencer/Config/ShowId", mShowIDsCheckBox->isChecked() );
   s.setValue( "/Plugin-GeoReferencer/Config/ShowCoords", mShowCoordsCheckBox->isChecked() );
   s.setValue( "/Plugin-GeoReferencer/Config/ShowDocked", mShowDockedCheckBox->isChecked() );
+  if ( mPixelsButton->isChecked() )
+  {
+    s.setValue( "/Plugin-GeoReferencer/Config/ResidualUnits", "pixels" );
+  }
+  else
+  {
+    s.setValue( "/Plugin-GeoReferencer/Config/ResidualUnits", "mapUnits" );
+  }
 }

Modified: trunk/qgis/src/plugins/georeferencer/qgsgeorefconfigdialogbase.ui
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgsgeorefconfigdialogbase.ui	2010-05-31 07:36:43 UTC (rev 13605)
+++ trunk/qgis/src/plugins/georeferencer/qgsgeorefconfigdialogbase.ui	2010-05-31 10:42:17 UTC (rev 13606)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>219</width>
-    <height>162</height>
+    <width>249</width>
+    <height>249</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -37,14 +37,14 @@
      </layout>
     </widget>
    </item>
-   <item row="1" column="0">
+   <item row="2" column="0">
     <widget class="QCheckBox" name="mShowDockedCheckBox">
      <property name="text">
       <string>Show Georeferencer window docked</string>
      </property>
     </widget>
    </item>
-   <item row="2" column="0">
+   <item row="3" column="0">
     <widget class="QDialogButtonBox" name="buttonBox">
      <property name="orientation">
       <enum>Qt::Horizontal</enum>
@@ -54,6 +54,29 @@
      </property>
     </widget>
    </item>
+   <item row="1" column="0">
+    <widget class="QGroupBox" name="mResidualUnitsGroupBox">
+     <property name="title">
+      <string>Residual units</string>
+     </property>
+     <layout class="QGridLayout" name="gridLayout_3">
+      <item row="0" column="0">
+       <widget class="QRadioButton" name="mPixelsButton">
+        <property name="text">
+         <string>Pixels</string>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="0">
+       <widget class="QRadioButton" name="mMapUnitsButton">
+        <property name="text">
+         <string>Map units</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
   </layout>
  </widget>
  <resources/>

Modified: trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.cpp
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.cpp	2010-05-31 07:36:43 UTC (rev 13605)
+++ trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.cpp	2010-05-31 10:42:17 UTC (rev 13606)
@@ -71,7 +71,7 @@
 
 void QgsGeorefDockWidget::closeEvent( QCloseEvent * ev )
 {
-  if (widget() && !widget()->close())
+  if ( widget() && !widget()->close() )
   {
     ev->ignore();
     return;
@@ -613,6 +613,13 @@
     {
       dockThisWindow( false );
     }
+    //update gcp model
+    if ( mGCPListWidget )
+    {
+      mGCPListWidget->updateGCPList();
+    }
+    //and status bar
+    updateTransformParamLabel();
   }
 }
 
@@ -1256,7 +1263,7 @@
 
   // Calculate the root mean square error, adjusted for degrees of freedom of the transform
   // Caveat: The number of DoFs is assumed to be even (as each control point fixes two degrees of freedom).
-  error = sqrt(( sumVxSquare + sumVySquare ) / ( nPointsEnabled - mGeorefTransform.getMinimumGCPCount() ));
+  error = sqrt(( sumVxSquare + sumVySquare ) / ( nPointsEnabled - mGeorefTransform.getMinimumGCPCount() ) );
   return true;
 }
 
@@ -1335,6 +1342,17 @@
   //transformation that involves only scaling and rotation (linear or helmert) ?
   bool wldTransform = transform.getOriginScaleRotation( origin, scaleX, scaleY, rotation );
 
+  QString residualUnits;
+  QSettings s;
+  if ( s.value( "/Plugin-GeoReferencer/Config/ResidualUnits" ) == "mapUnits" )
+  {
+    residualUnits = tr( "map units" );
+  }
+  else
+  {
+    residualUnits = tr( "pixels" );
+  }
+
   if ( wldTransform )
   {
     QString parameterTitle = tr( "Transformation parameters" ) + QString( " (" ) + convertTransformEnumToString( transform.transformParametrisation() ) + QString( ")" );
@@ -1354,7 +1372,7 @@
     parameterTable->setHeaderFont( tableHeaderFont );
     parameterTable->setContentFont( tableContentFont );
     QStringList headers;
-    headers << tr( "Translation x" ) << tr( "Translation y" ) << tr( "Scale x" ) << tr( "Scale y" ) << tr( "Rotation [degrees]" ) << tr( "Mean error [map units]" );
+    headers << tr( "Translation x" ) << tr( "Translation y" ) << tr( "Scale x" ) << tr( "Scale y" ) << tr( "Rotation [degrees]" ) << tr( "Mean error [%1]" ).arg( residualUnits );
     parameterTable->setHeaderLabels( headers );
     QStringList row;
     row << QString::number( origin.x() ) << QString::number( origin.y() ) << QString::number( scaleX ) << QString::number( scaleY ) << QString::number( rotation * 180 / M_PI ) << QString::number( meanError );
@@ -1395,15 +1413,6 @@
     }
   }
 
-  QString residualUnits;
-  if ( wldTransform )
-  {
-    residualUnits = tr( "map units" );
-  }
-  else
-  {
-    residualUnits = tr( "pixels" );
-  }
   QgsComposerTextTable* gcpTable = new QgsComposerTextTable( composition );
   gcpTable->setHeaderFont( tableHeaderFont );
   gcpTable->setContentFont( tableContentFont );



More information about the QGIS-commit mailing list