Skip to content
Permalink
Browse files

Merge pull request #566 from minorua/fix_cpg

Encoding: produce more compatible .cpg files.
  • Loading branch information
borysiasty committed Apr 29, 2013
2 parents c5177fc + 1113c60 commit 62c5e6315bc4747f2cdda3bcd29d5a1c1507f5ca
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 62c5e63

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