From cc04caf627b65f1074a5cc9c314ef73de3a3658e Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 17 Oct 2024 21:40:13 +0200 Subject: [PATCH] QgsRasterFileWriter::driverForExtension(): make sure querying the tif/tiff extension returns the GTiff driver Not strictly necessary since has been adressed on GDAL side per https://github.com/OSGeo/gdal/pull/11037 but might be prudent for future similar situations. Fixes #59112 --- src/core/raster/qgsrasterfilewriter.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/core/raster/qgsrasterfilewriter.cpp b/src/core/raster/qgsrasterfilewriter.cpp index 50ea824a1749..a07d2902f7c2 100644 --- a/src/core/raster/qgsrasterfilewriter.cpp +++ b/src/core/raster/qgsrasterfilewriter.cpp @@ -1072,6 +1072,16 @@ QString QgsRasterFileWriter::driverForExtension( const QString &extension ) if ( ext.startsWith( '.' ) ) ext.remove( 0, 1 ); + if ( ext.compare( QLatin1String( "tif" ), Qt::CaseInsensitive ) == 0 || + ext.compare( QLatin1String( "tiff" ), Qt::CaseInsensitive ) == 0 ) + { + // Be robust to GDAL drivers potentially recognizing the tif/tiff extensions + // but being registered before the GTiff one. + // Cf https://github.com/qgis/QGIS/issues/59112 + if ( GDALGetDriverByName( "GTiff" ) ) + return "GTiff"; + } + GDALAllRegister(); int const drvCount = GDALGetDriverCount();