[QGIS Commit] r15148 - in trunk/qgis/src: analysis/raster analysis/vector app/ogr core/raster mapserver plugins/georeferencer plugins/ogr_converter plugins/oracle_raster plugins/spit providers/ogr

svn_qgis at osgeo.org svn_qgis at osgeo.org
Wed Feb 9 11:27:17 EST 2011


Author: jef
Date: 2011-02-09 08:27:17 -0800 (Wed, 09 Feb 2011)
New Revision: 15148

Modified:
   trunk/qgis/src/analysis/raster/qgsninecellfilter.cpp
   trunk/qgis/src/analysis/raster/qgsrastercalculator.cpp
   trunk/qgis/src/analysis/raster/qgsrastercalculator.h
   trunk/qgis/src/analysis/vector/qgszonalstatistics.cpp
   trunk/qgis/src/app/ogr/qgsnewogrconnection.cpp
   trunk/qgis/src/core/raster/qgsrasterlayer.cpp
   trunk/qgis/src/mapserver/qgssldparser.cpp
   trunk/qgis/src/plugins/georeferencer/qgsimagewarper.cpp
   trunk/qgis/src/plugins/ogr_converter/dialog.cpp
   trunk/qgis/src/plugins/ogr_converter/translator.cpp
   trunk/qgis/src/plugins/oracle_raster/qgsselectgeoraster_ui.cpp
   trunk/qgis/src/plugins/spit/qgsshapefile.cpp
   trunk/qgis/src/providers/ogr/qgsogrprovider.cpp
Log:
add support for UTF8 in GDAL/OGR 1.8 (fixes #2551)

Modified: trunk/qgis/src/analysis/raster/qgsninecellfilter.cpp
===================================================================
--- trunk/qgis/src/analysis/raster/qgsninecellfilter.cpp	2011-02-09 16:27:05 UTC (rev 15147)
+++ trunk/qgis/src/analysis/raster/qgsninecellfilter.cpp	2011-02-09 16:27:17 UTC (rev 15148)
@@ -19,6 +19,11 @@
 #include "cpl_string.h"
 #include <QProgressDialog>
 
+#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
+#define TO8(x) (x).toUtf8().constData()
+#else
+#define TO8(x) (x).toLocal8Bit().constData()
+#endif
 
 QgsNineCellFilter::QgsNineCellFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat ): \
     mInputFile( inputFile ), mOutputFile( outputFile ), mOutputFormat( outputFormat ), mCellSizeX( -1 ), mCellSizeY( -1 ), mInputNodataValue( -1 ), mOutputNodataValue( -1 )
@@ -191,7 +196,7 @@
 
 GDALDatasetH QgsNineCellFilter::openInputFile( int& nCellsX, int& nCellsY )
 {
-  GDALDatasetH inputDataset = GDALOpen( mInputFile.toLocal8Bit().data(), GA_ReadOnly );
+  GDALDatasetH inputDataset = GDALOpen( TO8( mInputFile ), GA_ReadOnly );
   if ( inputDataset != NULL )
   {
     nCellsX = GDALGetRasterXSize( inputDataset );

Modified: trunk/qgis/src/analysis/raster/qgsrastercalculator.cpp
===================================================================
--- trunk/qgis/src/analysis/raster/qgsrastercalculator.cpp	2011-02-09 16:27:05 UTC (rev 15147)
+++ trunk/qgis/src/analysis/raster/qgsrastercalculator.cpp	2011-02-09 16:27:17 UTC (rev 15148)
@@ -24,6 +24,12 @@
 
 #include "gdalwarper.h"
 
+#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
+#define TO8(x) (x).toUtf8().constData()
+#else
+#define TO8(x) (x).toLocal8Bit().constData()
+#endif
+
 QgsRasterCalculator::QgsRasterCalculator( const QString& formulaString, const QString& outputFile, const QString& outputFormat,
     const QgsRectangle& outputExtent, int nOutputColumns, int nOutputRows, const QVector<QgsRasterCalculatorEntry>& rasterEntries ): mFormulaString( formulaString ), mOutputFile( outputFile ), mOutputFormat( outputFormat ),
     mOutputRectangle( outputExtent ), mNumOutputColumns( nOutputColumns ), mNumOutputRows( nOutputRows ), mRasterEntries( rasterEntries )
@@ -59,7 +65,7 @@
     {
       return 2;
     }
-    GDALDatasetH inputDataset = GDALOpen( it->raster->source().toLocal8Bit().data(), GA_ReadOnly );
+    GDALDatasetH inputDataset = GDALOpen( TO8( it->raster->source() ), GA_ReadOnly );
     if ( inputDataset == NULL )
     {
       return 2;

Modified: trunk/qgis/src/analysis/raster/qgsrastercalculator.h
===================================================================
--- trunk/qgis/src/analysis/raster/qgsrastercalculator.h	2011-02-09 16:27:05 UTC (rev 15147)
+++ trunk/qgis/src/analysis/raster/qgsrastercalculator.h	2011-02-09 16:27:17 UTC (rev 15148)
@@ -61,8 +61,22 @@
     GDALDatasetH openOutputFile( GDALDriverH outputDriver );
 
     /**Reads raster pixels from a dataset/band
-      @param targetGeotransformation transformation parameters of the requested raster array (not necessarily the same as the transform of the source dataset */
-    void readRasterPart( double* targetGeotransform, int xOffset, int yOffset, int nCols, int nRows, double* sourceTransform, GDALRasterBandH sourceBand, float* rasterBuffer );
+      @param targetGeotransform transformation parameters of the requested raster array
+                                (not necessarily the same as the transform of the source dataset)
+      @param xOffset x offset
+      @param yOffset y offset
+      @param nCols number of columns
+      @param nRows number of rows
+      @param sourceTransform source transformation
+      @param sourceBand source band
+      @param rasterBuffer raster buffer
+      */
+    void readRasterPart( double* targetGeotransform,
+                         int xOffset, int yOffset,
+                         int nCols, int nRows,
+                         double* sourceTransform,
+                         GDALRasterBandH sourceBand,
+                         float* rasterBuffer );
 
     /**Compares two geotransformations (six parameter double arrays*/
     bool transformationsEqual( double* t1, double* t2 ) const;

Modified: trunk/qgis/src/analysis/vector/qgszonalstatistics.cpp
===================================================================
--- trunk/qgis/src/analysis/vector/qgszonalstatistics.cpp	2011-02-09 16:27:05 UTC (rev 15147)
+++ trunk/qgis/src/analysis/vector/qgszonalstatistics.cpp	2011-02-09 16:27:17 UTC (rev 15148)
@@ -23,6 +23,12 @@
 #include "cpl_string.h"
 #include <QProgressDialog>
 
+#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
+#define TO8(x) (x).toUtf8().constData()
+#else
+#define TO8(x) (x).toLocal8Bit().constData()
+#endif
+
 QgsZonalStatistics::QgsZonalStatistics( QgsVectorLayer* polygonLayer, const QString& rasterFile, const QString& attributePrefix, int rasterBand )
     : mRasterFilePath( rasterFile )
     , mRasterBand( rasterBand )
@@ -60,7 +66,7 @@
 
   //open the raster layer and the raster band
   GDALAllRegister();
-  GDALDatasetH inputDataset = GDALOpen( mRasterFilePath.toLocal8Bit().data(), GA_ReadOnly );
+  GDALDatasetH inputDataset = GDALOpen( TO8( mRasterFilePath ), GA_ReadOnly );
   if ( inputDataset == NULL )
   {
     return 3;

Modified: trunk/qgis/src/app/ogr/qgsnewogrconnection.cpp
===================================================================
--- trunk/qgis/src/app/ogr/qgsnewogrconnection.cpp	2011-02-09 16:27:05 UTC (rev 15147)
+++ trunk/qgis/src/app/ogr/qgsnewogrconnection.cpp	2011-02-09 16:27:17 UTC (rev 15148)
@@ -29,6 +29,11 @@
 #include <ogr_api.h>
 #include <cpl_error.h>
 
+#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
+#define TO8F(x) (x).toUtf8().constData()
+#else
+#define TO8F(x) QFile::encodeName( x ).constData()
+#endif
 
 QgsNewOgrConnection::QgsNewOgrConnection( QWidget *parent, const QString& connType, const QString& connName, Qt::WFlags fl )
     : QDialog( parent, fl ),
@@ -83,7 +88,7 @@
   OGRDataSourceH       poDS;
   OGRSFDriverH         pahDriver;
   CPLErrorReset();
-  poDS = OGROpen( QFile::encodeName( uri ).constData(), false, &pahDriver );
+  poDS = OGROpen( TO8F( uri ), false, &pahDriver );
   if ( poDS == NULL )
   {
     QMessageBox::information( this, tr( "Test connection" ), tr( "Connection failed - Check settings and try again.\n\nExtended error information:\n%1" ).arg( QString::fromUtf8( CPLGetLastErrorMsg() ) ) );

Modified: trunk/qgis/src/core/raster/qgsrasterlayer.cpp
===================================================================
--- trunk/qgis/src/core/raster/qgsrasterlayer.cpp	2011-02-09 16:27:05 UTC (rev 15147)
+++ trunk/qgis/src/core/raster/qgsrasterlayer.cpp	2011-02-09 16:27:17 UTC (rev 15148)
@@ -74,6 +74,11 @@
 // doubles can take for the current system.  (Yes, 20 was arbitrary.)
 #define TINY_VALUE  std::numeric_limits<double>::epsilon() * 20
 
+#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
+#define TO8F(x) (x).toUtf8().constData()
+#else
+#define TO8F(x) QFile::encodeName( x ).constData()
+#endif
 
 QgsRasterLayer::QgsRasterLayer(
   QString const & path,
@@ -452,7 +457,7 @@
   CPLErrorReset();
 
   //open the file using gdal making sure we have handled locale properly
-  myDataset = GDALOpen( QFile::encodeName( theFileNameQString ).constData(), GA_ReadOnly );
+  myDataset = GDALOpen( TO8F( theFileNameQString ), GA_ReadOnly );
   if ( myDataset == NULL )
   {
     if ( CPLGetLastErrorNo() != CPLE_OpenFailed )
@@ -1002,12 +1007,12 @@
 
     //close the gdal dataset and reopen it in read / write mode
     GDALClose( mGdalDataset );
-    mGdalBaseDataset = GDALOpen( QFile::encodeName( mDataSource ).constData(), GA_Update );
+    mGdalBaseDataset = GDALOpen( TO8F( mDataSource ), GA_Update );
 
     // if the dataset couldn't be opened in read / write mode, tell the user
     if ( !mGdalBaseDataset )
     {
-      mGdalBaseDataset = GDALOpen( QFile::encodeName( mDataSource ).constData(), GA_ReadOnly );
+      mGdalBaseDataset = GDALOpen( TO8F( mDataSource ), GA_ReadOnly );
       //Since we are not a virtual warped dataset, mGdalDataSet and mGdalBaseDataset are supposed to be the same
       mGdalDataset = mGdalBaseDataset;
       return "ERROR_WRITE_FORMAT";
@@ -1077,7 +1082,7 @@
           //something bad happenend
           //QString myString = QString (CPLGetLastError());
           GDALClose( mGdalBaseDataset );
-          mGdalBaseDataset = GDALOpen( QFile::encodeName( mDataSource ).constData(), GA_ReadOnly );
+          mGdalBaseDataset = GDALOpen( TO8F( mDataSource ), GA_ReadOnly );
           //Since we are not a virtual warped dataset, mGdalDataSet and mGdalBaseDataset are supposed to be the same
           mGdalDataset = mGdalBaseDataset;
 
@@ -1104,7 +1109,7 @@
   {
     //close the gdal dataset and reopen it in read only mode
     GDALClose( mGdalBaseDataset );
-    mGdalBaseDataset = GDALOpen( QFile::encodeName( mDataSource ).constData(), GA_ReadOnly );
+    mGdalBaseDataset = GDALOpen( TO8F( mDataSource ), GA_ReadOnly );
     //Since we are not a virtual warped dataset, mGdalDataSet and mGdalBaseDataset are supposed to be the same
     mGdalDataset = mGdalBaseDataset;
   }
@@ -5299,7 +5304,7 @@
   mGdalDataset = NULL;
 
   //open the dataset making sure we handle char encoding of locale properly
-  mGdalBaseDataset = GDALOpen( QFile::encodeName( theFilename ).constData(), GA_ReadOnly );
+  mGdalBaseDataset = GDALOpen( TO8F( theFilename ), GA_ReadOnly );
 
   if ( mGdalBaseDataset == NULL )
   {

Modified: trunk/qgis/src/mapserver/qgssldparser.cpp
===================================================================
--- trunk/qgis/src/mapserver/qgssldparser.cpp	2011-02-09 16:27:05 UTC (rev 15147)
+++ trunk/qgis/src/mapserver/qgssldparser.cpp	2011-02-09 16:27:17 UTC (rev 15148)
@@ -76,6 +76,12 @@
 #include "qgsidwinterpolator.h"
 #include "qgstininterpolator.h"
 
+#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
+#define TO8(x) (x).toUtf8().constData()
+#else
+#define TO8(x) (x).toLocal8Bit().constData()
+#endif
+
 QgsSLDParser::QgsSLDParser( QDomDocument* doc ): QgsConfigParser(), mXMLDoc( doc )
 {
   mSLDNamespace = "http://www.opengis.net/sld";
@@ -1279,15 +1285,6 @@
   GDALRasterBandH hBand;
   GDALDatasetH hSrcDS;
 
-  QByteArray pszSrcData = rasterLayer->source().toLocal8Bit();
-  QByteArray pszDstData = tmpFileName.toLocal8Bit();
-  QByteArray pszElevData = propertyName.toLocal8Bit();
-
-  const char *pszSrcFilename = pszSrcData.data();
-  const char *pszDstFilename = pszDstData.data();
-  const char *pszElevAttrib = pszElevData.data();
-  const char *pszFormat = "ESRI Shapefile";
-
   int numberOfLevels = 0;
   double currentLevel = 0.0;
 
@@ -1315,7 +1312,7 @@
 
   int b3D = FALSE, bNoDataSet = FALSE, bIgnoreNoData = FALSE;
 
-  hSrcDS = GDALOpen( pszSrcFilename, GA_ReadOnly );
+  hSrcDS = GDALOpen( TO8( rasterLayer->source() ), GA_ReadOnly );
   if ( hSrcDS == NULL )
     exit( 2 );
 
@@ -1344,19 +1341,18 @@
   /*      Create the outputfile.                                          */
   /* -------------------------------------------------------------------- */
   OGRDataSourceH hDS;
-  OGRSFDriverH hDriver = OGRGetDriverByName( pszFormat );
+  OGRSFDriverH hDriver = OGRGetDriverByName( "ESRI Shapefile" );
   OGRFieldDefnH hFld;
   OGRLayerH hLayer;
   int nElevField = -1;
 
   if ( hDriver == NULL )
   {
-    fprintf( FCGI_stderr, "Unable to find format driver named %s.\n",
-             pszFormat );
+    fprintf( FCGI_stderr, "Unable to find format driver named 'ESRI Shapefile'.\n" );
     exit( 10 );
   }
 
-  hDS = OGR_Dr_CreateDataSource( hDriver, pszDstFilename, NULL );
+  hDS = OGR_Dr_CreateDataSource( hDriver, TO8( tmpFileName ), NULL );
   if ( hDS == NULL )
     exit( 1 );
 
@@ -1371,9 +1367,9 @@
   OGR_L_CreateField( hLayer, hFld, FALSE );
   OGR_Fld_Destroy( hFld );
 
-  if ( pszElevAttrib )
+  if ( !propertyName.isEmpty() )
   {
-    hFld = OGR_Fld_Create( pszElevAttrib, OFTReal );
+    hFld = OGR_Fld_Create( TO8( propertyName ), OFTReal );
     OGR_Fld_SetWidth( hFld, 12 );
     OGR_Fld_SetPrecision( hFld, 3 );
     OGR_L_CreateField( hLayer, hFld, FALSE );

Modified: trunk/qgis/src/plugins/georeferencer/qgsimagewarper.cpp
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgsimagewarper.cpp	2011-02-09 16:27:05 UTC (rev 15147)
+++ trunk/qgis/src/plugins/georeferencer/qgsimagewarper.cpp	2011-02-09 16:27:17 UTC (rev 15148)
@@ -31,6 +31,12 @@
 #include "qgsimagewarper.h"
 #include "qgsgeoreftransform.h"
 
+#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
+#define TO8F(x) (x).toUtf8().constData()
+#else
+#define TO8F(x) QFile::encodeName( x ).constData()
+#endif
+
 bool QgsImageWarper::mWarpCanceled = false;
 
 QgsImageWarper::QgsImageWarper( QWidget *theParent )
@@ -44,7 +50,7 @@
 {
   // Open input file
   GDALAllRegister();
-  hSrcDS = GDALOpen( QFile::encodeName( input ).constData(), GA_ReadOnly );
+  hSrcDS = GDALOpen( TO8F( input ), GA_ReadOnly );
   if ( hSrcDS == NULL ) return false;
 
   // Setup warp options.

Modified: trunk/qgis/src/plugins/ogr_converter/dialog.cpp
===================================================================
--- trunk/qgis/src/plugins/ogr_converter/dialog.cpp	2011-02-09 16:27:05 UTC (rev 15147)
+++ trunk/qgis/src/plugins/ogr_converter/dialog.cpp	2011-02-09 16:27:17 UTC (rev 15148)
@@ -32,6 +32,12 @@
 
 #include <ogr_api.h>
 
+#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
+#define TO8(x) (x).toUtf8().constData()
+#else
+#define TO8(x) (x).toLocal8Bit().constData()
+#endif
+
 Dialog::Dialog( QWidget* parent, Qt::WFlags fl )
     : QDialog( parent, fl )
 {
@@ -158,7 +164,7 @@
 {
   comboSrcLayer->clear();
 
-  OGRDataSourceH ds = OGROpen( url.toAscii().constData(), 0, 0 );
+  OGRDataSourceH ds = OGROpen( TO8( url ), 0, 0 );
   if ( 0 != ds )
   {
     QString lyrName;
@@ -199,7 +205,7 @@
 {
   bool success = false;
 
-  OGRDataSourceH ds = OGROpen( url.toAscii().constData(), 0, 0 );
+  OGRDataSourceH ds = OGROpen( TO8( url ), 0, 0 );
   if ( 0 != ds )
   {
     success = true;

Modified: trunk/qgis/src/plugins/ogr_converter/translator.cpp
===================================================================
--- trunk/qgis/src/plugins/ogr_converter/translator.cpp	2011-02-09 16:27:05 UTC (rev 15147)
+++ trunk/qgis/src/plugins/ogr_converter/translator.cpp	2011-02-09 16:27:17 UTC (rev 15148)
@@ -23,6 +23,14 @@
 #include <ogr_api.h>
 #include <cpl_error.h>
 
+#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
+#define TO8(x)  (x).toUtf8().constData()
+#define FROM8(x) QString::fromUtf8(x)
+#else
+#define TO8(x)  (x).toLocal8Bit().constData()
+#define FROM8(x) QString::fromLocal8Bit(x)
+#endif
+
 Translator::Translator()
     : mDstUpdate( false ), mDstLayerOverwrite( true )
 {
@@ -125,7 +133,7 @@
   // TODO: Support translation of all layers from input data source
   //for (int i = 0; i < OGR_DS_GetLayerCount(); ++i)
 
-  OGRLayerH srcLayer = OGR_DS_GetLayerByName( srcDs, mSrcLayer.toAscii().constData() );
+  OGRLayerH srcLayer = OGR_DS_GetLayerByName( srcDs, TO8( mSrcLayer ) );
   if ( 0 == srcLayer )
   {
     QgsDebugMsg( "Can not find layer: " + mSrcLayer );
@@ -201,13 +209,12 @@
     // TODO: Implement SRS transformation
     OGRSpatialReferenceH dstLayerSrs = OGR_L_GetSpatialRef( srcLayer );
 
-    dstLayer = OGR_DS_CreateLayer( dstDs, mDstLayer.toAscii().constData(),
-                                   dstLayerSrs, geomType, 0 );
+    dstLayer = OGR_DS_CreateLayer( dstDs, TO8( mDstLayer ), dstLayerSrs, geomType, 0 );
   }
 
   if ( 0 == dstLayer )
   {
-    qWarning() << QString("Layer %1 not found and CreateLayer failed [OGR: %2]\n" ).arg( mDstLayer ).arg( CPLGetLastErrorMsg() );
+    qWarning() << QString( "Layer %1 not found and CreateLayer failed [OGR: %2]\n" ).arg( mDstLayer ).arg( CPLGetLastErrorMsg() );
     return false;
   }
 
@@ -379,7 +386,8 @@
 
 OGRDataSourceH Translator::openDataSource( QString const& url, bool readOnly )
 {
-  OGRDataSourceH ds = OGROpen( url.toAscii().constData(), !readOnly, 0 );
+  OGRDataSourceH ds = OGROpen( TO8( url ), !readOnly, 0 );
+
   if ( 0 == ds )
   {
     QgsDebugMsg( "Failed to open: " + url );
@@ -410,7 +418,7 @@
     // Create the output data source
     //
     // TODO: Add support for creation options
-    ds = OGR_Dr_CreateDataSource( drv, url.toAscii().constData(), 0 );
+    ds = OGR_Dr_CreateDataSource( drv, TO8( url ), 0 );
     if ( 0 == ds )
     {
       QgsDebugMsg( "Failed to open: " + url );

Modified: trunk/qgis/src/plugins/oracle_raster/qgsselectgeoraster_ui.cpp
===================================================================
--- trunk/qgis/src/plugins/oracle_raster/qgsselectgeoraster_ui.cpp	2011-02-09 16:27:05 UTC (rev 15147)
+++ trunk/qgis/src/plugins/oracle_raster/qgsselectgeoraster_ui.cpp	2011-02-09 16:27:17 UTC (rev 15148)
@@ -26,6 +26,12 @@
 
 #include "qgsvectorlayer.h"
 
+#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
+#define TO8(x) (x).toUtf8().constData()
+#else
+#define TO8(x) (x).toLocal8Bit().constData()
+#endif
+
 QgsOracleSelectGeoraster::QgsOracleSelectGeoraster( QWidget* parent,
     QgisInterface* iface,
     Qt::WFlags fl ) : QDialog( parent, fl ), mIface( iface )
@@ -187,7 +193,7 @@
    *  Try to open georaster dataset
    */
 
-  hDS = GDALOpenShared( identification.toAscii(), eAccess );
+  hDS = GDALOpenShared( TO8( identification ), eAccess );
 
   buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
   if ( hDS == NULL )

Modified: trunk/qgis/src/plugins/spit/qgsshapefile.cpp
===================================================================
--- trunk/qgis/src/plugins/spit/qgsshapefile.cpp	2011-02-09 16:27:05 UTC (rev 15147)
+++ trunk/qgis/src/plugins/spit/qgsshapefile.cpp	2011-02-09 16:27:17 UTC (rev 15148)
@@ -47,13 +47,18 @@
 #include <netinet/in.h>
 #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
 
 QgsShapeFile::QgsShapeFile( QString name, QString encoding )
 {
   fileName = name;
   features = 0;
   QgsApplication::registerOgrDrivers();
-  ogrDataSource = OGROpen( QFile::encodeName( fileName ).constData(), false, NULL );
+  ogrDataSource = OGROpen( TO8F( fileName ), false, NULL );
   if ( ogrDataSource != NULL )
   {
     valid = true;

Modified: trunk/qgis/src/providers/ogr/qgsogrprovider.cpp
===================================================================
--- trunk/qgis/src/providers/ogr/qgsogrprovider.cpp	2011-02-09 16:27:05 UTC (rev 15147)
+++ trunk/qgis/src/providers/ogr/qgsogrprovider.cpp	2011-02-09 16:27:17 UTC (rev 15148)
@@ -54,6 +54,16 @@
   + GDALVersionInfo( "RELEASE_NAME" )
   + ")";
 
+#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
+#define TO8(x)   (x).toUtf8().constData()
+#define TO8F(x)  (x).toUtf8().constData()
+#define FROM8(x) QString::fromUtf8(x)
+#else
+#define TO8(x)   (x).toLocal8Bit().constData()
+#define TO8F(x)  QFile::encodeName( x ).constData()
+#define FROM8(x) QString::fromLocal8Bit(x)
+#endif
+
 class QgsCPLErrorHandler
 {
     static void CPL_STDCALL showError( CPLErr errClass, int errNo, const char *msg )
@@ -146,12 +156,12 @@
   QgsDebugMsg( "mLayerName: " + mLayerName );
   QgsDebugMsg( "mSubsetString: " + mSubsetString );
   CPLSetConfigOption( "OGR_ORGANIZE_POLYGONS", "ONLY_CCW" );  // "SKIP" returns MULTIPOLYGONs for multiringed POLYGONs
-  ogrDataSource = OGROpen( QFile::encodeName( mFilePath ).constData(), true, &ogrDriver );
 
+  ogrDataSource = OGROpen( TO8F( mFilePath ), true, &ogrDriver );
   if ( ogrDataSource == NULL )
   {
     // try to open read-only
-    ogrDataSource = OGROpen( QFile::encodeName( mFilePath ).constData(), false, &ogrDriver );
+    ogrDataSource = OGROpen( TO8F( mFilePath ), false, &ogrDriver );
 
     //TODO Need to set a flag or something to indicate that the layer
     //TODO is in read-only mode, otherwise edit ops will fail
@@ -175,7 +185,7 @@
     }
     else
     {
-      ogrOrigLayer = OGR_DS_GetLayerByName( ogrDataSource, mLayerName.toLocal8Bit().data() );
+      ogrOrigLayer = OGR_DS_GetLayerByName( ogrDataSource, TO8( mLayerName ) );
     }
 
     ogrLayer = ogrOrigLayer;
@@ -307,7 +317,7 @@
   }
   for ( unsigned int i = 0; i < layerCount() ; i++ )
   {
-    QString theLayerName = QString::fromLocal8Bit( OGR_FD_GetName( OGR_L_GetLayerDefn( OGR_DS_GetLayer( ogrDataSource, i ) ) ) );
+    QString theLayerName = FROM8( OGR_FD_GetName( OGR_L_GetLayerDefn( OGR_DS_GetLayer( ogrDataSource, i ) ) ) );
     OGRwkbGeometryType layerGeomType = OGR_FD_GetGeomType( OGR_L_GetLayerDefn( OGR_DS_GetLayer( ogrDataSource, i ) ) );
 
     int theLayerFeatureCount = OGR_L_GetFeatureCount( OGR_DS_GetLayer( ogrDataSource, i ), 1 ) ;



More information about the QGIS-commit mailing list