Skip to content

Commit b05abdf

Browse files
committed
Merge pull request #800 from minorua/8440
If ignoreShapeEncoding is false, clear SHAPE_ENCODING after creating shapefile with SHAPE_ENCODING="" (fix #8440)
2 parents 6937e4f + 6899a17 commit b05abdf

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/core/qgsvectorfilewriter.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,6 @@ QgsVectorFileWriter::QgsVectorFileWriter(
125125
layOptions.append( "ENCODING=" + convertCodecNameForEncodingOption( fileEncoding ) );
126126
}
127127

128-
CPLSetConfigOption( "SHAPE_ENCODING", "" );
129-
130128
if ( driverName == "ESRI Shapefile" && !vectorFileName.endsWith( ".shp", Qt::CaseInsensitive ) )
131129
{
132130
vectorFileName += ".shp";
@@ -270,6 +268,9 @@ QgsVectorFileWriter::QgsVectorFileWriter(
270268
options[ layOptions.size()] = NULL;
271269
}
272270

271+
// disable encoding conversion of OGR Shapefile layer
272+
CPLSetConfigOption( "SHAPE_ENCODING", "" );
273+
273274
mLayer = OGR_DS_CreateLayer( mDS, TO8F( layerName ), ogrRef, wkbType, options );
274275

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

284+
QSettings settings;
285+
if ( !settings.value( "/qgis/ignoreShapeEncoding", true ).toBool() )
286+
{
287+
CPLSetConfigOption( "SHAPE_ENCODING", 0 );
288+
}
289+
283290
if ( srs )
284291
{
285292
if ( ogrDriverName == "ESRI Shapefile" )

src/plugins/spit/qgsshapefile.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <QLabel>
2626
#include <QTextCodec>
2727
#include <QFileInfo>
28+
#include <QSettings>
2829

2930
#include "qgsapplication.h"
3031
#include "cpl_error.h"
@@ -45,6 +46,10 @@ QgsShapeFile::QgsShapeFile( QString name, QString encoding )
4546
fileName = name;
4647
features = 0;
4748
QgsApplication::registerOgrDrivers();
49+
50+
QSettings settings;
51+
CPLSetConfigOption( "SHAPE_ENCODING", settings.value( "/qgis/ignoreShapeEncoding", true ).toBool() ? "" : 0 );
52+
4853
ogrDataSource = OGROpen( TO8F( fileName ), false, NULL );
4954
if ( ogrDataSource != NULL )
5055
{

src/providers/ogr/qgsogrprovider.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,6 +2025,13 @@ QGISEXTERN bool createEmptyDataSource( const QString &uri,
20252025
OGRLayerH layer;
20262026
layer = OGR_DS_CreateLayer( dataSource, TO8F( QFileInfo( uri ).completeBaseName() ), reference, OGRvectortype, papszOptions );
20272027
CSLDestroy( papszOptions );
2028+
2029+
QSettings settings;
2030+
if ( !settings.value( "/qgis/ignoreShapeEncoding", true ).toBool() )
2031+
{
2032+
CPLSetConfigOption( "SHAPE_ENCODING", 0 );
2033+
}
2034+
20282035
if ( !layer )
20292036
{
20302037
QgsMessageLog::logMessage( QObject::tr( "Creation of OGR data source %1 failed: %2" ).arg( uri ).arg( QString::fromUtf8( CPLGetLastErrorMsg() ) ), QObject::tr( "OGR" ) );

0 commit comments

Comments
 (0)