QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsabstractgeopdfexporter.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsabstractgeopdfexporter.h
3  --------------------------
4  begin : August 2019
5  copyright : (C) 2019 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 #ifndef QGSABSTRACTGEOPDFEXPORTER_H
17 #define QGSABSTRACTGEOPDFEXPORTER_H
18 
19 #include "qgis_core.h"
20 #include <QList>
21 #include <QTemporaryDir>
22 #include <QMutex>
23 #include <QDateTime>
24 #include <QPainter>
25 
26 #include "qgsfeature.h"
28 #include "qgspolygon.h"
29 
30 #define SIP_NO_FILE
31 
32 
33 class QgsGeoPdfRenderedFeatureHandler;
34 
54 class CORE_EXPORT QgsAbstractGeoPdfExporter
55 {
56  public:
57 
64  static bool geoPDFCreationAvailable();
65 
72  static QString geoPDFAvailabilityExplanation();
73 
78 
79  virtual ~QgsAbstractGeoPdfExporter() = default;
80 
85  {
86 
90  RenderedFeature() = default;
91 
95  RenderedFeature( const QgsFeature &feature, const QgsGeometry &renderedBounds )
96  : feature( feature )
97  , renderedBounds( renderedBounds )
98  {}
99 
104 
109  };
110 
116  struct CORE_EXPORT ComponentLayerDetail
117  {
118 
120  QString name;
121 
123  QString mapLayerId;
124 
126  QString group;
127 
129  QString sourcePdfPath;
130 
132  QPainter::CompositionMode compositionMode = QPainter::CompositionMode_SourceOver;
133 
135  double opacity = 1.0;
136 
137  };
138 
145  {
146 
151  ControlPoint( const QgsPointXY &pagePoint, const QgsPointXY &geoPoint )
152  : pagePoint( pagePoint )
153  , geoPoint( geoPoint )
154  {}
155 
158 
161  };
162 
164  {
165 
172 
179 
182 
184  QList< QgsAbstractGeoPdfExporter::ControlPoint > controlPoints;
185 
186  };
187 
195  void pushRenderedFeature( const QString &layerId, const QgsAbstractGeoPdfExporter::RenderedFeature &feature, const QString &group = QString() );
196 
198  {
200  QSizeF pageSizeMm;
201 
203  double dpi = 300;
204 
206  QList< QgsAbstractGeoPdfExporter::GeoReferencedSection > georeferencedSections;
207 
209  QString author;
210 
212  QString producer;
213 
215  QString creator;
216 
218  QDateTime creationDateTime;
219 
221  QString subject;
222 
224  QString title;
225 
228 
235  bool useIso32000ExtensionFormatGeoreferencing = true;
236 
244  bool useOgcBestPracticeFormatGeoreferencing = false;
245 
249  bool includeFeatures = true;
250 
261  QMap< QString, QString > customLayerTreeGroups;
262 
268  QMap< QString, QString > layerIdToPdfLayerTreeNameMap;
269 
276  QMap< QString, bool > initialLayerVisibility;
277 
285  QStringList layerOrder;
286 
287  };
288 
302  bool finalize( const QList< QgsAbstractGeoPdfExporter::ComponentLayerDetail > &components, const QString &destinationFile, const ExportDetails &details );
303 
307  QString errorMessage() { return mErrorMessage; }
308 
312  QString generateTemporaryFilepath( const QString &filename ) const;
313 
320  static bool compositionModeSupported( QPainter::CompositionMode mode );
321 
322  protected:
323 
328  {
330  QString name;
331 
333  QString mapLayerId;
334 
336  QString group;
337 
340 
343 
346 
347  };
348 
349  private:
350 
351  QMutex mMutex;
352  QMap< QString, QMap< QString, QgsFeatureList > > mCollatedFeatures;
353 
357  virtual VectorComponentDetail componentDetailForLayerId( const QString &layerId ) = 0;
358 
359  QList< VectorComponentDetail > mVectorComponents;
360 
361  QString mErrorMessage;
362  QTemporaryDir mTemporaryDir;
363 
364 
365  bool saveTemporaryLayers();
366 
367  QString createCompositionXml( const QList< QgsAbstractGeoPdfExporter::ComponentLayerDetail > &components, const ExportDetails &details );
368 
372  static QString compositionModeToString( QPainter::CompositionMode mode );
373 
374  friend class TestQgsLayoutGeoPdfExport;
375  friend class TestQgsGeoPdfExport;
376 };
377 
378 #endif //QGSABSTRACTGEOPDFEXPORTER_H
379 
380 
381 
qgspolygon.h
QgsAbstractGeoPdfExporter::ExportDetails::layerOrder
QStringList layerOrder
Optional list of layer IDs, in the order desired to appear in the generated GeoPDF file.
Definition: qgsabstractgeopdfexporter.h:285
QgsAbstractGeoPdfExporter::ControlPoint
Contains details of a control point used during georeferencing GeoPDF outputs.
Definition: qgsabstractgeopdfexporter.h:145
QgsPolygon
Polygon geometry type.
Definition: qgspolygon.h:34
QgsAbstractGeoPdfExporter::VectorComponentDetail::displayAttribute
QString displayAttribute
Field name for display.
Definition: qgsabstractgeopdfexporter.h:339
QgsAbstractGeoPdfExporter::ComponentLayerDetail::mapLayerId
QString mapLayerId
Associated map layer ID, or an empty string if this component layer is not associated with a map laye...
Definition: qgsabstractgeopdfexporter.h:123
QgsAbstractGeoPdfExporter::RenderedFeature::renderedBounds
QgsGeometry renderedBounds
Bounds, in PDF units, of rendered feature.
Definition: qgsabstractgeopdfexporter.h:108
qgsfeature.h
QgsAbstractGeoPdfExporter::RenderedFeature::RenderedFeature
RenderedFeature(const QgsFeature &feature, const QgsGeometry &renderedBounds)
Constructor for RenderedFeature.
Definition: qgsabstractgeopdfexporter.h:95
QgsAbstractGeoPdfExporter::GeoReferencedSection::pageBoundsPolygon
QgsPolygon pageBoundsPolygon
Bounds of the georeferenced section on the page, in millimeters, as a free-form polygon.
Definition: qgsabstractgeopdfexporter.h:178
QgsAbstractGeoPdfExporter::RenderedFeature::feature
QgsFeature feature
Rendered feature.
Definition: qgsabstractgeopdfexporter.h:103
QgsAbstractGeoPdfExporter::errorMessage
QString errorMessage()
Returns the last error message encountered during the export.
Definition: qgsabstractgeopdfexporter.h:307
QgsAbstractGeoPdfExporter::ExportDetails
Definition: qgsabstractgeopdfexporter.h:198
QgsAbstractGeoPdfExporter::GeoReferencedSection
Definition: qgsabstractgeopdfexporter.h:164
QgsAbstractGeoPdfExporter::ExportDetails::layerIdToPdfLayerTreeNameMap
QMap< QString, QString > layerIdToPdfLayerTreeNameMap
Optional map of map layer ID to custom layer tree name to show in the created PDF file.
Definition: qgsabstractgeopdfexporter.h:268
QgsAbstractGeoPdfExporter::ExportDetails::title
QString title
Metadata title tag.
Definition: qgsabstractgeopdfexporter.h:224
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsAbstractGeoPdfExporter::ExportDetails::keywords
QgsAbstractMetadataBase::KeywordMap keywords
Metadata keyword map.
Definition: qgsabstractgeopdfexporter.h:227
QgsAbstractGeoPdfExporter::ExportDetails::georeferencedSections
QList< QgsAbstractGeoPdfExporter::GeoReferencedSection > georeferencedSections
List of georeferenced sections.
Definition: qgsabstractgeopdfexporter.h:206
QgsAbstractGeoPdfExporter::ControlPoint::geoPoint
QgsPointXY geoPoint
Georeferenced coordinate of the control point, in CRS units.
Definition: qgsabstractgeopdfexporter.h:160
QgsAbstractGeoPdfExporter::ExportDetails::initialLayerVisibility
QMap< QString, bool > initialLayerVisibility
Optional map of map layer ID to initial visibility state.
Definition: qgsabstractgeopdfexporter.h:276
QgsAbstractGeoPdfExporter::VectorComponentDetail::mapLayerId
QString mapLayerId
Associated map layer ID.
Definition: qgsabstractgeopdfexporter.h:333
QgsAbstractGeoPdfExporter::VectorComponentDetail
Contains information relating to a single PDF layer in the GeoPDF export.
Definition: qgsabstractgeopdfexporter.h:328
QgsAbstractGeoPdfExporter::RenderedFeature::RenderedFeature
RenderedFeature()=default
Constructor for RenderedFeature.
QgsAbstractGeoPdfExporter::RenderedFeature
Contains information about a feature rendered inside the PDF.
Definition: qgsabstractgeopdfexporter.h:85
QgsAbstractGeoPdfExporter::ComponentLayerDetail::sourcePdfPath
QString sourcePdfPath
File path to the (already created) PDF to use as the source for this component layer.
Definition: qgsabstractgeopdfexporter.h:129
QgsAbstractGeoPdfExporter::ExportDetails::producer
QString producer
Metadata producer tag.
Definition: qgsabstractgeopdfexporter.h:212
QgsAbstractGeoPdfExporter::VectorComponentDetail::sourceVectorPath
QString sourceVectorPath
File path to the (already created) vector dataset to use as the source for this component layer.
Definition: qgsabstractgeopdfexporter.h:342
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:206
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:44
QgsAbstractGeoPdfExporter::ControlPoint::pagePoint
QgsPointXY pagePoint
Coordinate on the page of the control point, in millimeters.
Definition: qgsabstractgeopdfexporter.h:157
QgsAbstractGeoPdfExporter::VectorComponentDetail::group
QString group
Optional layer group name.
Definition: qgsabstractgeopdfexporter.h:336
QgsAbstractGeoPdfExporter::ExportDetails::creator
QString creator
Metadata creator tag.
Definition: qgsabstractgeopdfexporter.h:215
QgsAbstractGeoPdfExporter::ComponentLayerDetail
Contains details of a particular input component to be used during PDF composition.
Definition: qgsabstractgeopdfexporter.h:117
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsAbstractGeoPdfExporter::GeoReferencedSection::pageBoundsMm
QgsRectangle pageBoundsMm
Bounds of the georeferenced section on the page, in millimeters.
Definition: qgsabstractgeopdfexporter.h:171
QgsAbstractGeoPdfExporter::GeoReferencedSection::controlPoints
QList< QgsAbstractGeoPdfExporter::ControlPoint > controlPoints
List of control points corresponding to this georeferenced section.
Definition: qgsabstractgeopdfexporter.h:184
QgsAbstractGeoPdfExporter::ExportDetails::author
QString author
Metadata author tag.
Definition: qgsabstractgeopdfexporter.h:209
QgsAbstractGeoPdfExporter::VectorComponentDetail::sourceVectorLayer
QString sourceVectorLayer
Layer name in vector dataset to use as the source.
Definition: qgsabstractgeopdfexporter.h:345
QgsAbstractGeoPdfExporter::ComponentLayerDetail::group
QString group
Optional group name, for arranging layers in top-level groups.
Definition: qgsabstractgeopdfexporter.h:126
QgsAbstractGeoPdfExporter::GeoReferencedSection::crs
QgsCoordinateReferenceSystem crs
Coordinate reference system for georeferenced section.
Definition: qgsabstractgeopdfexporter.h:181
qgsabstractmetadatabase.h
QgsAbstractGeoPdfExporter::QgsAbstractGeoPdfExporter
QgsAbstractGeoPdfExporter()=default
Constructor for QgsAbstractGeoPdfExporter.
QgsAbstractMetadataBase::KeywordMap
QMap< QString, QStringList > KeywordMap
Map of vocabulary string to keyword list.
Definition: qgsabstractmetadatabase.h:78
QgsAbstractGeoPdfExporter::ExportDetails::subject
QString subject
Metadata subject tag.
Definition: qgsabstractgeopdfexporter.h:221
QgsAbstractGeoPdfExporter::ExportDetails::creationDateTime
QDateTime creationDateTime
Metadata creation datetime.
Definition: qgsabstractgeopdfexporter.h:218
QgsFeature
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
QgsAbstractGeoPdfExporter::VectorComponentDetail::name
QString name
User-friendly name for the generated PDF layer.
Definition: qgsabstractgeopdfexporter.h:330
QgsAbstractGeoPdfExporter::ComponentLayerDetail::name
QString name
User-friendly name for the generated PDF layer.
Definition: qgsabstractgeopdfexporter.h:120
QgsAbstractGeoPdfExporter::ControlPoint::ControlPoint
ControlPoint(const QgsPointXY &pagePoint, const QgsPointXY &geoPoint)
Constructor for ControlPoint, at the specified pagePoint (in millimeters) and geoPoint (in CRS units)...
Definition: qgsabstractgeopdfexporter.h:151
QgsAbstractGeoPdfExporter
Abstract base class for GeoPDF exporters.
Definition: qgsabstractgeopdfexporter.h:55
QgsAbstractGeoPdfExporter::ExportDetails::pageSizeMm
QSizeF pageSizeMm
Page size, in millimeters.
Definition: qgsabstractgeopdfexporter.h:200
QgsAbstractGeoPdfExporter::ExportDetails::customLayerTreeGroups
QMap< QString, QString > customLayerTreeGroups
Optional map of map layer ID to custom logical layer tree group in created PDF file.
Definition: qgsabstractgeopdfexporter.h:261
QgsAbstractGeoPdfExporter::~QgsAbstractGeoPdfExporter
virtual ~QgsAbstractGeoPdfExporter()=default