28
28
#include < QPushButton>
29
29
#include < QSettings>
30
30
#include < QTextStream>
31
+ #include < QPen>
32
+ #include < QStringList>
33
+ #include < QList>
31
34
32
35
#include " qgisinterface.h"
33
36
#include " qgslegendinterface.h"
62
65
63
66
#include " qgsgeorefplugingui.h"
64
67
65
-
66
68
QgsGeorefDockWidget::QgsGeorefDockWidget ( const QString & title, QWidget * parent, Qt::WindowFlags flags )
67
69
: QDockWidget( title, parent, flags )
68
70
{
@@ -310,7 +312,7 @@ bool QgsGeorefPluginGui::getTransformSettings()
310
312
}
311
313
312
314
d.getTransformSettings ( mTransformParam , mResamplingMethod , mCompressionMethod ,
313
- mModifiedRasterFileName , mProjection , mPdfOutputFile , mUseZeroForTrans , mLoadInQgis , mUserResX , mUserResY );
315
+ mModifiedRasterFileName , mProjection , mPdfOutputMapFile , mPdfOutputFile , mUseZeroForTrans , mLoadInQgis , mUserResX , mUserResY );
314
316
mTransformParamLabel ->setText ( tr ( " Transform: " ) + convertTransformEnumToString ( mTransformParam ) );
315
317
mGeorefTransform .selectTransformParametrisation ( mTransformParam );
316
318
mGCPListWidget ->setGeorefTransform ( &mGeorefTransform );
@@ -1219,6 +1221,12 @@ bool QgsGeorefPluginGui::georeference()
1219
1221
{
1220
1222
writePDFReportFile ( mPdfOutputFile , mGeorefTransform );
1221
1223
}
1224
+ if ( success && !mPdfOutputMapFile .isEmpty () )
1225
+ {
1226
+ writePDFMapFile ( mPdfOutputMapFile , mGeorefTransform );
1227
+ }
1228
+
1229
+
1222
1230
}
1223
1231
else // Helmert, Polinom 1, Polinom 2, Polinom 3
1224
1232
{
@@ -1243,6 +1251,10 @@ bool QgsGeorefPluginGui::georeference()
1243
1251
{
1244
1252
writePDFReportFile ( mPdfOutputFile , mGeorefTransform );
1245
1253
}
1254
+ if ( !mPdfOutputMapFile .isEmpty () )
1255
+ {
1256
+ writePDFMapFile ( mPdfOutputMapFile , mGeorefTransform );
1257
+ }
1246
1258
return true ;
1247
1259
}
1248
1260
}
@@ -1328,6 +1340,112 @@ bool QgsGeorefPluginGui::calculateMeanError( double& error ) const
1328
1340
return true ;
1329
1341
}
1330
1342
1343
+ bool QgsGeorefPluginGui::writePDFMapFile ( const QString& fileName, const QgsGeorefTransform& transform )
1344
+ {
1345
+ if ( !mCanvas )
1346
+ {
1347
+ return false ;
1348
+ }
1349
+
1350
+ QgsMapRenderer* canvasRenderer = mCanvas ->mapRenderer ();
1351
+ if ( !canvasRenderer )
1352
+ {
1353
+ return false ;
1354
+ }
1355
+
1356
+ QgsRasterLayer *rlayer = ( QgsRasterLayer* ) mCanvas ->layer ( 0 );
1357
+ if ( !rlayer )
1358
+ {
1359
+ return false ;
1360
+ }
1361
+ double mapRatio = rlayer->extent ().width () / rlayer->extent ().height ();
1362
+
1363
+ QPrinter printer;
1364
+ printer.setOutputFormat ( QPrinter::PdfFormat );
1365
+ printer.setOutputFileName ( fileName );
1366
+
1367
+ QSettings s;
1368
+ double paperWidth = s.value ( " /Plugin-GeoReferencer/Config/WidthPDFMap" ).toDouble ();
1369
+ double paperHeight = s.value ( " /Plugin-GeoReferencer/Config/HeightPDFMap" ).toDouble ();
1370
+
1371
+ // create composition
1372
+ QgsComposition* composition = new QgsComposition ( mCanvas ->mapRenderer () );
1373
+ if ( mapRatio >= 1 )
1374
+ {
1375
+ composition->setPaperSize ( paperHeight, paperWidth );
1376
+ }
1377
+ else
1378
+ {
1379
+ composition->setPaperSize ( paperWidth, paperHeight );
1380
+ }
1381
+ composition->setPrintResolution ( 300 );
1382
+ printer.setPaperSize ( QSizeF ( composition->paperWidth (), composition->paperHeight () ), QPrinter::Millimeter );
1383
+
1384
+ double leftMargin = 8 ;
1385
+ double topMargin = 8 ;
1386
+ double contentWidth = composition->paperWidth () - 2 * leftMargin;
1387
+ double contentHeight = composition->paperHeight () - 2 * topMargin;
1388
+ double contentRatio = contentWidth / contentHeight;
1389
+
1390
+ // composer map
1391
+ QgsComposerMap* composerMap = new QgsComposerMap ( composition, leftMargin, topMargin, contentWidth, contentHeight );
1392
+ composerMap->setKeepLayerSet ( true );
1393
+ QStringList list;
1394
+ list.append ( canvasRenderer->layerSet ()[0 ] );
1395
+ composerMap->setLayerSet ( list );
1396
+
1397
+ double xcenter = rlayer->extent ().center ().x ();
1398
+ double ycenter = rlayer->extent ().center ().y ();
1399
+
1400
+ QgsRectangle rect;
1401
+ if ( mapRatio > contentRatio )
1402
+ {
1403
+ rect = QgsRectangle ( 0 , ycenter - ( rlayer->extent ().width () / contentRatio ) / 2 , rlayer->extent ().width (), ycenter + ( rlayer->extent ().width () / contentRatio ) / 2 );
1404
+ }
1405
+ if ( mapRatio <= contentRatio )
1406
+ {
1407
+ rect = QgsRectangle ( xcenter - ( rlayer->extent ().height () * contentRatio / 2 ), -1 * rlayer->extent ().height (), xcenter + ( rlayer->extent ().height () * contentRatio / 2 ), 0 );
1408
+ }
1409
+
1410
+ composerMap->setNewExtent ( rect );
1411
+ composition->addItem ( composerMap );
1412
+ printer.setFullPage ( true );
1413
+ printer.setColorMode ( QPrinter::Color );
1414
+
1415
+ QString residualUnits;
1416
+ if ( s.value ( " /Plugin-GeoReferencer/Config/ResidualUnits" ) == " mapUnits" && mGeorefTransform .providesAccurateInverseTransformation () )
1417
+ {
1418
+ residualUnits = tr ( " map units" );
1419
+ }
1420
+ else
1421
+ {
1422
+ residualUnits = tr ( " pixels" );
1423
+ }
1424
+
1425
+ // residual plot
1426
+ QgsResidualPlotItem* resPlotItem = new QgsResidualPlotItem ( composition );
1427
+ composition->addItem ( resPlotItem );
1428
+ resPlotItem->setSceneRect ( QRectF ( leftMargin, topMargin, contentWidth, contentHeight ) );
1429
+ resPlotItem->setExtent ( rect );
1430
+ resPlotItem->setGCPList ( mPoints );
1431
+ resPlotItem->setConvertScaleToMapUnits ( residualUnits == tr ( " map units" ) );
1432
+
1433
+ printer.setResolution ( composition->printResolution () );
1434
+ QPainter p ( &printer );
1435
+ composition->setPlotStyle ( QgsComposition::Print );
1436
+ QRectF paperRectMM = printer.pageRect ( QPrinter::Millimeter );
1437
+ QRectF paperRectPixel = printer.pageRect ( QPrinter::DevicePixel );
1438
+ composition->render ( &p, paperRectPixel, paperRectMM );
1439
+
1440
+ delete resPlotItem;
1441
+ delete composerMap;
1442
+ delete composition;
1443
+
1444
+ return true ;
1445
+ }
1446
+
1447
+
1448
+
1331
1449
bool QgsGeorefPluginGui::writePDFReportFile ( const QString& fileName, const QgsGeorefTransform& transform )
1332
1450
{
1333
1451
if ( !mCanvas )
@@ -1475,7 +1593,7 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
1475
1593
gcpTable->setHeaderFont ( tableHeaderFont );
1476
1594
gcpTable->setContentFont ( tableContentFont );
1477
1595
QStringList gcpHeader;
1478
- gcpHeader << " id" << " enabled" << " pixelX" << " pixelY" << " mapX" << " mapY" << " resX[" + residualUnits + " ]" << " resY[" + residualUnits + " ]" << " resTot[" + residualUnits + " ]" ;
1596
+ gcpHeader << " id" << " enabled" << " pixelX" << " pixelY" << " mapX" << " mapY" << " resX [" + residualUnits + " ]" << " resY [" + residualUnits + " ]" << " resTot [" + residualUnits + " ]" ;
1479
1597
gcpTable->setHeaderLabels ( gcpHeader );
1480
1598
1481
1599
QgsGCPList::const_iterator gcpIt = mPoints .constBegin ();
@@ -1494,8 +1612,8 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
1494
1612
{
1495
1613
currentGCPStrings << tr ( " no" );
1496
1614
}
1497
- currentGCPStrings << QString::number (( *gcpIt )->pixelCoords ().x (), ' f' , 2 ) << QString::number (( *gcpIt )->pixelCoords ().y (), ' f' , 2 ) << QString::number (( *gcpIt )->mapCoords ().x (), ' f' , 2 )\
1498
- << QString::number (( *gcpIt )->mapCoords ().y (), ' f' , 2 ) << QString::number ( residual.x () ) << QString::number ( residual.y () ) << QString::number ( residualTot );
1615
+ currentGCPStrings << QString::number (( *gcpIt )->pixelCoords ().x (), ' f' , 0 ) << QString::number (( *gcpIt )->pixelCoords ().y (), ' f' , 0 ) << QString::number (( *gcpIt )->mapCoords ().x (), ' f' , 3 )\
1616
+ << QString::number (( *gcpIt )->mapCoords ().y (), ' f' , 3 ) << QString::number ( residual.x () ) << QString::number ( residual.y () ) << QString::number ( residualTot );
1499
1617
gcpTable->addRow ( currentGCPStrings );
1500
1618
}
1501
1619
0 commit comments