fix .cpg file contents

This commit is contained in:
Minoru Akagi 2013-04-28 12:19:46 +09:00
parent 195918293c
commit 1113c6099a
3 changed files with 22 additions and 2 deletions

View File

@ -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" ) )

View File

@ -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();

View File

@ -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", "" );