@@ -136,7 +136,6 @@ void QgsGeorefPluginGui::dockThisWindow( bool dock )
136
136
137
137
QgsGeorefPluginGui::~QgsGeorefPluginGui ()
138
138
{
139
- QgsTransformSettingsDialog::resetSettings ();
140
139
clearGCPData ();
141
140
142
141
// delete layer (and don't signal it as it's our private layer)
@@ -336,6 +335,7 @@ bool QgsGeorefPluginGui::getTransformSettings()
336
335
mActionLinkQGisToGeoref ->setEnabled ( false );
337
336
}
338
337
338
+ updateTransformParamLabel ();
339
339
return true ;
340
340
}
341
341
@@ -472,6 +472,7 @@ void QgsGeorefPluginGui::addPoint( const QgsPoint& pixelCoords, const QgsPoint&
472
472
}
473
473
474
474
connect ( mCanvas , SIGNAL ( extentsChanged () ), pnt, SLOT ( updateCoords () ) );
475
+ updateGeorefTransform ();
475
476
476
477
// if (verbose)
477
478
// logRequaredGCPs();
@@ -498,13 +499,15 @@ void QgsGeorefPluginGui::deleteDataPoint( const QPoint &coords )
498
499
break ;
499
500
}
500
501
}
502
+ updateGeorefTransform ();
501
503
}
502
504
503
505
void QgsGeorefPluginGui::deleteDataPoint ( int index )
504
506
{
505
507
mGCPListWidget ->model ()->removeRow ( index );
506
508
delete mPoints .takeAt ( index );
507
509
mGCPListWidget ->updateGCPList ();
510
+ updateGeorefTransform ();
508
511
}
509
512
510
513
void QgsGeorefPluginGui::selectPoint ( const QPoint &p )
@@ -930,12 +933,24 @@ void QgsGeorefPluginGui::createDockWidgets()
930
933
this , SLOT ( replaceDataPoint ( QgsGeorefDataPoint*, int ) ) );
931
934
connect ( mGCPListWidget , SIGNAL ( deleteDataPoint ( int ) ),
932
935
this , SLOT ( deleteDataPoint ( int ) ) );
936
+ connect ( mGCPListWidget , SIGNAL ( pointEnabled ( QgsGeorefDataPoint*, int ) ), this , SLOT ( updateGeorefTransform () ) );
933
937
}
934
938
935
939
void QgsGeorefPluginGui::createStatusBar ()
936
940
{
937
941
QFont myFont ( " Arial" , 9 );
938
942
943
+ mTransformParamLabel = new QLabel ( statusBar () );
944
+ mTransformParamLabel ->setFont ( myFont );
945
+ mTransformParamLabel ->setMinimumWidth ( 10 );
946
+ mTransformParamLabel ->setMaximumHeight ( 20 );
947
+ mTransformParamLabel ->setMargin ( 3 );
948
+ mTransformParamLabel ->setAlignment ( Qt::AlignCenter );
949
+ mTransformParamLabel ->setFrameStyle ( QFrame::NoFrame );
950
+ mTransformParamLabel ->setText ( tr ( " Transform: " ) + convertTransformEnumToString ( mTransformParam ) );
951
+ mTransformParamLabel ->setToolTip ( tr ( " Current transform parametrisation" ) );
952
+ statusBar ()->addPermanentWidget ( mTransformParamLabel , 0 );
953
+
939
954
mCoordsLabel = new QLabel ( QString (), statusBar () );
940
955
mCoordsLabel ->setFont ( myFont );
941
956
mCoordsLabel ->setMinimumWidth ( 10 );
@@ -947,17 +962,6 @@ void QgsGeorefPluginGui::createStatusBar()
947
962
mCoordsLabel ->setText ( tr ( " Coordinate: " ) );
948
963
mCoordsLabel ->setToolTip ( tr ( " Current map coordinate" ) );
949
964
statusBar ()->addPermanentWidget ( mCoordsLabel , 0 );
950
-
951
- mTransformParamLabel = new QLabel ( statusBar () );
952
- mTransformParamLabel ->setFont ( myFont );
953
- mTransformParamLabel ->setMinimumWidth ( 10 );
954
- mTransformParamLabel ->setMaximumHeight ( 20 );
955
- mTransformParamLabel ->setMargin ( 3 );
956
- mTransformParamLabel ->setAlignment ( Qt::AlignCenter );
957
- mTransformParamLabel ->setFrameStyle ( QFrame::NoFrame );
958
- mTransformParamLabel ->setText ( tr ( " Transform: " ) + convertTransformEnumToString ( mTransformParam ) );
959
- mTransformParamLabel ->setToolTip ( tr ( " Current transform parametrisation" ) );
960
- statusBar ()->addPermanentWidget ( mTransformParamLabel , 0 );
961
965
}
962
966
963
967
void QgsGeorefPluginGui::setupConnections ()
@@ -1208,6 +1212,53 @@ bool QgsGeorefPluginGui::writeWorldFile( QgsPoint origin, double pixelXSize, dou
1208
1212
return true ;
1209
1213
}
1210
1214
1215
+ bool QgsGeorefPluginGui::calculateMeanError ( double & error ) const
1216
+ {
1217
+ if ( mGeorefTransform .transformParametrisation () == QgsGeorefTransform::InvalidTransform )
1218
+ {
1219
+ return false ;
1220
+ }
1221
+
1222
+ int nPointsEnabled = 0 ;
1223
+ QgsGCPList::const_iterator gcpIt = mPoints .constBegin ();
1224
+ for ( ; gcpIt != mPoints .constEnd (); ++gcpIt )
1225
+ {
1226
+ if (( *gcpIt )->isEnabled () )
1227
+ {
1228
+ ++nPointsEnabled;
1229
+ }
1230
+ }
1231
+
1232
+ if ( nPointsEnabled == mGeorefTransform .getMinimumGCPCount () )
1233
+ {
1234
+ error = 0 ;
1235
+ return true ;
1236
+ }
1237
+ else if ( nPointsEnabled < mGeorefTransform .getMinimumGCPCount () )
1238
+ {
1239
+ return false ;
1240
+ }
1241
+
1242
+ double sumVxSquare = 0 ;
1243
+ double sumVySquare = 0 ;
1244
+ double resXMap, resYMap;
1245
+
1246
+ gcpIt = mPoints .constBegin ();
1247
+ for ( ; gcpIt != mPoints .constEnd (); ++gcpIt )
1248
+ {
1249
+ if (( *gcpIt )->isEnabled () )
1250
+ {
1251
+ sumVxSquare += (( *gcpIt )->residual ().x () * ( *gcpIt )->residual ().x () );
1252
+ sumVySquare += (( *gcpIt )->residual ().y () * ( *gcpIt )->residual ().y () );
1253
+ }
1254
+ }
1255
+
1256
+ // Calculate the root mean square error, adjusted for degrees of freedom of the transform
1257
+ // Caveat: The number of DoFs is assumed to be even (as each control point fixes two degrees of freedom).
1258
+ error = sqrt (( sumVxSquare + sumVySquare ) / ( nPointsEnabled - mGeorefTransform .getMinimumGCPCount () ));
1259
+ return true ;
1260
+ }
1261
+
1211
1262
bool QgsGeorefPluginGui::writePDFReportFile ( const QString& fileName, const QgsGeorefTransform& transform )
1212
1263
{
1213
1264
if ( !mCanvas )
@@ -1250,7 +1301,24 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
1250
1301
titleLabel->setFrame ( false );
1251
1302
1252
1303
// composer map
1253
- QgsComposerMap* composerMap = new QgsComposerMap ( composition, 2 , titleLabel->rect ().bottom () + titleLabel->transform ().dy (), 206 , 277 );
1304
+ QgsRectangle canvasExtent = mCanvas ->extent ();
1305
+ // calculate width and height considering extent aspect ratio and max Width 206, maxHeight 70
1306
+ double widthExtentRatio = 206 / canvasExtent.width ();
1307
+ double heightExtentRatio = 70 / canvasExtent.height ();
1308
+ double mapWidthMM = 0 ;
1309
+ double mapHeightMM = 0 ;
1310
+ if ( widthExtentRatio < heightExtentRatio )
1311
+ {
1312
+ mapWidthMM = 206 ;
1313
+ mapHeightMM = 206 / canvasExtent.width () * canvasExtent.height ();
1314
+ }
1315
+ else
1316
+ {
1317
+ mapHeightMM = 70 ;
1318
+ mapWidthMM = 70 / canvasExtent.height () * canvasExtent.width ();
1319
+ }
1320
+
1321
+ QgsComposerMap* composerMap = new QgsComposerMap ( composition, 2 , titleLabel->rect ().bottom () + titleLabel->transform ().dy (), mapWidthMM, mapHeightMM );
1254
1322
composerMap->setLayerSet ( canvasRenderer->layerSet () );
1255
1323
composerMap->setNewExtent ( mCanvas ->extent () );
1256
1324
composerMap->setMapCanvas ( mCanvas );
@@ -1266,26 +1334,9 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
1266
1334
// transformation that involves only scaling and rotation (linear or helmert) ?
1267
1335
bool wldTransform = transform.getOriginScaleRotation ( origin, scaleX, scaleY, rotation );
1268
1336
1269
- // consider rotation in scale parameter
1270
- double wldScaleX = scaleX;
1271
- double wldScaleY = scaleY;
1272
- if ( wldTransform && !doubleNear ( rotation, 0.0 ) )
1273
- {
1274
- wldScaleX *= cos ( rotation );
1275
- wldScaleY *= cos ( rotation );
1276
- }
1277
-
1278
1337
if ( wldTransform )
1279
1338
{
1280
- QString parameterTitle = tr ( " Transformation parameters" );
1281
- if ( transform.transformParametrisation () == QgsGeorefTransform::Helmert )
1282
- {
1283
- parameterTitle += " (Helmert)" ;
1284
- }
1285
- else if ( transform.transformParametrisation () == QgsGeorefTransform::Linear )
1286
- {
1287
- parameterTitle += " (Linear)" ;
1288
- }
1339
+ QString parameterTitle = tr ( " Transformation parameters" ) + QString ( " (" ) + convertTransformEnumToString ( transform.transformParametrisation () ) + QString ( " )" );
1289
1340
parameterLabel = new QgsComposerLabel ( composition );
1290
1341
parameterLabel->setFont ( titleFont );
1291
1342
parameterLabel->setText ( parameterTitle );
@@ -1304,29 +1355,9 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
1304
1355
}
1305
1356
}
1306
1357
1307
- // calculate mean error (in map units)
1358
+ // calculate mean error
1308
1359
double meanError = 0 ;
1309
- if ( nPointsEnabled > 2 )
1310
- {
1311
- double sumVxSquare = 0 ;
1312
- double sumVySquare = 0 ;
1313
- double resXMap, resYMap;
1314
-
1315
- QgsGCPList::const_iterator gcpIt = mPoints .constBegin ();
1316
- for ( ; gcpIt != mPoints .constEnd (); ++gcpIt )
1317
- {
1318
- if (( *gcpIt )->isEnabled () )
1319
- {
1320
- resXMap = ( *gcpIt )->residual ().x () * wldScaleX;
1321
- resYMap = ( *gcpIt )->residual ().y () * wldScaleY;
1322
- sumVxSquare += ( resXMap * resXMap );
1323
- sumVySquare += ( resYMap * resYMap );
1324
- }
1325
- }
1326
-
1327
- meanError = sqrt (( sumVxSquare + sumVySquare ) / ( 2 * nPointsEnabled - 4 ) ) * sqrt ( 2.0 );
1328
- }
1329
-
1360
+ calculateMeanError ( meanError );
1330
1361
1331
1362
parameterTable = new QgsComposerTextTable ( composition );
1332
1363
parameterTable->setHeaderFont ( tableHeaderFont );
@@ -1366,7 +1397,7 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
1366
1397
// convert residual scale bar plot to map units if scaling is equal in x- and y-direction (e.g. helmert)
1367
1398
if ( wldTransform )
1368
1399
{
1369
- if ( doubleNear ( wldScaleX, wldScaleY ) )
1400
+ if ( doubleNear ( scaleX, scaleX ) )
1370
1401
{
1371
1402
resPlotItem->setPixelToMapUnits ( scaleX );
1372
1403
resPlotItem->setConvertScaleToMapUnits ( true );
@@ -1394,17 +1425,7 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
1394
1425
{
1395
1426
QStringList currentGCPStrings;
1396
1427
QPointF residual = ( *gcpIt )->residual ();
1397
- double residualX = residual.x ();
1398
- if ( wldTransform )
1399
- {
1400
- residualX *= wldScaleX;
1401
- }
1402
- double residualY = residual.y ();
1403
- if ( wldTransform )
1404
- {
1405
- residualY *= wldScaleY;
1406
- }
1407
- double residualTot = sqrt ( residualX * residualX + residualY * residualY );
1428
+ double residualTot = sqrt ( residual.x () * residual.x () + residual.y () * residual.y () );
1408
1429
1409
1430
currentGCPStrings << QString::number (( *gcpIt )->id () );
1410
1431
if (( *gcpIt )->isEnabled () )
@@ -1416,7 +1437,7 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
1416
1437
currentGCPStrings << tr ( " no" );
1417
1438
}
1418
1439
currentGCPStrings << QString::number (( *gcpIt )->pixelCoords ().x (), ' f' , 2 ) << QString::number (( *gcpIt )->pixelCoords ().y (), ' f' , 2 ) << QString::number (( *gcpIt )->mapCoords ().x (), ' f' , 2 )\
1419
- << QString::number (( *gcpIt )->mapCoords ().y (), ' f' , 2 ) << QString::number ( residualX ) << QString::number ( residualY ) << QString::number ( residualTot );
1440
+ << QString::number (( *gcpIt )->mapCoords ().y (), ' f' , 2 ) << QString::number ( residual. x () ) << QString::number ( residual. y () ) << QString::number ( residualTot );
1420
1441
gcpTable->addRow ( currentGCPStrings );
1421
1442
}
1422
1443
@@ -1443,6 +1464,35 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
1443
1464
return true ;
1444
1465
}
1445
1466
1467
+ void QgsGeorefPluginGui::updateTransformParamLabel ()
1468
+ {
1469
+ if ( !mTransformParamLabel )
1470
+ {
1471
+ return ;
1472
+ }
1473
+
1474
+ QString transformName = convertTransformEnumToString ( mGeorefTransform .transformParametrisation () );
1475
+ QString labelString = tr ( " Transform: " ) + transformName;
1476
+
1477
+ QgsPoint origin;
1478
+ double scaleX, scaleY, rotation;
1479
+ if ( mGeorefTransform .getOriginScaleRotation ( origin, scaleX, scaleY, rotation ) )
1480
+ {
1481
+ labelString += " " ;
1482
+ labelString += tr ( " Translation (%1, %2)" ).arg ( origin.x () ).arg ( origin.y () ); labelString += " " ;
1483
+ labelString += tr ( " Scale (%1, %2)" ).arg ( scaleX ).arg ( scaleY ); labelString += " " ;
1484
+ labelString += tr ( " Rotation: %1" ).arg ( rotation );
1485
+ }
1486
+
1487
+ double meanError = 0 ;
1488
+ if ( calculateMeanError ( meanError ) )
1489
+ {
1490
+ labelString += " " ;
1491
+ labelString += tr ( " Mean error: %1" ).arg ( meanError );
1492
+ }
1493
+ mTransformParamLabel ->setText ( labelString );
1494
+ }
1495
+
1446
1496
// Gdal script
1447
1497
void QgsGeorefPluginGui::showGDALScript ( int argNum... )
1448
1498
{
@@ -1605,22 +1655,20 @@ bool QgsGeorefPluginGui::checkReadyGeoref()
1605
1655
1606
1656
bool QgsGeorefPluginGui::updateGeorefTransform ()
1607
1657
{
1608
- if ( mGCPsDirty || !mGeorefTransform .parametersInitialized () )
1609
- {
1610
- std::vector<QgsPoint> mapCoords, pixelCoords;
1611
- if ( mGCPListWidget ->gcpList () )
1612
- mGCPListWidget ->gcpList ()->createGCPVectors ( mapCoords, pixelCoords );
1613
- else
1614
- return false ;
1615
-
1616
- // Parametrize the transform with GCPs
1617
- if ( !mGeorefTransform .updateParametersFromGCPs ( mapCoords, pixelCoords ) )
1618
- {
1619
- return false ;
1620
- }
1658
+ std::vector<QgsPoint> mapCoords, pixelCoords;
1659
+ if ( mGCPListWidget ->gcpList () )
1660
+ mGCPListWidget ->gcpList ()->createGCPVectors ( mapCoords, pixelCoords );
1661
+ else
1662
+ return false ;
1621
1663
1622
- mGCPsDirty = false ;
1664
+ // Parametrize the transform with GCPs
1665
+ if ( !mGeorefTransform .updateParametersFromGCPs ( mapCoords, pixelCoords ) )
1666
+ {
1667
+ return false ;
1623
1668
}
1669
+
1670
+ mGCPsDirty = false ;
1671
+ updateTransformParamLabel ();
1624
1672
return true ;
1625
1673
}
1626
1674
0 commit comments