Skip to content

Commit

Permalink
make filename encoding consistent (gdal/ogr)
Browse files Browse the repository at this point in the history
  • Loading branch information
minorua committed Jul 14, 2013
1 parent f6c057e commit 618ffa0
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 27 deletions.
10 changes: 5 additions & 5 deletions src/analysis/raster/qgsninecellfilter.cpp
Expand Up @@ -20,9 +20,9 @@
#include <QProgressDialog>

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8(x) (x).toUtf8().constData()
#define TO8F(x) (x).toUtf8().constData()
#else
#define TO8(x) (x).toLocal8Bit().constData()
#define TO8F(x) QFile::encodeName( x ).constData()
#endif

QgsNineCellFilter::QgsNineCellFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat )
Expand Down Expand Up @@ -187,7 +187,7 @@ int QgsNineCellFilter::processRaster( QProgressDialog* p )
if ( p && p->wasCanceled() )
{
//delete the dataset without closing (because it is faster)
GDALDeleteDataset( outputDriver, mOutputFile.toLocal8Bit().data() );
GDALDeleteDataset( outputDriver, TO8F( mOutputFile ) );
return 7;
}
GDALClose( outputDataset );
Expand All @@ -197,7 +197,7 @@ int QgsNineCellFilter::processRaster( QProgressDialog* p )

GDALDatasetH QgsNineCellFilter::openInputFile( int& nCellsX, int& nCellsY )
{
GDALDatasetH inputDataset = GDALOpen( TO8( mInputFile ), GA_ReadOnly );
GDALDatasetH inputDataset = GDALOpen( TO8F( mInputFile ), GA_ReadOnly );
if ( inputDataset != NULL )
{
nCellsX = GDALGetRasterXSize( inputDataset );
Expand Down Expand Up @@ -246,7 +246,7 @@ GDALDatasetH QgsNineCellFilter::openOutputFile( GDALDatasetH inputDataset, GDALD

//open output file
char **papszOptions = NULL;
GDALDatasetH outputDataset = GDALCreate( outputDriver, mOutputFile.toLocal8Bit().data(), xSize, ySize, 1, GDT_Float32, papszOptions );
GDALDatasetH outputDataset = GDALCreate( outputDriver, TO8F( mOutputFile ), xSize, ySize, 1, GDT_Float32, papszOptions );
if ( outputDataset == NULL )
{
return outputDataset;
Expand Down
12 changes: 7 additions & 5 deletions src/analysis/raster/qgsrastercalculator.cpp
Expand Up @@ -26,9 +26,11 @@
#include <ogr_srs_api.h>

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8(x) (x).toUtf8().constData()
#define TO8(x) (x).toUtf8().constData()
#define TO8F(x) (x).toUtf8().constData()
#else
#define TO8(x) (x).toLocal8Bit().constData()
#define TO8(x) (x).toLocal8Bit().constData()
#define TO8F(x) QFile::encodeName( x ).constData()
#endif

QgsRasterCalculator::QgsRasterCalculator( const QString& formulaString, const QString& outputFile, const QString& outputFormat,
Expand Down Expand Up @@ -66,7 +68,7 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
{
return 2;
}
GDALDatasetH inputDataset = GDALOpen( TO8( it->raster->source() ), GA_ReadOnly );
GDALDatasetH inputDataset = GDALOpen( TO8F( it->raster->source() ), GA_ReadOnly );
if ( inputDataset == NULL )
{
return 2;
Expand Down Expand Up @@ -237,7 +239,7 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
if ( p && p->wasCanceled() )
{
//delete the dataset without closing (because it is faster)
GDALDeleteDataset( outputDriver, mOutputFile.toLocal8Bit().data() );
GDALDeleteDataset( outputDriver, TO8F( mOutputFile ) );
return 3;
}
GDALClose( outputDataset );
Expand Down Expand Up @@ -274,7 +276,7 @@ GDALDatasetH QgsRasterCalculator::openOutputFile( GDALDriverH outputDriver )
{
//open output file
char **papszOptions = NULL;
GDALDatasetH outputDataset = GDALCreate( outputDriver, mOutputFile.toLocal8Bit().data(), mNumOutputColumns, mNumOutputRows, 1, GDT_Float32, papszOptions );
GDALDatasetH outputDataset = GDALCreate( outputDriver, TO8F( mOutputFile ), mNumOutputColumns, mNumOutputRows, 1, GDT_Float32, papszOptions );
if ( outputDataset == NULL )
{
return outputDataset;
Expand Down
10 changes: 5 additions & 5 deletions src/analysis/raster/qgsrelief.cpp
Expand Up @@ -28,9 +28,9 @@
#include <QTextStream>

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8(x) (x).toUtf8().constData()
#define TO8F(x) (x).toUtf8().constData()
#else
#define TO8(x) (x).toLocal8Bit().constData()
#define TO8F(x) QFile::encodeName( x ).constData()
#endif

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

//create three band raster (reg, green, blue)
GDALDatasetH outputDataset = GDALCreate( outputDriver, mOutputFile.toLocal8Bit().data(), xSize, ySize, 3, GDT_Byte, papszOptions );
GDALDatasetH outputDataset = GDALCreate( outputDriver, TO8F( mOutputFile ), xSize, ySize, 3, GDT_Byte, papszOptions );
if ( outputDataset == NULL )
{
return outputDataset;
Expand Down
6 changes: 3 additions & 3 deletions src/analysis/vector/qgszonalstatistics.cpp
Expand Up @@ -24,9 +24,9 @@
#include <QProgressDialog>

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8(x) (x).toUtf8().constData()
#define TO8F(x) (x).toUtf8().constData()
#else
#define TO8(x) (x).toLocal8Bit().constData()
#define TO8F(x) QFile::encodeName( x ).constData()
#endif

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

//open the raster layer and the raster band
GDALAllRegister();
GDALDatasetH inputDataset = GDALOpen( TO8( mRasterFilePath ), GA_ReadOnly );
GDALDatasetH inputDataset = GDALOpen( TO8F( mRasterFilePath ), GA_ReadOnly );
if ( inputDataset == NULL )
{
return 3;
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsvectorfilewriter.cpp
Expand Up @@ -198,7 +198,7 @@ QgsVectorFileWriter::QgsVectorFileWriter(
}

// create the data source
mDS = OGR_Dr_CreateDataSource( poDriver, TO8( vectorFileName ), options );
mDS = OGR_Dr_CreateDataSource( poDriver, TO8F( vectorFileName ), options );

if ( options )
{
Expand Down Expand Up @@ -1012,11 +1012,11 @@ QMap<QString, QString> QgsVectorFileWriter::ogrDriverList()
poDriver = OGRGetDriverByName( drvName.toLocal8Bit().data() );
if ( poDriver )
{
OGRDataSourceH ds = OGR_Dr_CreateDataSource( poDriver, TO8( QString( "/vsimem/spatialitetest.sqlite" ) ), options );
OGRDataSourceH ds = OGR_Dr_CreateDataSource( poDriver, TO8F( QString( "/vsimem/spatialitetest.sqlite" ) ), options );
if ( ds )
{
writableDrivers << "SpatiaLite";
OGR_Dr_DeleteDataSource( poDriver, TO8( QString( "/vsimem/spatialitetest.sqlite" ) ) );
OGR_Dr_DeleteDataSource( poDriver, TO8F( QString( "/vsimem/spatialitetest.sqlite" ) ) );
OGR_DS_Destroy( ds );
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/plugins/heatmap/heatmap.cpp
Expand Up @@ -47,6 +47,12 @@
#define M_PI 3.14159265358979323846
#endif

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8F(x) (x).toUtf8().constData()
#else
#define TO8F(x) QFile::encodeName( x ).constData()
#endif

static const QString sName = QObject::tr( "Heatmap" );
static const QString sDescription = QObject::tr( "Creates a Heatmap raster for the input point vector" );
static const QString sCategory = QObject::tr( "Raster" );
Expand Down Expand Up @@ -157,7 +163,7 @@ void Heatmap::run()

// open the raster in GA_Update mode
GDALDataset *heatmapDS;
heatmapDS = ( GDALDataset * ) GDALOpen( d.outputFilename().toUtf8(), GA_Update );
heatmapDS = ( GDALDataset * ) GDALOpen( TO8F( d.outputFilename() ), GA_Update );
if ( !heatmapDS )
{
QMessageBox::information( 0, tr( "Raster update error" ), tr( "Could not open the created raster for updating. The heatmap was not generated." ) );
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/oracle_raster/qgsselectgeoraster_ui.cpp
Expand Up @@ -26,9 +26,9 @@
#include "qgsvectorlayer.h"

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8(x) (x).toUtf8().constData()
#define TO8F(x) (x).toUtf8().constData()
#else
#define TO8(x) (x).toLocal8Bit().constData()
#define TO8F(x) QFile::encodeName( x ).constData()
#endif

QgsOracleSelectGeoraster::QgsOracleSelectGeoraster( QWidget* parent,
Expand Down Expand Up @@ -199,7 +199,7 @@ void QgsOracleSelectGeoraster::showSelection( const QString & line )
* Try to open georaster dataset
*/

hDS = GDALOpenShared( TO8( identification ), eAccess );
hDS = GDALOpenShared( TO8F( identification ), eAccess );

buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
if ( hDS == NULL )
Expand Down
2 changes: 1 addition & 1 deletion src/providers/gdal/qgsgdaldataitems.cpp
Expand Up @@ -240,7 +240,7 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
// do not print errors, but write to debug
CPLPushErrorHandler( CPLQuietErrorHandler );
CPLErrorReset();
if ( ! GDALIdentifyDriver( thePath.toLocal8Bit().constData(), 0 ) )
if ( ! GDALIdentifyDriver( TO8F( thePath ), 0 ) )
{
QgsDebugMsgLevel( "Skipping VRT file because root is not a GDAL VRT", 2 );
CPLPopErrorHandler();
Expand Down
2 changes: 1 addition & 1 deletion src/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -2505,7 +2505,7 @@ QGISEXTERN QgsGdalProvider * create(
//create dataset
CPLErrorReset();
char **papszOptions = papszFromStringList( createOptions );
GDALDatasetH dataset = GDALCreate( driver, uri.toLocal8Bit().data(), width, height, nBands, ( GDALDataType )type, papszOptions );
GDALDatasetH dataset = GDALCreate( driver, TO8F( uri ), width, height, nBands, ( GDALDataType )type, papszOptions );
CSLDestroy( papszOptions );
if ( dataset == NULL )
{
Expand Down

0 comments on commit 618ffa0

Please sign in to comment.