Skip to content
Permalink
Browse files
[FEATURE] georeferencer: possibility to configure if residuals should…
… be showed in pixels or map units

git-svn-id: http://svn.osgeo.org/qgis/trunk@13606 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed May 31, 2010
1 parent b1aaa39 commit d3bbe113d0e10cb753ff4e8d52ec132547c58cdc
@@ -19,6 +19,7 @@
#include "qgis.h"
#include "qgsgeorefdatapoint.h"
#include "qgsgeoreftransform.h"
#include <QSettings>

#include <cmath>
using namespace std;
@@ -90,29 +91,25 @@ void QgsGCPListModel::updateModel()
double wldScaleX, wldScaleY, rotation;
QgsPoint origin;

if ( mGeorefTransform )
{
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 )
{
vector<QgsPoint> mapCoords, pixelCoords;
mGCPList->createGCPVectors( mapCoords, pixelCoords );

}
}
// TODO: the parameters should probable be updated externally (by user interaction)
bTransformUpdated = mGeorefTransform->updateParametersFromGCPs( mapCoords, pixelCoords );

// // Setup table header
QStringList itemLabels;
QString unitType = wldTransform ? tr( "map units" ) : tr ("pixels");
QString unitType;
QSettings s;
if ( s.value( "/Plugin-GeoReferencer/Config/ResidualUnits" ) == "mapUnits" )
{
unitType = tr( "map units" );
}
else
{
unitType = tr( "pixels" );
}

itemLabels << "on/off" << "id" << "srcX" << "srcY" << "dstX" << "dstY" << QString( "dX[" ) + unitType + "]" << QString( "dY[" ) + unitType + "]" << "residual[" + unitType + "]";

setHorizontalHeaderLabels( itemLabels );
@@ -140,29 +137,34 @@ void QgsGCPListModel::updateModel()
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() );
}
}
else if ( unitType == tr( "map units" ) )
{
if ( mGeorefTransform->transformRasterToWorld( p->pixelCoords(), dst ) )
{
dX = ( dst.x() - p->mapCoords().x() );
dY = ( dst.y() - p->mapCoords().y() );
}
}
residual = sqrt( dX * dX + dY * dY );
}
else
{
dX = dY = residual = 0;
}
residual = sqrt( dX * dX + dY * dY );

if ( p )
{
@@ -79,6 +79,15 @@ void QgsGeorefConfigDialog::readSettings()
{
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 @@ void QgsGeorefConfigDialog::writeSettings()
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" );
}
}
@@ -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/>
@@ -71,7 +71,7 @@ QgsGeorefDockWidget::QgsGeorefDockWidget( const QString & title, QWidget * paren

void QgsGeorefDockWidget::closeEvent( QCloseEvent * ev )
{
if (widget() && !widget()->close())
if ( widget() && !widget()->close() )
{
ev->ignore();
return;
@@ -613,6 +613,13 @@ void QgsGeorefPluginGui::showGeorefConfigDialog()
{
dockThisWindow( false );
}
//update gcp model
if ( mGCPListWidget )
{
mGCPListWidget->updateGCPList();
}
//and status bar
updateTransformParamLabel();
}
}

@@ -1256,7 +1263,7 @@ bool QgsGeorefPluginGui::calculateMeanError( double& error ) const

// 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 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
//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 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
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 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
}
}

QString residualUnits;
if ( wldTransform )
{
residualUnits = tr( "map units" );
}
else
{
residualUnits = tr( "pixels" );
}
QgsComposerTextTable* gcpTable = new QgsComposerTextTable( composition );
gcpTable->setHeaderFont( tableHeaderFont );
gcpTable->setContentFont( tableContentFont );

0 comments on commit d3bbe11

Please sign in to comment.