[QGIS Commit] r12290 - in trunk/qgis/src: app providers/ogr

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun Nov 29 11:33:12 EST 2009


Author: jef
Date: 2009-11-29 11:33:11 -0500 (Sun, 29 Nov 2009)
New Revision: 12290

Modified:
   trunk/qgis/src/app/qgisapp.cpp
   trunk/qgis/src/providers/ogr/qgsogrprovider.cpp
Log:
fix  #2154 again:
- ogr provider doesn't create shapefiles without .shp extension anymore (OGR
  used to create a subdirectory in that case)
- automatically add .shp extension when using the new vector layer dialog



Modified: trunk/qgis/src/app/qgisapp.cpp
===================================================================
--- trunk/qgis/src/app/qgisapp.cpp	2009-11-29 16:23:55 UTC (rev 12289)
+++ trunk/qgis/src/app/qgisapp.cpp	2009-11-29 16:33:11 UTC (rev 12290)
@@ -138,6 +138,8 @@
 #include "qgsvectorlayer.h"
 #include "ogr/qgsopenvectorlayerdialog.h"
 #include "qgsattributetabledialog.h"
+#include "qgsvectorfilewriter.h"
+
 //
 // Gdal/Ogr includes
 //
@@ -3272,8 +3274,18 @@
   // file, which can cause problems (e.g., if the file contains
   // linestrings, but we're wanting to create points, we'll end up
   // with a linestring file).
-  QFile::remove( fileName );
+  if ( fileformat == "ESRI Shapefile" )
+  {
+    if ( !fileName.endsWith( ".shp", Qt::CaseInsensitive ) )
+      fileName += ".shp";
 
+    QgsVectorFileWriter::deleteShapeFile( fileName );
+  }
+  else
+  {
+    QFile::remove( fileName );
+  }
+
   settings.setValue( "/UI/lastVectorFileFilter", openFileDialog->selectedFilter() );
 
   settings.setValue( "/UI/lastVectorFileFilterDir", openFileDialog->directory().absolutePath() );

Modified: trunk/qgis/src/providers/ogr/qgsogrprovider.cpp
===================================================================
--- trunk/qgis/src/providers/ogr/qgsogrprovider.cpp	2009-11-29 16:23:55 UTC (rev 12289)
+++ trunk/qgis/src/providers/ogr/qgsogrprovider.cpp	2009-11-29 16:33:11 UTC (rev 12290)
@@ -1445,14 +1445,15 @@
 @param vectortype point/line/polygon or multitypes
 @param attributes a list of name/type pairs for the initial attributes
 @return true in case of success*/
-QGISEXTERN bool createEmptyDataSource( const QString& uri,
-                                       const QString& format,
-                                       const QString& encoding,
+QGISEXTERN bool createEmptyDataSource( const QString &uri,
+                                       const QString &format,
+                                       const QString &encoding,
                                        QGis::WkbType vectortype,
                                        const std::list<std::pair<QString, QString> > &attributes,
                                        const QgsCoordinateReferenceSystem *srs = NULL )
 {
   QgsDebugMsg( QString( "Creating empty vector layer with format: %1" ).arg( format ) );
+
   OGRSFDriverH driver;
   QgsApplication::registerOgrDrivers();
   driver = OGRGetDriverByName( format.toAscii() );
@@ -1465,6 +1466,11 @@
 
   if ( driverName == "ESRI Shapefile" )
   {
+    if ( !uri.endsWith( ".shp", Qt::CaseInsensitive ) )
+    {
+      return false;
+    }
+
     // check for duplicate fieldnames
     QSet<QString> fieldNames;
     std::list<std::pair<QString, QString> >::const_iterator fldIt;



More information about the QGIS-commit mailing list