Skip to content

Commit d3bbe11

Browse files
author
mhugent
committed
[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
1 parent b1aaa39 commit d3bbe11

File tree

4 files changed

+102
-51
lines changed

4 files changed

+102
-51
lines changed

src/plugins/georeferencer/qgsgcplistmodel.cpp

+37-35
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "qgis.h"
2020
#include "qgsgeorefdatapoint.h"
2121
#include "qgsgeoreftransform.h"
22+
#include <QSettings>
2223

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

93-
if ( mGeorefTransform )
94-
{
95-
vector<QgsPoint> mapCoords, pixelCoords;
96-
mGCPList->createGCPVectors( mapCoords, pixelCoords );
97-
98-
// TODO: the parameters should probable be updated externally (by user interaction)
99-
bTransformUpdated = mGeorefTransform->updateParametersFromGCPs( mapCoords, pixelCoords );
100-
//transformation that involves only scaling and rotation (linear or helmert) ?
101-
wldTransform = mGeorefTransform->getOriginScaleRotation( origin, wldScaleX, wldScaleY, rotation );
102-
if ( wldTransform && !doubleNear( rotation, 0.0 ) )
103-
{
104-
wldScaleX *= cos( rotation );
105-
wldScaleY *= cos( rotation );
106-
}
107-
if ( wldTransform )
108-
{
94+
vector<QgsPoint> mapCoords, pixelCoords;
95+
mGCPList->createGCPVectors( mapCoords, pixelCoords );
10996

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

113100
// // Setup table header
114101
QStringList itemLabels;
115-
QString unitType = wldTransform ? tr( "map units" ) : tr ("pixels");
102+
QString unitType;
103+
QSettings s;
104+
if ( s.value( "/Plugin-GeoReferencer/Config/ResidualUnits" ) == "mapUnits" )
105+
{
106+
unitType = tr( "map units" );
107+
}
108+
else
109+
{
110+
unitType = tr( "pixels" );
111+
}
112+
116113
itemLabels << "on/off" << "id" << "srcX" << "srcY" << "dstX" << "dstY" << QString( "dX[" ) + unitType + "]" << QString( "dY[" ) + unitType + "]" << "residual[" + unitType + "]";
117114

118115
setHorizontalHeaderLabels( itemLabels );
@@ -140,29 +137,34 @@ void QgsGCPListModel::updateModel()
140137
setItem( i, j++, QGSSTANDARDITEM( p->mapCoords().y() ) /*create_item<double>( p->mapCoords().y() )*/ );
141138

142139
double residual;
143-
double dX, dY;
140+
double dX = 0;
141+
double dY = 0;
144142
// Calculate residual if transform is available and up-to-date
145143
if ( mGeorefTransform && bTransformUpdated && mGeorefTransform->parametersInitialized() )
146144
{
147145
QgsPoint dst;
148-
// Transform from world to raster coordinate:
149-
// This is the transform direction used by the warp operation.
150-
// As transforms of order >=2 are not invertible, we are only
151-
// interested in the residual in this direction
152-
mGeorefTransform->transformWorldToRaster( p->mapCoords(), dst );
153-
dX = ( dst.x() - p->pixelCoords().x() );
154-
dY = -( dst.y() - p->pixelCoords().y() );
155-
if ( wldTransform )
146+
if ( unitType == tr( "pixels" ) )
156147
{
157-
dX *= wldScaleX;
158-
dY *= wldScaleY;
148+
// Transform from world to raster coordinate:
149+
// This is the transform direction used by the warp operation.
150+
// As transforms of order >=2 are not invertible, we are only
151+
// interested in the residual in this direction
152+
if ( mGeorefTransform->transformWorldToRaster( p->mapCoords(), dst ) )
153+
{
154+
dX = ( dst.x() - p->pixelCoords().x() );
155+
dY = -( dst.y() - p->pixelCoords().y() );
156+
}
157+
}
158+
else if ( unitType == tr( "map units" ) )
159+
{
160+
if ( mGeorefTransform->transformRasterToWorld( p->pixelCoords(), dst ) )
161+
{
162+
dX = ( dst.x() - p->mapCoords().x() );
163+
dY = ( dst.y() - p->mapCoords().y() );
164+
}
159165
}
160-
residual = sqrt( dX * dX + dY * dY );
161-
}
162-
else
163-
{
164-
dX = dY = residual = 0;
165166
}
167+
residual = sqrt( dX * dX + dY * dY );
166168

167169
if ( p )
168170
{

src/plugins/georeferencer/qgsgeorefconfigdialog.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ void QgsGeorefConfigDialog::readSettings()
7979
{
8080
mShowDockedCheckBox->setChecked( false );
8181
}
82+
83+
if ( s.value( "/Plugin-GeoReferencer/Config/ResidualUnits" ).toString() == "mapUnits" )
84+
{
85+
mMapUnitsButton->setChecked( true );
86+
}
87+
else
88+
{
89+
mPixelsButton->setChecked( true );
90+
}
8291
}
8392

8493
void QgsGeorefConfigDialog::writeSettings()
@@ -87,4 +96,12 @@ void QgsGeorefConfigDialog::writeSettings()
8796
s.setValue( "/Plugin-GeoReferencer/Config/ShowId", mShowIDsCheckBox->isChecked() );
8897
s.setValue( "/Plugin-GeoReferencer/Config/ShowCoords", mShowCoordsCheckBox->isChecked() );
8998
s.setValue( "/Plugin-GeoReferencer/Config/ShowDocked", mShowDockedCheckBox->isChecked() );
99+
if ( mPixelsButton->isChecked() )
100+
{
101+
s.setValue( "/Plugin-GeoReferencer/Config/ResidualUnits", "pixels" );
102+
}
103+
else
104+
{
105+
s.setValue( "/Plugin-GeoReferencer/Config/ResidualUnits", "mapUnits" );
106+
}
90107
}

src/plugins/georeferencer/qgsgeorefconfigdialogbase.ui

+27-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>219</width>
10-
<height>162</height>
9+
<width>249</width>
10+
<height>249</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -37,14 +37,14 @@
3737
</layout>
3838
</widget>
3939
</item>
40-
<item row="1" column="0">
40+
<item row="2" column="0">
4141
<widget class="QCheckBox" name="mShowDockedCheckBox">
4242
<property name="text">
4343
<string>Show Georeferencer window docked</string>
4444
</property>
4545
</widget>
4646
</item>
47-
<item row="2" column="0">
47+
<item row="3" column="0">
4848
<widget class="QDialogButtonBox" name="buttonBox">
4949
<property name="orientation">
5050
<enum>Qt::Horizontal</enum>
@@ -54,6 +54,29 @@
5454
</property>
5555
</widget>
5656
</item>
57+
<item row="1" column="0">
58+
<widget class="QGroupBox" name="mResidualUnitsGroupBox">
59+
<property name="title">
60+
<string>Residual units</string>
61+
</property>
62+
<layout class="QGridLayout" name="gridLayout_3">
63+
<item row="0" column="0">
64+
<widget class="QRadioButton" name="mPixelsButton">
65+
<property name="text">
66+
<string>Pixels</string>
67+
</property>
68+
</widget>
69+
</item>
70+
<item row="1" column="0">
71+
<widget class="QRadioButton" name="mMapUnitsButton">
72+
<property name="text">
73+
<string>Map units</string>
74+
</property>
75+
</widget>
76+
</item>
77+
</layout>
78+
</widget>
79+
</item>
5780
</layout>
5881
</widget>
5982
<resources/>

src/plugins/georeferencer/qgsgeorefplugingui.cpp

+21-12
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ QgsGeorefDockWidget::QgsGeorefDockWidget( const QString & title, QWidget * paren
7171

7272
void QgsGeorefDockWidget::closeEvent( QCloseEvent * ev )
7373
{
74-
if (widget() && !widget()->close())
74+
if ( widget() && !widget()->close() )
7575
{
7676
ev->ignore();
7777
return;
@@ -613,6 +613,13 @@ void QgsGeorefPluginGui::showGeorefConfigDialog()
613613
{
614614
dockThisWindow( false );
615615
}
616+
//update gcp model
617+
if ( mGCPListWidget )
618+
{
619+
mGCPListWidget->updateGCPList();
620+
}
621+
//and status bar
622+
updateTransformParamLabel();
616623
}
617624
}
618625

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

12571264
// Calculate the root mean square error, adjusted for degrees of freedom of the transform
12581265
// Caveat: The number of DoFs is assumed to be even (as each control point fixes two degrees of freedom).
1259-
error = sqrt(( sumVxSquare + sumVySquare ) / ( nPointsEnabled - mGeorefTransform.getMinimumGCPCount() ));
1266+
error = sqrt(( sumVxSquare + sumVySquare ) / ( nPointsEnabled - mGeorefTransform.getMinimumGCPCount() ) );
12601267
return true;
12611268
}
12621269

@@ -1335,6 +1342,17 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
13351342
//transformation that involves only scaling and rotation (linear or helmert) ?
13361343
bool wldTransform = transform.getOriginScaleRotation( origin, scaleX, scaleY, rotation );
13371344

1345+
QString residualUnits;
1346+
QSettings s;
1347+
if ( s.value( "/Plugin-GeoReferencer/Config/ResidualUnits" ) == "mapUnits" )
1348+
{
1349+
residualUnits = tr( "map units" );
1350+
}
1351+
else
1352+
{
1353+
residualUnits = tr( "pixels" );
1354+
}
1355+
13381356
if ( wldTransform )
13391357
{
13401358
QString parameterTitle = tr( "Transformation parameters" ) + QString( " (" ) + convertTransformEnumToString( transform.transformParametrisation() ) + QString( ")" );
@@ -1354,7 +1372,7 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
13541372
parameterTable->setHeaderFont( tableHeaderFont );
13551373
parameterTable->setContentFont( tableContentFont );
13561374
QStringList headers;
1357-
headers << tr( "Translation x" ) << tr( "Translation y" ) << tr( "Scale x" ) << tr( "Scale y" ) << tr( "Rotation [degrees]" ) << tr( "Mean error [map units]" );
1375+
headers << tr( "Translation x" ) << tr( "Translation y" ) << tr( "Scale x" ) << tr( "Scale y" ) << tr( "Rotation [degrees]" ) << tr( "Mean error [%1]" ).arg( residualUnits );
13581376
parameterTable->setHeaderLabels( headers );
13591377
QStringList row;
13601378
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
13951413
}
13961414
}
13971415

1398-
QString residualUnits;
1399-
if ( wldTransform )
1400-
{
1401-
residualUnits = tr( "map units" );
1402-
}
1403-
else
1404-
{
1405-
residualUnits = tr( "pixels" );
1406-
}
14071416
QgsComposerTextTable* gcpTable = new QgsComposerTextTable( composition );
14081417
gcpTable->setHeaderFont( tableHeaderFont );
14091418
gcpTable->setContentFont( tableContentFont );

0 commit comments

Comments
 (0)