Skip to content

Commit b2970fb

Browse files
author
jef
committed
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 git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12290 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 62c1a69 commit b2970fb

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/app/qgisapp.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@
138138
#include "qgsvectorlayer.h"
139139
#include "ogr/qgsopenvectorlayerdialog.h"
140140
#include "qgsattributetabledialog.h"
141+
#include "qgsvectorfilewriter.h"
142+
141143
//
142144
// Gdal/Ogr includes
143145
//
@@ -3272,7 +3274,17 @@ void QgisApp::newVectorLayer()
32723274
// file, which can cause problems (e.g., if the file contains
32733275
// linestrings, but we're wanting to create points, we'll end up
32743276
// with a linestring file).
3275-
QFile::remove( fileName );
3277+
if ( fileformat == "ESRI Shapefile" )
3278+
{
3279+
if ( !fileName.endsWith( ".shp", Qt::CaseInsensitive ) )
3280+
fileName += ".shp";
3281+
3282+
QgsVectorFileWriter::deleteShapeFile( fileName );
3283+
}
3284+
else
3285+
{
3286+
QFile::remove( fileName );
3287+
}
32763288

32773289
settings.setValue( "/UI/lastVectorFileFilter", openFileDialog->selectedFilter() );
32783290

src/providers/ogr/qgsogrprovider.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,14 +1445,15 @@ QGISEXTERN bool isProvider()
14451445
@param vectortype point/line/polygon or multitypes
14461446
@param attributes a list of name/type pairs for the initial attributes
14471447
@return true in case of success*/
1448-
QGISEXTERN bool createEmptyDataSource( const QString& uri,
1449-
const QString& format,
1450-
const QString& encoding,
1448+
QGISEXTERN bool createEmptyDataSource( const QString &uri,
1449+
const QString &format,
1450+
const QString &encoding,
14511451
QGis::WkbType vectortype,
14521452
const std::list<std::pair<QString, QString> > &attributes,
14531453
const QgsCoordinateReferenceSystem *srs = NULL )
14541454
{
14551455
QgsDebugMsg( QString( "Creating empty vector layer with format: %1" ).arg( format ) );
1456+
14561457
OGRSFDriverH driver;
14571458
QgsApplication::registerOgrDrivers();
14581459
driver = OGRGetDriverByName( format.toAscii() );
@@ -1465,6 +1466,11 @@ QGISEXTERN bool createEmptyDataSource( const QString& uri,
14651466

14661467
if ( driverName == "ESRI Shapefile" )
14671468
{
1469+
if ( !uri.endsWith( ".shp", Qt::CaseInsensitive ) )
1470+
{
1471+
return false;
1472+
}
1473+
14681474
// check for duplicate fieldnames
14691475
QSet<QString> fieldNames;
14701476
std::list<std::pair<QString, QString> >::const_iterator fldIt;

0 commit comments

Comments
 (0)