Skip to content
Permalink
Browse files

If ignoreShapeEncoding is false, clear SHAPE_ENCODING after creating …

…shapefile with SHAPE_ENCODING="" (fix #8440)

Spit: apply SHAPE_ENCODING to shape layer opening
  • Loading branch information
minorua committed Aug 11, 2013
1 parent 9c4c215 commit 6899a1756c985cf3f66338f13633dd568634e099
Showing with 21 additions and 2 deletions.
  1. +9 −2 src/core/qgsvectorfilewriter.cpp
  2. +5 −0 src/plugins/spit/qgsshapefile.cpp
  3. +7 −0 src/providers/ogr/qgsogrprovider.cpp
@@ -125,8 +125,6 @@ QgsVectorFileWriter::QgsVectorFileWriter(
layOptions.append( "ENCODING=" + convertCodecNameForEncodingOption( fileEncoding ) );
}

CPLSetConfigOption( "SHAPE_ENCODING", "" );

if ( driverName == "ESRI Shapefile" && !vectorFileName.endsWith( ".shp", Qt::CaseInsensitive ) )
{
vectorFileName += ".shp";
@@ -270,6 +268,9 @@ QgsVectorFileWriter::QgsVectorFileWriter(
options[ layOptions.size()] = NULL;
}

// disable encoding conversion of OGR Shapefile layer
CPLSetConfigOption( "SHAPE_ENCODING", "" );

mLayer = OGR_DS_CreateLayer( mDS, TO8F( layerName ), ogrRef, wkbType, options );

if ( options )
@@ -280,6 +281,12 @@ QgsVectorFileWriter::QgsVectorFileWriter(
options = NULL;
}

QSettings settings;
if ( !settings.value( "/qgis/ignoreShapeEncoding", true ).toBool() )
{
CPLSetConfigOption( "SHAPE_ENCODING", 0 );
}

if ( srs )
{
if ( ogrDriverName == "ESRI Shapefile" )
@@ -25,6 +25,7 @@
#include <QLabel>
#include <QTextCodec>
#include <QFileInfo>
#include <QSettings>

#include "qgsapplication.h"
#include "cpl_error.h"
@@ -45,6 +46,10 @@ QgsShapeFile::QgsShapeFile( QString name, QString encoding )
fileName = name;
features = 0;
QgsApplication::registerOgrDrivers();

QSettings settings;
CPLSetConfigOption( "SHAPE_ENCODING", settings.value( "/qgis/ignoreShapeEncoding", true ).toBool() ? "" : 0 );

ogrDataSource = OGROpen( TO8F( fileName ), false, NULL );
if ( ogrDataSource != NULL )
{
@@ -2025,6 +2025,13 @@ QGISEXTERN bool createEmptyDataSource( const QString &uri,
OGRLayerH layer;
layer = OGR_DS_CreateLayer( dataSource, TO8F( QFileInfo( uri ).completeBaseName() ), reference, OGRvectortype, papszOptions );
CSLDestroy( papszOptions );

QSettings settings;
if ( !settings.value( "/qgis/ignoreShapeEncoding", true ).toBool() )
{
CPLSetConfigOption( "SHAPE_ENCODING", 0 );
}

if ( !layer )
{
QgsMessageLog::logMessage( QObject::tr( "Creation of OGR data source %1 failed: %2" ).arg( uri ).arg( QString::fromUtf8( CPLGetLastErrorMsg() ) ), QObject::tr( "OGR" ) );

0 comments on commit 6899a17

Please sign in to comment.
You can’t perform that action at this time.