diff --git a/python/core/auto_generated/layout/qgslayoutitemmap.sip.in b/python/core/auto_generated/layout/qgslayoutitemmap.sip.in index 7b6f8a7c7778..7854144cdb57 100644 --- a/python/core/auto_generated/layout/qgslayoutitemmap.sip.in +++ b/python/core/auto_generated/layout/qgslayoutitemmap.sip.in @@ -612,6 +612,11 @@ Removes a previously added rendered feature ``handler``. .. seealso:: :py:func:`addRenderedFeatureHandler` .. versionadded:: 3.10 +%End + + QTransform layoutToMapCoordsTransform() const; +%Docstring +Creates a transform from layout coordinates to map coordinates. %End protected: diff --git a/src/core/layout/qgslayoutexporter.cpp b/src/core/layout/qgslayoutexporter.cpp index b9826df4e14c..1f567e2a1d48 100644 --- a/src/core/layout/qgslayoutexporter.cpp +++ b/src/core/layout/qgslayoutexporter.cpp @@ -26,6 +26,7 @@ #include "qgsabstractlayoutiterator.h" #include "qgsfeedback.h" #include "qgslayoutgeopdfexporter.h" +#include "qgslinestring.h" #include #include #include @@ -595,6 +596,46 @@ QgsLayoutExporter::ExportResult QgsLayoutExporter::exportToPdf( const QString &f details.keywords = mLayout->project()->metadata().keywords(); } + if ( settings.appendGeoreference ) + { + // setup georeferencing + QList< QgsLayoutItemMap * > maps; + mLayout->layoutItems( maps ); + for ( QgsLayoutItemMap *map : qgis::as_const( maps ) ) + { + QgsAbstractGeoPdfExporter::GeoReferencedSection georef; + georef.crs = map->crs(); + + const QPointF topLeft = map->mapToScene( QPointF( 0, 0 ) ); + const QPointF topRight = map->mapToScene( QPointF( map->rect().width(), 0 ) ); + const QPointF bottomLeft = map->mapToScene( QPointF( 0, map->rect().height() ) ); + const QPointF bottomRight = map->mapToScene( QPointF( map->rect().width(), map->rect().height() ) ); + const QgsLayoutPoint topLeftMm = mLayout->convertFromLayoutUnits( topLeft, QgsUnitTypes::LayoutMillimeters ); + const QgsLayoutPoint topRightMm = mLayout->convertFromLayoutUnits( topRight, QgsUnitTypes::LayoutMillimeters ); + const QgsLayoutPoint bottomLeftMm = mLayout->convertFromLayoutUnits( bottomLeft, QgsUnitTypes::LayoutMillimeters ); + const QgsLayoutPoint bottomRightMm = mLayout->convertFromLayoutUnits( bottomRight, QgsUnitTypes::LayoutMillimeters ); + + georef.pageBoundsPolygon.setExteriorRing( new QgsLineString( QVector< QgsPointXY >() << QgsPointXY( topLeftMm.x(), topLeftMm.y() ) + << QgsPointXY( topRightMm.x(), topRightMm.y() ) + << QgsPointXY( bottomRightMm.x(), bottomRightMm.y() ) + << QgsPointXY( bottomLeftMm.x(), bottomLeftMm.y() ) + << QgsPointXY( topLeftMm.x(), topLeftMm.y() ) ) ); + + georef.controlPoints.reserve( 4 ); + const QTransform t = map->layoutToMapCoordsTransform(); + const QgsPointXY topLeftMap = t.map( topLeft ); + const QgsPointXY topRightMap = t.map( topRight ); + const QgsPointXY bottomLeftMap = t.map( bottomLeft ); + const QgsPointXY bottomRightMap = t.map( bottomRight ); + + georef.controlPoints << QgsAbstractGeoPdfExporter::ControlPoint( QgsPointXY( topLeftMm.x(), topLeftMm.y() ), topLeftMap ); + georef.controlPoints << QgsAbstractGeoPdfExporter::ControlPoint( QgsPointXY( topRightMm.x(), topRightMm.y() ), topRightMap ); + georef.controlPoints << QgsAbstractGeoPdfExporter::ControlPoint( QgsPointXY( bottomLeftMm.x(), bottomLeftMm.y() ), bottomLeftMap ); + georef.controlPoints << QgsAbstractGeoPdfExporter::ControlPoint( QgsPointXY( bottomRightMm.x(), bottomRightMm.y() ), bottomRightMap ); + details.georeferencedSections << georef; + } + } + details.includeFeatures = settings.includeGeoPdfFeatures; details.useOgcBestPracticeFormatGeoreferencing = settings.useOgcBestPracticeFormatGeoreferencing; details.useIso32000ExtensionFormatGeoreferencing = settings.useIso32000ExtensionFormatGeoreferencing; diff --git a/src/core/layout/qgslayoutitemmap.h b/src/core/layout/qgslayoutitemmap.h index f57ab0028fed..be42fb2a5931 100644 --- a/src/core/layout/qgslayoutitemmap.h +++ b/src/core/layout/qgslayoutitemmap.h @@ -549,6 +549,11 @@ class CORE_EXPORT QgsLayoutItemMap : public QgsLayoutItem */ void removeRenderedFeatureHandler( QgsRenderedFeatureHandlerInterface *handler ); + /** + * Creates a transform from layout coordinates to map coordinates. + */ + QTransform layoutToMapCoordsTransform() const; + protected: void draw( QgsLayoutItemRenderContext &context ) override; @@ -731,11 +736,6 @@ class CORE_EXPORT QgsLayoutItemMap : public QgsLayoutItem //! Returns first map overview or creates an empty one if none const QgsLayoutItemMapOverview *constFirstMapOverview() const; - /** - * Creates a transform from layout coordinates to map coordinates. - */ - QTransform layoutToMapCoordsTransform() const; - /** * Creates a list of label blocking regions for the map, which correspond to the * map areas covered by other layout items marked as label blockers for this map. diff --git a/src/core/qgsabstractgeopdfexporter.cpp b/src/core/qgsabstractgeopdfexporter.cpp index 91ce4f5ef5d1..3497e87dc5d2 100644 --- a/src/core/qgsabstractgeopdfexporter.cpp +++ b/src/core/qgsabstractgeopdfexporter.cpp @@ -346,10 +346,11 @@ QString QgsAbstractGeoPdfExporter::createCompositionXml( const QList