Skip to content

Commit 618ffa0

Browse files
committed
make filename encoding consistent (gdal/ogr)
1 parent f6c057e commit 618ffa0

File tree

9 files changed

+35
-27
lines changed

9 files changed

+35
-27
lines changed

src/analysis/raster/qgsninecellfilter.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
#include <QProgressDialog>
2121

2222
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
23-
#define TO8(x) (x).toUtf8().constData()
23+
#define TO8F(x) (x).toUtf8().constData()
2424
#else
25-
#define TO8(x) (x).toLocal8Bit().constData()
25+
#define TO8F(x) QFile::encodeName( x ).constData()
2626
#endif
2727

2828
QgsNineCellFilter::QgsNineCellFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat )
@@ -187,7 +187,7 @@ int QgsNineCellFilter::processRaster( QProgressDialog* p )
187187
if ( p && p->wasCanceled() )
188188
{
189189
//delete the dataset without closing (because it is faster)
190-
GDALDeleteDataset( outputDriver, mOutputFile.toLocal8Bit().data() );
190+
GDALDeleteDataset( outputDriver, TO8F( mOutputFile ) );
191191
return 7;
192192
}
193193
GDALClose( outputDataset );
@@ -197,7 +197,7 @@ int QgsNineCellFilter::processRaster( QProgressDialog* p )
197197

198198
GDALDatasetH QgsNineCellFilter::openInputFile( int& nCellsX, int& nCellsY )
199199
{
200-
GDALDatasetH inputDataset = GDALOpen( TO8( mInputFile ), GA_ReadOnly );
200+
GDALDatasetH inputDataset = GDALOpen( TO8F( mInputFile ), GA_ReadOnly );
201201
if ( inputDataset != NULL )
202202
{
203203
nCellsX = GDALGetRasterXSize( inputDataset );
@@ -246,7 +246,7 @@ GDALDatasetH QgsNineCellFilter::openOutputFile( GDALDatasetH inputDataset, GDALD
246246

247247
//open output file
248248
char **papszOptions = NULL;
249-
GDALDatasetH outputDataset = GDALCreate( outputDriver, mOutputFile.toLocal8Bit().data(), xSize, ySize, 1, GDT_Float32, papszOptions );
249+
GDALDatasetH outputDataset = GDALCreate( outputDriver, TO8F( mOutputFile ), xSize, ySize, 1, GDT_Float32, papszOptions );
250250
if ( outputDataset == NULL )
251251
{
252252
return outputDataset;

src/analysis/raster/qgsrastercalculator.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626
#include <ogr_srs_api.h>
2727

2828
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
29-
#define TO8(x) (x).toUtf8().constData()
29+
#define TO8(x) (x).toUtf8().constData()
30+
#define TO8F(x) (x).toUtf8().constData()
3031
#else
31-
#define TO8(x) (x).toLocal8Bit().constData()
32+
#define TO8(x) (x).toLocal8Bit().constData()
33+
#define TO8F(x) QFile::encodeName( x ).constData()
3234
#endif
3335

3436
QgsRasterCalculator::QgsRasterCalculator( const QString& formulaString, const QString& outputFile, const QString& outputFormat,
@@ -66,7 +68,7 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
6668
{
6769
return 2;
6870
}
69-
GDALDatasetH inputDataset = GDALOpen( TO8( it->raster->source() ), GA_ReadOnly );
71+
GDALDatasetH inputDataset = GDALOpen( TO8F( it->raster->source() ), GA_ReadOnly );
7072
if ( inputDataset == NULL )
7173
{
7274
return 2;
@@ -237,7 +239,7 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
237239
if ( p && p->wasCanceled() )
238240
{
239241
//delete the dataset without closing (because it is faster)
240-
GDALDeleteDataset( outputDriver, mOutputFile.toLocal8Bit().data() );
242+
GDALDeleteDataset( outputDriver, TO8F( mOutputFile ) );
241243
return 3;
242244
}
243245
GDALClose( outputDataset );
@@ -274,7 +276,7 @@ GDALDatasetH QgsRasterCalculator::openOutputFile( GDALDriverH outputDriver )
274276
{
275277
//open output file
276278
char **papszOptions = NULL;
277-
GDALDatasetH outputDataset = GDALCreate( outputDriver, mOutputFile.toLocal8Bit().data(), mNumOutputColumns, mNumOutputRows, 1, GDT_Float32, papszOptions );
279+
GDALDatasetH outputDataset = GDALCreate( outputDriver, TO8F( mOutputFile ), mNumOutputColumns, mNumOutputRows, 1, GDT_Float32, papszOptions );
278280
if ( outputDataset == NULL )
279281
{
280282
return outputDataset;

src/analysis/raster/qgsrelief.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
#include <QTextStream>
2929

3030
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
31-
#define TO8(x) (x).toUtf8().constData()
31+
#define TO8F(x) (x).toUtf8().constData()
3232
#else
33-
#define TO8(x) (x).toLocal8Bit().constData()
33+
#define TO8F(x) QFile::encodeName( x ).constData()
3434
#endif
3535

3636
QgsRelief::QgsRelief( const QString& inputFile, const QString& outputFile, const QString& outputFormat ): \
@@ -269,7 +269,7 @@ int QgsRelief::processRaster( QProgressDialog* p )
269269
if ( p && p->wasCanceled() )
270270
{
271271
//delete the dataset without closing (because it is faster)
272-
GDALDeleteDataset( outputDriver, mOutputFile.toLocal8Bit().data() );
272+
GDALDeleteDataset( outputDriver, TO8F( mOutputFile ) );
273273
return 7;
274274
}
275275
GDALClose( outputDataset );
@@ -390,7 +390,7 @@ bool QgsRelief::setElevationColor( double elevation, int* red, int* green, int*
390390
//duplicated from QgsNineCellFilter. Todo: make common base class
391391
GDALDatasetH QgsRelief::openInputFile( int& nCellsX, int& nCellsY )
392392
{
393-
GDALDatasetH inputDataset = GDALOpen( TO8( mInputFile ), GA_ReadOnly );
393+
GDALDatasetH inputDataset = GDALOpen( TO8F( mInputFile ), GA_ReadOnly );
394394
if ( inputDataset != NULL )
395395
{
396396
nCellsX = GDALGetRasterXSize( inputDataset );
@@ -444,7 +444,7 @@ GDALDatasetH QgsRelief::openOutputFile( GDALDatasetH inputDataset, GDALDriverH o
444444
papszOptions = CSLSetNameValue( papszOptions, "COMPRESS", "PACKBITS" );
445445

446446
//create three band raster (reg, green, blue)
447-
GDALDatasetH outputDataset = GDALCreate( outputDriver, mOutputFile.toLocal8Bit().data(), xSize, ySize, 3, GDT_Byte, papszOptions );
447+
GDALDatasetH outputDataset = GDALCreate( outputDriver, TO8F( mOutputFile ), xSize, ySize, 3, GDT_Byte, papszOptions );
448448
if ( outputDataset == NULL )
449449
{
450450
return outputDataset;

src/analysis/vector/qgszonalstatistics.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
#include <QProgressDialog>
2525

2626
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
27-
#define TO8(x) (x).toUtf8().constData()
27+
#define TO8F(x) (x).toUtf8().constData()
2828
#else
29-
#define TO8(x) (x).toLocal8Bit().constData()
29+
#define TO8F(x) QFile::encodeName( x ).constData()
3030
#endif
3131

3232
QgsZonalStatistics::QgsZonalStatistics( QgsVectorLayer* polygonLayer, const QString& rasterFile, const QString& attributePrefix, int rasterBand )
@@ -66,7 +66,7 @@ int QgsZonalStatistics::calculateStatistics( QProgressDialog* p )
6666

6767
//open the raster layer and the raster band
6868
GDALAllRegister();
69-
GDALDatasetH inputDataset = GDALOpen( TO8( mRasterFilePath ), GA_ReadOnly );
69+
GDALDatasetH inputDataset = GDALOpen( TO8F( mRasterFilePath ), GA_ReadOnly );
7070
if ( inputDataset == NULL )
7171
{
7272
return 3;

src/core/qgsvectorfilewriter.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ QgsVectorFileWriter::QgsVectorFileWriter(
198198
}
199199

200200
// create the data source
201-
mDS = OGR_Dr_CreateDataSource( poDriver, TO8( vectorFileName ), options );
201+
mDS = OGR_Dr_CreateDataSource( poDriver, TO8F( vectorFileName ), options );
202202

203203
if ( options )
204204
{
@@ -1012,11 +1012,11 @@ QMap<QString, QString> QgsVectorFileWriter::ogrDriverList()
10121012
poDriver = OGRGetDriverByName( drvName.toLocal8Bit().data() );
10131013
if ( poDriver )
10141014
{
1015-
OGRDataSourceH ds = OGR_Dr_CreateDataSource( poDriver, TO8( QString( "/vsimem/spatialitetest.sqlite" ) ), options );
1015+
OGRDataSourceH ds = OGR_Dr_CreateDataSource( poDriver, TO8F( QString( "/vsimem/spatialitetest.sqlite" ) ), options );
10161016
if ( ds )
10171017
{
10181018
writableDrivers << "SpatiaLite";
1019-
OGR_Dr_DeleteDataSource( poDriver, TO8( QString( "/vsimem/spatialitetest.sqlite" ) ) );
1019+
OGR_Dr_DeleteDataSource( poDriver, TO8F( QString( "/vsimem/spatialitetest.sqlite" ) ) );
10201020
OGR_DS_Destroy( ds );
10211021
}
10221022
}

src/plugins/heatmap/heatmap.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@
4747
#define M_PI 3.14159265358979323846
4848
#endif
4949

50+
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
51+
#define TO8F(x) (x).toUtf8().constData()
52+
#else
53+
#define TO8F(x) QFile::encodeName( x ).constData()
54+
#endif
55+
5056
static const QString sName = QObject::tr( "Heatmap" );
5157
static const QString sDescription = QObject::tr( "Creates a Heatmap raster for the input point vector" );
5258
static const QString sCategory = QObject::tr( "Raster" );
@@ -157,7 +163,7 @@ void Heatmap::run()
157163

158164
// open the raster in GA_Update mode
159165
GDALDataset *heatmapDS;
160-
heatmapDS = ( GDALDataset * ) GDALOpen( d.outputFilename().toUtf8(), GA_Update );
166+
heatmapDS = ( GDALDataset * ) GDALOpen( TO8F( d.outputFilename() ), GA_Update );
161167
if ( !heatmapDS )
162168
{
163169
QMessageBox::information( 0, tr( "Raster update error" ), tr( "Could not open the created raster for updating. The heatmap was not generated." ) );

src/plugins/oracle_raster/qgsselectgeoraster_ui.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
#include "qgsvectorlayer.h"
2727

2828
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
29-
#define TO8(x) (x).toUtf8().constData()
29+
#define TO8F(x) (x).toUtf8().constData()
3030
#else
31-
#define TO8(x) (x).toLocal8Bit().constData()
31+
#define TO8F(x) QFile::encodeName( x ).constData()
3232
#endif
3333

3434
QgsOracleSelectGeoraster::QgsOracleSelectGeoraster( QWidget* parent,
@@ -199,7 +199,7 @@ void QgsOracleSelectGeoraster::showSelection( const QString & line )
199199
* Try to open georaster dataset
200200
*/
201201

202-
hDS = GDALOpenShared( TO8( identification ), eAccess );
202+
hDS = GDALOpenShared( TO8F( identification ), eAccess );
203203

204204
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
205205
if ( hDS == NULL )

src/providers/gdal/qgsgdaldataitems.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
240240
// do not print errors, but write to debug
241241
CPLPushErrorHandler( CPLQuietErrorHandler );
242242
CPLErrorReset();
243-
if ( ! GDALIdentifyDriver( thePath.toLocal8Bit().constData(), 0 ) )
243+
if ( ! GDALIdentifyDriver( TO8F( thePath ), 0 ) )
244244
{
245245
QgsDebugMsgLevel( "Skipping VRT file because root is not a GDAL VRT", 2 );
246246
CPLPopErrorHandler();

src/providers/gdal/qgsgdalprovider.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2505,7 +2505,7 @@ QGISEXTERN QgsGdalProvider * create(
25052505
//create dataset
25062506
CPLErrorReset();
25072507
char **papszOptions = papszFromStringList( createOptions );
2508-
GDALDatasetH dataset = GDALCreate( driver, uri.toLocal8Bit().data(), width, height, nBands, ( GDALDataType )type, papszOptions );
2508+
GDALDatasetH dataset = GDALCreate( driver, TO8F( uri ), width, height, nBands, ( GDALDataType )type, papszOptions );
25092509
CSLDestroy( papszOptions );
25102510
if ( dataset == NULL )
25112511
{

0 commit comments

Comments
 (0)