Showing with 11 additions and 15 deletions.
  1. +2 −12 src/core/qgsvectorfilewriter.cpp
  2. +9 −3 src/providers/ogr/qgsogrprovider.cpp
14 changes: 2 additions & 12 deletions src/core/qgsvectorfilewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,25 +109,14 @@ QgsVectorFileWriter::QgsVectorFileWriter(
return;
}

QSettings settings;

if ( driverName == "ESRI Shapefile" )
{
if ( layOptions.join( "" ).toUpper().indexOf( "ENCODING=" ) == -1 )
{
layOptions.append( "ENCODING=" + fileEncoding );
}

if ( settings.value( "/qgis/ignoreShapeEncoding", true ).toBool() )
{
CPLSetConfigOption( "SHAPE_ENCODING", "" );
}
else
{
CPLSetConfigOption( "SHAPE_ENCODING", fileEncoding.toLocal8Bit().data() );
// WARNING!! If SHAPE_ENCODING and -lco ENCODING are used, the fileEncoding must be set to the layer internal encoding!!
fileEncoding = "UTF-8";
}
CPLSetConfigOption( "SHAPE_ENCODING", "" );

if ( !vectorFileName.endsWith( ".shp", Qt::CaseInsensitive ) &&
!vectorFileName.endsWith( ".dbf", Qt::CaseInsensitive ) )
Expand Down Expand Up @@ -235,6 +224,7 @@ QgsVectorFileWriter::QgsVectorFileWriter(
{
QgsDebugMsg( "error finding QTextCodec for " + fileEncoding );

QSettings settings;
QString enc = settings.value( "/UI/encoding", "System" ).toString();
mCodec = QTextCodec::codecForName( enc.toLocal8Bit().constData() );
if ( !mCodec )
Expand Down
12 changes: 9 additions & 3 deletions src/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ email : sherman at mrcc.com
#include <gdal.h> // to collect version information
#include <ogr_api.h>
#include <ogr_srs_api.h>
#include <cpl_error.h>
#include <cpl_conv.h>
#include <cpl_string.h>

#include <limits>

Expand Down Expand Up @@ -1848,8 +1847,15 @@ QGISEXTERN bool createEmptyDataSource( const QString &uri,
}
}

char **papszOptions = NULL;
if ( driverName == "ESRI Shapefile" )
{
papszOptions = CSLSetNameValue( papszOptions, "ENCODING", encoding.toLocal8Bit().data() );
}

OGRLayerH layer;
layer = OGR_DS_CreateLayer( dataSource, TO8F( QFileInfo( uri ).completeBaseName() ), reference, OGRvectortype, NULL );
layer = OGR_DS_CreateLayer( dataSource, TO8F( QFileInfo( uri ).completeBaseName() ), reference, OGRvectortype, papszOptions );
CSLDestroy( papszOptions );
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