Skip to content
Permalink
Browse files

fix .cpg file contents

  • Loading branch information
minorua committed Apr 29, 2013
1 parent 1959182 commit 1113c6099a41fe41cfde92c351eb2d303104d0f1
Showing with 22 additions and 2 deletions.
  1. +18 −1 src/core/qgsvectorfilewriter.cpp
  2. +3 −0 src/core/qgsvectorfilewriter.h
  3. +1 −1 src/providers/ogr/qgsogrprovider.cpp
@@ -113,7 +113,7 @@ QgsVectorFileWriter::QgsVectorFileWriter(
{
if ( layOptions.join( "" ).toUpper().indexOf( "ENCODING=" ) == -1 )
{
layOptions.append( "ENCODING=" + fileEncoding );
layOptions.append( "ENCODING=" + convertCodecNameForEncodingOption( fileEncoding ) );
}

CPLSetConfigOption( "SHAPE_ENCODING", "" );
@@ -1023,6 +1023,23 @@ QString QgsVectorFileWriter::filterForDriver( const QString& driverName )
return trLongName + " [OGR] (" + glob.toLower() + " " + glob.toUpper() + ")";
}

QString QgsVectorFileWriter::convertCodecNameForEncodingOption( const QString &codecName )
{
if ( codecName == "System" )
return QString( "LDID/0" );

QRegExp re = QRegExp( QString( "(CP|windows-|ISO[ -])(.+)" ), Qt::CaseInsensitive );
if ( re.exactMatch( codecName ) )
{
QString c = re.cap( 2 ).replace( "-" , "" );
bool isNumber;
c.toInt( &isNumber );
if ( isNumber )
return c;
}
return codecName;
}

bool QgsVectorFileWriter::driverMetadata( QString driverName, QString &longName, QString &trLongName, QString &glob, QString &ext )
{
if ( driverName.startsWith( "AVCE00" ) )
@@ -123,6 +123,9 @@ class CORE_EXPORT QgsVectorFileWriter
/**Creates a filter for an OGR driver key*/
static QString filterForDriver( const QString& driverName );

/**Converts codec name to string passed to ENCODING layer creation option of OGR Shapefile*/
static QString convertCodecNameForEncodingOption( const QString &codecName );

/** checks whether there were any errors in constructor */
WriterError hasError();

@@ -1850,7 +1850,7 @@ QGISEXTERN bool createEmptyDataSource( const QString &uri,
char **papszOptions = NULL;
if ( driverName == "ESRI Shapefile" )
{
papszOptions = CSLSetNameValue( papszOptions, "ENCODING", encoding.toLocal8Bit().data() );
papszOptions = CSLSetNameValue( papszOptions, "ENCODING", QgsVectorFileWriter::convertCodecNameForEncodingOption( encoding ).toLocal8Bit().data() );
// OGR Shapefile fails to create fields if given encoding is not supported by its side
// so disable encoding conversion of OGR Shapefile layer
CPLSetConfigOption( "SHAPE_ENCODING", "" );

0 comments on commit 1113c60

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