[QGIS Commit] r12280 - in trunk/qgis/src: core providers/ogr

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Nov 28 18:20:51 EST 2009


Author: jef
Date: 2009-11-28 18:20:50 -0500 (Sat, 28 Nov 2009)
New Revision: 12280

Modified:
   trunk/qgis/src/core/qgsvectorfilewriter.cpp
   trunk/qgis/src/providers/ogr/qgsogrprovider.cpp
Log:
fix #2151

Modified: trunk/qgis/src/core/qgsvectorfilewriter.cpp
===================================================================
--- trunk/qgis/src/core/qgsvectorfilewriter.cpp	2009-11-28 21:20:16 UTC (rev 12279)
+++ trunk/qgis/src/core/qgsvectorfilewriter.cpp	2009-11-28 23:20:50 UTC (rev 12280)
@@ -31,6 +31,7 @@
 #include <QFileInfo>
 #include <QTextCodec>
 #include <QTextStream>
+#include <QSet>
 
 #include <cassert>
 #include <cstdlib> // size_t
@@ -60,6 +61,23 @@
     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 )

Modified: trunk/qgis/src/providers/ogr/qgsogrprovider.cpp
===================================================================
--- trunk/qgis/src/providers/ogr/qgsogrprovider.cpp	2009-11-28 21:20:16 UTC (rev 12279)
+++ trunk/qgis/src/providers/ogr/qgsogrprovider.cpp	2009-11-28 23:20:50 UTC (rev 12280)
@@ -1461,6 +1461,25 @@
     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 @@
 
   OGR_DS_Destroy( dataSource );
 
-  QString driverName = OGR_Dr_GetName( driver );
-
   if ( driverName == "ESRI Shapefile" )
   {
     QString layerName = uri.left( uri.indexOf( ".shp", Qt::CaseInsensitive ) );



More information about the QGIS-commit mailing list