-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QgsLayoutExporter: avoid to print the "ERROR 6: The PNG driver does not support update access to existing datasets." GDAL error message #60208
Conversation
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.
🪟 Windows buildsDownload Windows builds of this PR for testing. 🪟 Windows Qt6 buildsDownload Windows Qt6 builds of this PR for testing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't be better to avoid adding georeferencing information to format that don't support it instead of silencing potential useful errors ?
indeed. The thing is that it is not so easy for QGIS to know which formats support update. GDAL advertizes for Create or CreateCopy support, but not for update (I'm considering working on that. not as immediately trivial as I would hope) Looking closer at the code, it is weird that this georeferenceOutputPrivate() method returns true when GDALOpen() fails, or doesn't test the output of GDALSetGeoTransform() or GDALSetProjection() for the return code to return. That said, I don't know the downstream impacts of returning false. But if we want to be clean, georeferenceOutputPrivate() should return an error on PNG. |
While the error message is only displayed in some systems's terminal (so it is not displayed in general), and it is a little bit misleading (so it is not useful to be displayed), and the GDAL's error silencing is used in various other part of the code (so it shouldn't be be an issue to use it in this particular function), I also think, like you, that it would be better to find another approach. I don't know a proper way to check if a GDAL driver is capable to open a file in GA_Update mode. Assuming (but I'm not sure) that only GTiff and PDF drivers can handle to store georeference and metadata information inside the file (which const char *const apszAllowedDrivers[] = { "GTiff", "PDF", nullptr };
if ( !GDALIdentifyDriverEx( file.toUtf8().constData(), GDAL_OF_RASTER, apszAllowedDrivers, nullptr ) )
return false; |
yes, what I was refereing above: there's none currently
const char *const apszAllowedDrivers[] = { "GTiff", "PDF", nullptr }; hum, that's a bit restrictive, although I guess that would cover 90% of the update scenarios. Or maybe let that (somewhat minor) topic aside until GDAL offers something cleaner ? |
Oops... I was writing the comment before your comment get published, so I haven't read it before publishing my comment...
I'm not sure to understand. The issue is that when GDALOpen() in GA_Update mode fails (e.g. for PNG), then the "ERROR 6: The PNG driver does not support update access to existing datasets." error message in printed in some system's terminal: that seems to create confusion since the PNG file is actually correctly created even if GDALOpen() fails and the error message is misleading in such situation (see "Would anyone know why that is? ... However, there is no updating within this process but simply creation." in https://gis.stackexchange.com/questions/360254/pyqgis-exporting-print-layout-error-6-the-png-driver-does-not-support-update). It looks like a similar approach (to restrict the opening in GA_Update mode only to exported files with PDF or TIF or TIFF format) is currently used in QgsMapRendererTask QGIS/src/core/maprenderer/qgsmaprenderertask.cpp Lines 302 to 316 in e5b41bf
QGIS/src/core/maprenderer/qgsmaprenderertask.cpp Lines 393 to 395 in e5b41bf
Moreover, I cannot find where in the code it is actually checked what
I agree with you that if the proposed approaches are not considered optimal, when can wait to fix this minor issue later. |
if you open that PNG, is it georeferenced ? (with the georeferencing in the .aux.xml side car file)
That code in QgsMapRenderedTask looks a bit like band-aid to a cleaner approach that would be needed, or just a down-to-earth approach trying to covering the most common use cases, which is also fine sometimes.
indeed, so there might be something missing to report to users that not everything went right. |
No. Using the GUI, it only has gereferencing info in an ESRI World File .pgw sidecar file if the "Generate world file" checkbox is checked: Anyway, I agree with you that if the proposed approaches are not considered optimal, whe can wait to fix this minor issue later. |
as in QgsMapRendererTask
Filter on format is fine by, but it could indeed lead to issues if other format supporting it are missing (or added later in gdal).
But shall we not instead:
This way user is fully aware of what happen and has an hint on how to fix it! |
My understanding is that, from a user point of view (I've failed to find issue reports about missing georef info) and according to the documentation and the tests, not having georeference info for PNG or JPEG files (or other non GeoTIFF formats) is expected unless the "Generate world file" checkbox is checked, so there is no need to either print the "ERROR 6: ..." message in the console or to display a dialog window in the GUI. There is probably a not quite straightforward and clear logic in QgsLayoutExporter::exportToImage (and "Export as Image") and QgsLayoutExporter::georeferenceOutputPrivate (considering it is also called by QgsLayoutExporter::exportToPDF and it tries to do the same actions for both images and PDF) and it seems also inconsistent with the logic of QgsMapRendererTask (and "Export Map to Image") So, maybe better to wait for a comprehensive reworking of the logic of both in a more coherent way. |
See proposed related GDAL RFC: OSGeo/gdal#11708 |
Description
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, and displayed in the console window on some systems, becauseQgsLayoutExporter.exportToImage
tries to open the already exported image file in "update mode" 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.
Fixes #51947.