Skip to content
Permalink
Browse files
fix #2151
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12280 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Nov 28, 2009
1 parent 978dbb5 commit af24fd4e914459060521c5759a8848c679f309f9
Showing with 37 additions and 2 deletions.
  1. +18 −0 src/core/qgsvectorfilewriter.cpp
  2. +19 −2 src/providers/ogr/qgsogrprovider.cpp
@@ -31,6 +31,7 @@
#include <QFileInfo>
#include <QTextCodec>
#include <QTextStream>
#include <QSet>

#include <cassert>
#include <cstdlib> // size_t
@@ -60,6 +61,23 @@ QgsVectorFileWriter::QgsVectorFileWriter( const QString& shapefileName,
return;
}

if ( driverName == "ESRI Shapefile" )
{
// check for unique fieldnames
QSet<QString> fieldNames;
QgsFieldMap::const_iterator fldIt;
for ( fldIt = fields.begin(); fldIt != fields.end(); ++fldIt )
{
QString name = fldIt.value().name().left( 10 );
if ( fieldNames.contains( name ) )
{
mError = ErrAttributeCreationFailed;
return;
}
fieldNames << name;
}
}

// create the data source
mDS = OGR_Dr_CreateDataSource( poDriver, shapefileName.toLocal8Bit().data(), NULL );
if ( mDS == NULL )
@@ -1461,6 +1461,25 @@ QGISEXTERN bool createEmptyDataSource( const QString& uri,
return false;
}

QString driverName = OGR_Dr_GetName( driver );

if ( driverName == "ESRI Shapefile" )
{
// check for duplicate fieldnames
QSet<QString> fieldNames;
std::list<std::pair<QString, QString> >::const_iterator fldIt;
for ( fldIt = attributes.begin(); fldIt != attributes.end(); ++fldIt )
{
QString name = fldIt->first.left( 10 );
if ( fieldNames.contains( name ) )
{
QgsDebugMsg( QString( "duplicate field (10 significant characters): %1" ).arg( name ) );
return false;
}
fieldNames << name;
}
}

OGRDataSourceH dataSource;
dataSource = OGR_Dr_CreateDataSource( driver, QFile::encodeName( uri ).constData(), NULL );
if ( dataSource == NULL )
@@ -1582,8 +1601,6 @@ QGISEXTERN bool createEmptyDataSource( const QString& uri,

OGR_DS_Destroy( dataSource );

QString driverName = OGR_Dr_GetName( driver );

if ( driverName == "ESRI Shapefile" )
{
QString layerName = uri.left( uri.indexOf( ".shp", Qt::CaseInsensitive ) );

0 comments on commit af24fd4

Please sign in to comment.