Skip to content

Commit

Permalink
Use utf-8 encoding to call gdal's file operation function
Browse files Browse the repository at this point in the history
  • Loading branch information
longhuan2018 authored and github-actions[bot] committed Jan 13, 2023
1 parent 9c9c02c commit b0f9b68
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/analysis/processing/qgsalgorithmrasterize.cpp
Expand Up @@ -162,7 +162,7 @@ QVariantMap QgsRasterizeAlgorithm::processAlgorithm( const QVariantMap &paramete
throw QgsProcessingException( QObject::tr( "Error creating GDAL driver" ) );
}

gdal::dataset_unique_ptr hOutputDataset( GDALCreate( hOutputFileDriver, outputLayerFileName.toLocal8Bit().constData(), width, height, nBands, GDALDataType::GDT_Byte, nullptr ) );
gdal::dataset_unique_ptr hOutputDataset( GDALCreate( hOutputFileDriver, outputLayerFileName.toUtf8().constData(), width, height, nBands, GDALDataType::GDT_Byte, nullptr ) );
if ( !hOutputDataset )
{
throw QgsProcessingException( QObject::tr( "Error creating GDAL output layer" ) );
Expand Down
6 changes: 3 additions & 3 deletions src/analysis/raster/qgsalignraster.cpp
Expand Up @@ -428,7 +428,7 @@ bool QgsAlignRaster::createAndWarp( const Item &raster )
}

// Open the source file.
const gdal::dataset_unique_ptr hSrcDS( GDALOpen( raster.inputFilename.toLocal8Bit().constData(), GA_ReadOnly ) );
const gdal::dataset_unique_ptr hSrcDS( GDALOpen( raster.inputFilename.toUtf8().constData(), GA_ReadOnly ) );
if ( !hSrcDS )
{
mErrorMessage = QObject::tr( "Unable to open input file: %1" ).arg( raster.inputFilename );
Expand All @@ -441,7 +441,7 @@ bool QgsAlignRaster::createAndWarp( const Item &raster )
const GDALDataType eDT = GDALGetRasterDataType( GDALGetRasterBand( hSrcDS.get(), 1 ) );

// Create the output file.
const gdal::dataset_unique_ptr hDstDS( GDALCreate( hDriver, raster.outputFilename.toLocal8Bit().constData(), mXSize, mYSize,
const gdal::dataset_unique_ptr hDstDS( GDALCreate( hDriver, raster.outputFilename.toUtf8().constData(), mXSize, mYSize,
bandCount, eDT, nullptr ) );
if ( !hDstDS )
{
Expand Down Expand Up @@ -550,7 +550,7 @@ bool QgsAlignRaster::suggestedWarpOutput( const QgsAlignRaster::RasterInfo &info

QgsAlignRaster::RasterInfo::RasterInfo( const QString &layerpath )
{
mDataset.reset( GDALOpen( layerpath.toLocal8Bit().constData(), GA_ReadOnly ) );
mDataset.reset( GDALOpen( layerpath.toUtf8().constData(), GA_ReadOnly ) );
if ( !mDataset )
return;

Expand Down
2 changes: 1 addition & 1 deletion src/core/browser/qgszipitem.cpp
Expand Up @@ -228,7 +228,7 @@ QStringList QgsZipItem::getZipFileList()

// get list of files inside zip file
QgsDebugMsgLevel( QStringLiteral( "Open file %1 with gdal vsi" ).arg( mVsiPrefix + mFilePath ), 3 );
char **papszSiblingFiles = VSIReadDirRecursive( QString( mVsiPrefix + mFilePath ).toLocal8Bit().constData() );
char **papszSiblingFiles = VSIReadDirRecursive( QString( mVsiPrefix + mFilePath ).toUtf8().constData() );
if ( papszSiblingFiles )
{
for ( int i = 0; papszSiblingFiles[i]; i++ )
Expand Down
4 changes: 2 additions & 2 deletions src/core/layout/qgslayoutexporter.cpp
Expand Up @@ -1632,8 +1632,8 @@ 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 ).toLocal8Bit().constData() );
gdal::dataset_unique_ptr outputDS( GDALOpen( file.toLocal8Bit().constData(), GA_Update ) );
CPLSetConfigOption( "GDAL_PDF_DPI", QString::number( dpi ).toUtf8().constData() );
gdal::dataset_unique_ptr outputDS( GDALOpen( file.toUtf8().constData(), GA_Update ) );
if ( outputDS )
{
if ( t )
Expand Down
4 changes: 2 additions & 2 deletions src/core/maprenderer/qgsmaprenderertask.cpp
Expand Up @@ -323,7 +323,7 @@ bool QgsMapRendererTask::run()
if ( mSaveWorldFile || mExportMetadata )
{
CPLSetThreadLocalConfigOption( "GDAL_PDF_DPI", QString::number( mMapSettings.outputDpi() ).toLocal8Bit().constData() );
const gdal::dataset_unique_ptr outputDS( GDALOpen( mFileName.toLocal8Bit().constData(), GA_Update ) );
const gdal::dataset_unique_ptr outputDS( GDALOpen( mFileName.toUtf8().constData(), GA_Update ) );
if ( outputDS )
{
if ( mSaveWorldFile )
Expand Down Expand Up @@ -406,7 +406,7 @@ bool QgsMapRendererTask::run()
bool skipWorldFile = false;
if ( outputSuffix == QLatin1String( "tif" ) || outputSuffix == QLatin1String( "tiff" ) )
{
const gdal::dataset_unique_ptr outputDS( GDALOpen( mFileName.toLocal8Bit().constData(), GA_Update ) );
const gdal::dataset_unique_ptr outputDS( GDALOpen( mFileName.toUtf8().constData(), GA_Update ) );
if ( outputDS )
{
skipWorldFile = true;
Expand Down
2 changes: 1 addition & 1 deletion src/core/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -3872,7 +3872,7 @@ QList<QgsProviderSublayerDetails> QgsGdalProviderMetadata::querySublayers( const
{
// get list of files inside archive file
QgsDebugMsgLevel( QStringLiteral( "Open file %1 with gdal vsi" ).arg( vsiPrefix + uriParts.value( QStringLiteral( "path" ) ).toString() ), 3 );
char **papszSiblingFiles = VSIReadDirRecursive( QString( vsiPrefix + uriParts.value( QStringLiteral( "path" ) ).toString() ).toLocal8Bit().constData() );
char **papszSiblingFiles = VSIReadDirRecursive( QString( vsiPrefix + uriParts.value( QStringLiteral( "path" ) ).toString() ).toUtf8().constData() );
if ( papszSiblingFiles )
{
QList<QgsProviderSublayerDetails> res;
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsgdalutils.cpp
Expand Up @@ -94,7 +94,7 @@ gdal::dataset_unique_ptr QgsGdalUtils::createSingleBandTiffDataset( const QStrin
}

// Create the output file.
gdal::dataset_unique_ptr hDstDS( GDALCreate( hDriver, filename.toLocal8Bit().constData(), width, height, 1, dataType, nullptr ) );
gdal::dataset_unique_ptr hDstDS( GDALCreate( hDriver, filename.toUtf8().constData(), width, height, 1, dataType, nullptr ) );
if ( !hDstDS )
{
return gdal::dataset_unique_ptr();
Expand Down
2 changes: 1 addition & 1 deletion tests/src/core/testqgsrasterlayer.cpp
Expand Up @@ -580,7 +580,7 @@ void TestQgsRasterLayer::buildExternalOverviews()

// Check that the overview is Deflate compressed
const QString ovrFilename( myTempPath + "landsat.tif.ovr" );
GDALDatasetH hDS = GDALOpen( ovrFilename.toLocal8Bit().constData(), GA_ReadOnly );
GDALDatasetH hDS = GDALOpen( ovrFilename.toUtf8().constData(), GA_ReadOnly );
QVERIFY( hDS );
const char *pszCompression = GDALGetMetadataItem( hDS, "COMPRESSION", "IMAGE_STRUCTURE" );
QVERIFY( pszCompression && EQUAL( pszCompression, "DEFLATE" ) );
Expand Down

0 comments on commit b0f9b68

Please sign in to comment.