Skip to content

Commit

Permalink
fix #2151
Browse files Browse the repository at this point in the history
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 af24fd4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/core/qgsvectorfilewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <QFileInfo>
#include <QTextCodec>
#include <QTextStream>
#include <QSet>

#include <cassert>
#include <cstdlib> // size_t
Expand Down Expand Up @@ -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 )
Expand Down
21 changes: 19 additions & 2 deletions src/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 ) );
Expand Down

0 comments on commit af24fd4

Please sign in to comment.