From bb56ddc135c904eb7a40be28fbe1bf2705692a39 Mon Sep 17 00:00:00 2001 From: Andrea Giudiceandrea Date: Wed, 22 Jan 2025 10:31:23 +0100 Subject: [PATCH 1/2] QgsLayoutExporter: avoid to print a GDAL error message When QgsLayoutExporter.exportToImage is executed, the "ERROR 6: The PNG driver does not support update access to existing datasets." error message may be thrown by the GDAL/OGR library because QgsLayoutExporter.exportToImage tries to open in "update mode" the already exported image file in order to add the georeferencing information inside it, while it is not possible for many image formats (e.g. PNG). The error doesn't actually affects the exporting functionality. --- src/core/layout/qgslayoutexporter.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/core/layout/qgslayoutexporter.cpp b/src/core/layout/qgslayoutexporter.cpp index f364465510ac..6da604c05418 100644 --- a/src/core/layout/qgslayoutexporter.cpp +++ b/src/core/layout/qgslayoutexporter.cpp @@ -1743,7 +1743,12 @@ bool QgsLayoutExporter::georeferenceOutputPrivate( const QString &file, QgsLayou // important - we need to manually specify the DPI in advance, as GDAL will otherwise // assume a DPI of 150 CPLSetConfigOption( "GDAL_PDF_DPI", QString::number( dpi ).toUtf8().constData() ); + + CPLPushErrorHandler( CPLQuietErrorHandler ); + CPLErrorReset(); gdal::dataset_unique_ptr outputDS( GDALOpen( file.toUtf8().constData(), GA_Update ) ); + CPLPopErrorHandler(); + if ( outputDS ) { if ( t ) From 74b0f7b6b81c5187ed9f3152ccf68349cce308f4 Mon Sep 17 00:00:00 2001 From: Andrea Giudiceandrea Date: Thu, 23 Jan 2025 08:05:26 +0100 Subject: [PATCH 2/2] QgsLayoutExporter: embed goeref and metadata in GeoTIFF and PDF only as in QgsMapRendererTask --- src/core/layout/qgslayoutexporter.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/core/layout/qgslayoutexporter.cpp b/src/core/layout/qgslayoutexporter.cpp index 6da604c05418..c157289042b8 100644 --- a/src/core/layout/qgslayoutexporter.cpp +++ b/src/core/layout/qgslayoutexporter.cpp @@ -1727,6 +1727,10 @@ bool QgsLayoutExporter::georeferenceOutputPrivate( const QString &file, QgsLayou if ( !mLayout ) return false; + const char *const apszAllowedDrivers[] = { "GTiff", "PDF", nullptr }; + if ( !GDALIdentifyDriverEx( file.toUtf8().constData(), GDAL_OF_RASTER, apszAllowedDrivers, nullptr ) ) + return false; + if ( !map && includeGeoreference ) map = mLayout->referenceMap(); @@ -1743,12 +1747,7 @@ bool QgsLayoutExporter::georeferenceOutputPrivate( const QString &file, QgsLayou // important - we need to manually specify the DPI in advance, as GDAL will otherwise // assume a DPI of 150 CPLSetConfigOption( "GDAL_PDF_DPI", QString::number( dpi ).toUtf8().constData() ); - - CPLPushErrorHandler( CPLQuietErrorHandler ); - CPLErrorReset(); gdal::dataset_unique_ptr outputDS( GDALOpen( file.toUtf8().constData(), GA_Update ) ); - CPLPopErrorHandler(); - if ( outputDS ) { if ( t )