From 913f53a53f55f02f4091f989f984f53fff23bf8c Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Mon, 19 Aug 2019 09:16:12 +1000 Subject: [PATCH] [FEATURE] Add option to simplify geometries when exporting canvas to PDF Reduces output file size by removing redundant vertices given export DPI settings --- src/app/qgsmapsavedialog.cpp | 12 ++++++++++++ src/ui/qgsmapsavedialog.ui | 22 ++++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/app/qgsmapsavedialog.cpp b/src/app/qgsmapsavedialog.cpp index feaf15651de0..566c542f6b08 100644 --- a/src/app/qgsmapsavedialog.cpp +++ b/src/app/qgsmapsavedialog.cpp @@ -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 ); @@ -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() ) { diff --git a/src/ui/qgsmapsavedialog.ui b/src/ui/qgsmapsavedialog.ui index 07cc9c5c32f6..6c851a85b572 100644 --- a/src/ui/qgsmapsavedialog.ui +++ b/src/ui/qgsmapsavedialog.ui @@ -15,7 +15,7 @@ - + @@ -43,7 +43,7 @@ - + Create Geospatial PDF (GeoPDF) @@ -97,7 +97,7 @@ 0 - + Qt::Vertical @@ -105,7 +105,7 @@ 20 - 133 + 102 @@ -158,7 +158,7 @@ - + false @@ -287,13 +287,23 @@ Rasterizing the map is recommended when such effects are used. - + false + + + + Simplify geometries to reduce output file size + + + true + + +