Skip to content

Commit 93f6de8

Browse files
author
mhugent
committed
Apply patch #2948 from Stefan Ziegler (PDF map for georeferencer)
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14192 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 15f272f commit 93f6de8

8 files changed

+252
-37
lines changed

src/plugins/georeferencer/qgsgeorefconfigdialog.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
/* $Id$ */
1616
#include <QCloseEvent>
1717
#include <QSettings>
18+
#include <QSizeF>
1819

1920
#include "qgsgeorefconfigdialog.h"
2021

@@ -24,6 +25,35 @@ QgsGeorefConfigDialog::QgsGeorefConfigDialog( QWidget *parent ) :
2425
setupUi( this );
2526

2627
readSettings();
28+
29+
mPaperSizeComboBox->addItem( tr( "A5 (148x210 mm)" ), QSizeF( 148, 210 ) );
30+
mPaperSizeComboBox->addItem( tr( "A4 (210x297 mm)" ), QSizeF( 210, 297 ) );
31+
mPaperSizeComboBox->addItem( tr( "A3 (297x420 mm)" ), QSizeF( 297, 420 ) );
32+
mPaperSizeComboBox->addItem( tr( "A2 (420x594 mm)" ), QSizeF( 420, 594 ) );
33+
mPaperSizeComboBox->addItem( tr( "A1 (594x841 mm)" ), QSizeF( 594, 841 ) );
34+
mPaperSizeComboBox->addItem( tr( "A0 (841x1189 mm)" ), QSizeF( 841, 1189 ) );
35+
mPaperSizeComboBox->addItem( tr( "B5 (176 x 250 mm)" ), QSizeF( 176, 250 ) );
36+
mPaperSizeComboBox->addItem( tr( "B4 (250 x 353 mm)" ), QSizeF( 250, 353 ) );
37+
mPaperSizeComboBox->addItem( tr( "B3 (353 x 500 mm)" ), QSizeF( 353, 500 ) );
38+
mPaperSizeComboBox->addItem( tr( "B2 (500 x 707 mm)" ), QSizeF( 500, 707 ) );
39+
mPaperSizeComboBox->addItem( tr( "B1 (707 x 1000 mm)" ), QSizeF( 707, 1000 ) );
40+
mPaperSizeComboBox->addItem( tr( "B0 (1000 x 1414 mm)" ), QSizeF( 1000, 1414 ) );
41+
// North american formats
42+
mPaperSizeComboBox->addItem( tr( "Legal (8.5x14 inches)" ), QSizeF( 215.9, 355.6 ) );
43+
mPaperSizeComboBox->addItem( tr( "ANSI A (Letter; 8.5x11 inches)" ), QSizeF( 215.9, 279.4 ) );
44+
mPaperSizeComboBox->addItem( tr( "ANSI B (Tabloid; 11x17 inches)" ), QSizeF( 279.4, 431.8 ) );
45+
mPaperSizeComboBox->addItem( tr( "ANSI C (17x22 inches)" ), QSizeF( 431.8, 558.8 ) );
46+
mPaperSizeComboBox->addItem( tr( "ANSI D (22x34 inches)" ), QSizeF( 558.8, 863.6 ) );
47+
mPaperSizeComboBox->addItem( tr( "ANSI E (34x44 inches)" ), QSizeF( 863.6, 1117.6 ) );
48+
mPaperSizeComboBox->addItem( tr( "Arch A (9x12 inches)" ), QSizeF( 228.6, 304.8 ) );
49+
mPaperSizeComboBox->addItem( tr( "Arch B (12x18 inches)" ), QSizeF( 304.8, 457.2 ) );
50+
mPaperSizeComboBox->addItem( tr( "Arch C (18x24 inches)" ), QSizeF( 457.2, 609.6 ) );
51+
mPaperSizeComboBox->addItem( tr( "Arch D (24x36 inches)" ), QSizeF( 609.6, 914.4 ) );
52+
mPaperSizeComboBox->addItem( tr( "Arch E (36x48 inches)" ), QSizeF( 914.4, 1219.2 ) );
53+
mPaperSizeComboBox->addItem( tr( "Arch E1 (30x42 inches)" ) , QSizeF( 762, 1066.8 ) );
54+
55+
mPaperSizeComboBox->setCurrentIndex( 2 ); //A3
56+
2757
}
2858

2959
void QgsGeorefConfigDialog::changeEvent( QEvent *e )
@@ -109,4 +139,9 @@ void QgsGeorefConfigDialog::writeSettings()
109139
}
110140
s.setValue( "/Plugin-GeoReferencer/Config/LeftMarginPDF", mLeftMarginSpinBox->value() );
111141
s.setValue( "/Plugin-GeoReferencer/Config/RightMarginPDF", mRightMarginSpinBox->value() );
142+
143+
s.setValue( "/Plugin-GeoReferencer/Config/WidthPDFMap", mPaperSizeComboBox->itemData( mPaperSizeComboBox->currentIndex() ).toSizeF().width() );
144+
s.setValue( "/Plugin-GeoReferencer/Config/HeightPDFMap", mPaperSizeComboBox->itemData( mPaperSizeComboBox->currentIndex() ).toSizeF().height() );
145+
112146
}
147+

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>249</width>
10-
<height>344</height>
9+
<width>309</width>
10+
<height>468</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -108,14 +108,14 @@
108108
</layout>
109109
</widget>
110110
</item>
111-
<item row="3" column="0">
111+
<item row="4" column="0">
112112
<widget class="QCheckBox" name="mShowDockedCheckBox">
113113
<property name="text">
114114
<string>Show Georeferencer window docked</string>
115115
</property>
116116
</widget>
117117
</item>
118-
<item row="4" column="0">
118+
<item row="5" column="0">
119119
<widget class="QDialogButtonBox" name="buttonBox">
120120
<property name="orientation">
121121
<enum>Qt::Horizontal</enum>
@@ -125,6 +125,29 @@
125125
</property>
126126
</widget>
127127
</item>
128+
<item row="3" column="0">
129+
<widget class="QGroupBox" name="groupBox">
130+
<property name="title">
131+
<string>PDF map</string>
132+
</property>
133+
<layout class="QGridLayout" name="gridLayout_5">
134+
<item row="0" column="0">
135+
<layout class="QHBoxLayout" name="horizontalLayout_3">
136+
<item>
137+
<widget class="QLabel" name="label_3">
138+
<property name="text">
139+
<string>Paper size</string>
140+
</property>
141+
</widget>
142+
</item>
143+
<item>
144+
<widget class="QComboBox" name="mPaperSizeComboBox"/>
145+
</item>
146+
</layout>
147+
</item>
148+
</layout>
149+
</widget>
150+
</item>
128151
</layout>
129152
</widget>
130153
<resources/>

src/plugins/georeferencer/qgsgeorefplugingui.cpp

+123-5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
#include <QPushButton>
2929
#include <QSettings>
3030
#include <QTextStream>
31+
#include <QPen>
32+
#include <QStringList>
33+
#include <QList>
3134

3235
#include "qgisinterface.h"
3336
#include "qgslegendinterface.h"
@@ -62,7 +65,6 @@
6265

6366
#include "qgsgeorefplugingui.h"
6467

65-
6668
QgsGeorefDockWidget::QgsGeorefDockWidget( const QString & title, QWidget * parent, Qt::WindowFlags flags )
6769
: QDockWidget( title, parent, flags )
6870
{
@@ -310,7 +312,7 @@ bool QgsGeorefPluginGui::getTransformSettings()
310312
}
311313

312314
d.getTransformSettings( mTransformParam, mResamplingMethod, mCompressionMethod,
313-
mModifiedRasterFileName, mProjection, mPdfOutputFile, mUseZeroForTrans, mLoadInQgis, mUserResX, mUserResY );
315+
mModifiedRasterFileName, mProjection, mPdfOutputMapFile, mPdfOutputFile, mUseZeroForTrans, mLoadInQgis, mUserResX, mUserResY );
314316
mTransformParamLabel->setText( tr( "Transform: " ) + convertTransformEnumToString( mTransformParam ) );
315317
mGeorefTransform.selectTransformParametrisation( mTransformParam );
316318
mGCPListWidget->setGeorefTransform( &mGeorefTransform );
@@ -1219,6 +1221,12 @@ bool QgsGeorefPluginGui::georeference()
12191221
{
12201222
writePDFReportFile( mPdfOutputFile, mGeorefTransform );
12211223
}
1224+
if ( success && !mPdfOutputMapFile.isEmpty() )
1225+
{
1226+
writePDFMapFile( mPdfOutputMapFile, mGeorefTransform );
1227+
}
1228+
1229+
12221230
}
12231231
else // Helmert, Polinom 1, Polinom 2, Polinom 3
12241232
{
@@ -1243,6 +1251,10 @@ bool QgsGeorefPluginGui::georeference()
12431251
{
12441252
writePDFReportFile( mPdfOutputFile, mGeorefTransform );
12451253
}
1254+
if ( !mPdfOutputMapFile.isEmpty() )
1255+
{
1256+
writePDFMapFile( mPdfOutputMapFile, mGeorefTransform );
1257+
}
12461258
return true;
12471259
}
12481260
}
@@ -1328,6 +1340,112 @@ bool QgsGeorefPluginGui::calculateMeanError( double& error ) const
13281340
return true;
13291341
}
13301342

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+
13311449
bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsGeorefTransform& transform )
13321450
{
13331451
if ( !mCanvas )
@@ -1475,7 +1593,7 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
14751593
gcpTable->setHeaderFont( tableHeaderFont );
14761594
gcpTable->setContentFont( tableContentFont );
14771595
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 + "]";
14791597
gcpTable->setHeaderLabels( gcpHeader );
14801598

14811599
QgsGCPList::const_iterator gcpIt = mPoints.constBegin();
@@ -1494,8 +1612,8 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
14941612
{
14951613
currentGCPStrings << tr( "no" );
14961614
}
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 );
14991617
gcpTable->addRow( currentGCPStrings );
15001618
}
15011619

src/plugins/georeferencer/qgsgeorefplugingui.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
103103
void updateMouseCoordinatePrecision();
104104

105105
// when one Layer is removed
106-
void layerWillBeRemoved ( QString theLayerId );
106+
void layerWillBeRemoved( QString theLayerId );
107107
void extentsChanged(); // Use for need add again Raster (case above)
108108

109109
bool updateGeorefTransform();
@@ -127,7 +127,7 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
127127
void setupConnections();
128128

129129
// Mapcanvas Plugin
130-
void addRaster(QString file);
130+
void addRaster( QString file );
131131

132132
// settings
133133
void readSettings();
@@ -142,6 +142,7 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
142142
bool georeference();
143143
bool writeWorldFile( QgsPoint origin, double pixelXSize, double pixelYSize, double rotation );
144144
bool writePDFReportFile( const QString& fileName, const QgsGeorefTransform& transform );
145+
bool writePDFMapFile( const QString& fileName, const QgsGeorefTransform& transform );
145146
void updateTransformParamLabel();
146147

147148
// gdal script
@@ -201,6 +202,7 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
201202
QString mGCPpointsFileName;
202203
QString mProjection;
203204
QString mPdfOutputFile;
205+
QString mPdfOutputMapFile;
204206
double mUserResX, mUserResY; // User specified target scale
205207

206208
QgsGeorefTransform::TransformParametrisation mTransformParam;

src/plugins/georeferencer/qgsresidualplotitem.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,10 @@ void QgsResidualPlotItem::paint( QPainter* painter, const QStyleOptionGraphicsIt
4444
double widthMM = rect().width();
4545
double heightMM = rect().height();
4646

47-
QPen enabledPen( QColor( 0, 0, 255, 255 ) );
48-
enabledPen.setWidthF( 0.4 );
49-
QPen disabledPen( QColor( 0, 0, 255, 127 ) );
50-
disabledPen.setWidthF( 0.3 );
51-
QBrush enabledBrush( QColor( 255, 0, 0, 255 ) );
52-
QBrush disabledBrush( QColor( 255, 0, 0, 127 ) );
47+
QPen enabledPen( QColor( 255, 0, 0, 255 ), 0.3, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin );
48+
QPen disabledPen( QColor( 255, 0, 0, 85 ), 0.2, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin );
49+
QBrush enabledBrush( QColor( 255, 255, 255, 255 ) );
50+
QBrush disabledBrush( QColor( 255, 255, 255, 127 ) );
5351

5452
//draw all points and collect minimal mm/pixel ratio
5553
double minMMPixelRatio = DBL_MAX;
@@ -74,7 +72,7 @@ void QgsResidualPlotItem::paint( QPainter* painter, const QStyleOptionGraphicsIt
7472
painter->setPen( disabledPen );
7573
painter->setBrush( disabledBrush );
7674
}
77-
painter->drawRect( QRectF( gcpItemMMX - 1, gcpItemMMY - 1, 2, 2 ) );
75+
painter->drawRect( QRectF( gcpItemMMX - 0.5, gcpItemMMY - 0.5, 1, 1 ) );
7876
drawText( painter, gcpItemMMX + 2, gcpItemMMY + 2, QString::number(( *gcpIt )->id() ), QFont() );
7977

8078
mmPixelRatio = maxMMToPixelRatioForGCP( *gcpIt, gcpItemMMX, gcpItemMMY );

0 commit comments

Comments
 (0)