Skip to content

Commit 1113c60

Browse files
committedApr 29, 2013
fix .cpg file contents
1 parent 1959182 commit 1113c60

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed
 

‎src/core/qgsvectorfilewriter.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ QgsVectorFileWriter::QgsVectorFileWriter(
113113
{
114114
if ( layOptions.join( "" ).toUpper().indexOf( "ENCODING=" ) == -1 )
115115
{
116-
layOptions.append( "ENCODING=" + fileEncoding );
116+
layOptions.append( "ENCODING=" + convertCodecNameForEncodingOption( fileEncoding ) );
117117
}
118118

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

1026+
QString QgsVectorFileWriter::convertCodecNameForEncodingOption( const QString &codecName )
1027+
{
1028+
if ( codecName == "System" )
1029+
return QString( "LDID/0" );
1030+
1031+
QRegExp re = QRegExp( QString( "(CP|windows-|ISO[ -])(.+)" ), Qt::CaseInsensitive );
1032+
if ( re.exactMatch( codecName ) )
1033+
{
1034+
QString c = re.cap( 2 ).replace( "-" , "" );
1035+
bool isNumber;
1036+
c.toInt( &isNumber );
1037+
if ( isNumber )
1038+
return c;
1039+
}
1040+
return codecName;
1041+
}
1042+
10261043
bool QgsVectorFileWriter::driverMetadata( QString driverName, QString &longName, QString &trLongName, QString &glob, QString &ext )
10271044
{
10281045
if ( driverName.startsWith( "AVCE00" ) )

‎src/core/qgsvectorfilewriter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ class CORE_EXPORT QgsVectorFileWriter
123123
/**Creates a filter for an OGR driver key*/
124124
static QString filterForDriver( const QString& driverName );
125125

126+
/**Converts codec name to string passed to ENCODING layer creation option of OGR Shapefile*/
127+
static QString convertCodecNameForEncodingOption( const QString &codecName );
128+
126129
/** checks whether there were any errors in constructor */
127130
WriterError hasError();
128131

‎src/providers/ogr/qgsogrprovider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1850,7 +1850,7 @@ QGISEXTERN bool createEmptyDataSource( const QString &uri,
18501850
char **papszOptions = NULL;
18511851
if ( driverName == "ESRI Shapefile" )
18521852
{
1853-
papszOptions = CSLSetNameValue( papszOptions, "ENCODING", encoding.toLocal8Bit().data() );
1853+
papszOptions = CSLSetNameValue( papszOptions, "ENCODING", QgsVectorFileWriter::convertCodecNameForEncodingOption( encoding ).toLocal8Bit().data() );
18541854
// OGR Shapefile fails to create fields if given encoding is not supported by its side
18551855
// so disable encoding conversion of OGR Shapefile layer
18561856
CPLSetConfigOption( "SHAPE_ENCODING", "" );

0 commit comments

Comments
 (0)
Please sign in to comment.