Skip to content

Commit

Permalink
[FEATURE] Add option to simplify geometries when exporting canvas to PDF
Browse files Browse the repository at this point in the history
Reduces output file size by removing redundant vertices given export
DPI settings
  • Loading branch information
nyalldawson committed Aug 19, 2019
1 parent 7f00ea9 commit 913f53a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
12 changes: 12 additions & 0 deletions src/app/qgsmapsavedialog.cpp
Expand Up @@ -137,6 +137,7 @@ QgsMapSaveDialog::QgsMapSaveDialog( QWidget *parent, QgsMapCanvas *mapCanvas, co
case Image:
{
mGeoPDFGroupBox->hide();
mSimplifyGeometriesCheckbox->hide();
QPushButton *button = new QPushButton( tr( "Copy to Clipboard" ) );
buttonBox->addButton( button, QDialogButtonBox::ResetRole );
connect( button, &QPushButton::clicked, this, &QgsMapSaveDialog::copyToClipboard );
Expand Down Expand Up @@ -474,6 +475,17 @@ void QgsMapSaveDialog::onAccepted()
QgsMapSettings ms = QgsMapSettings();
applyMapSettings( ms );

if ( mSimplifyGeometriesCheckbox->isChecked() )
{
QgsVectorSimplifyMethod simplifyMethod;
simplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::GeometrySimplification );
simplifyMethod.setForceLocalOptimization( true );
// we use SnappedToGridGlobal, because it avoids gaps and slivers between previously adjacent polygons
simplifyMethod.setSimplifyAlgorithm( QgsVectorSimplifyMethod::SnappedToGridGlobal );
simplifyMethod.setThreshold( 0.1f ); // (pixels). We are quite conservative here. This could possibly be bumped all the way up to 1. But let's play it safe.
ms.setSimplifyMethod( simplifyMethod );
}

QgsAbstractGeoPdfExporter::ExportDetails geoPdfExportDetails;
if ( mGeoPDFGroupBox->isChecked() )
{
Expand Down
22 changes: 16 additions & 6 deletions src/ui/qgsmapsavedialog.ui
Expand Up @@ -15,7 +15,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout" rowstretch="0,0,0,0,0,0,0,0,0,0,0">
<layout class="QGridLayout" name="gridLayout" rowstretch="0,0,0,0,0,0,0,0,0,0,0,0">
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
Expand Down Expand Up @@ -43,7 +43,7 @@
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<item row="9" column="0" colspan="2">
<widget class="QGroupBox" name="mGeoPDFGroupBox">
<property name="title">
<string>Create Geospatial PDF (GeoPDF)</string>
Expand Down Expand Up @@ -97,15 +97,15 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item row="1" column="0">
<item row="2" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>133</height>
<height>102</height>
</size>
</property>
</spacer>
Expand Down Expand Up @@ -158,7 +158,7 @@
</property>
</widget>
</item>
<item row="9" column="0" colspan="2">
<item row="10" column="0" colspan="2">
<widget class="QCheckBox" name="mSaveAsRaster">
<property name="visible">
<bool>false</bool>
Expand Down Expand Up @@ -287,13 +287,23 @@ Rasterizing the map is recommended when such effects are used.</string>
</property>
</widget>
</item>
<item row="10" column="0" colspan="2">
<item row="11" column="0" colspan="2">
<widget class="QLabel" name="mInfo">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="QCheckBox" name="mSimplifyGeometriesCheckbox">
<property name="text">
<string>Simplify geometries to reduce output file size</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down

0 comments on commit 913f53a

Please sign in to comment.