Skip to content

Commit

Permalink
If ignoreShapeEncoding is false, clear SHAPE_ENCODING after creating …
Browse files Browse the repository at this point in the history
…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 6899a17
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/core/qgsvectorfilewriter.cpp
Expand Up @@ -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";
Expand Down Expand Up @@ -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 )
Expand All @@ -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" )
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/spit/qgsshapefile.cpp
Expand Up @@ -25,6 +25,7 @@
#include <QLabel>
#include <QTextCodec>
#include <QFileInfo>
#include <QSettings>

#include "qgsapplication.h"
#include "cpl_error.h"
Expand All @@ -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 )
{
Expand Down
7 changes: 7 additions & 0 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -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" ) );
Expand Down

0 comments on commit 6899a17

Please sign in to comment.