Skip to content

Commit

Permalink
fix #2154 again:
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
jef committed Nov 29, 2009
1 parent 62c1a69 commit b2970fb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
14 changes: 13 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -138,6 +138,8 @@
#include "qgsvectorlayer.h"
#include "ogr/qgsopenvectorlayerdialog.h"
#include "qgsattributetabledialog.h"
#include "qgsvectorfilewriter.h"

//
// Gdal/Ogr includes
//
Expand Down Expand Up @@ -3272,7 +3274,17 @@ void QgisApp::newVectorLayer()
// 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() );

Expand Down
12 changes: 9 additions & 3 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -1445,14 +1445,15 @@ QGISEXTERN bool isProvider()
@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() );
Expand All @@ -1465,6 +1466,11 @@ QGISEXTERN bool createEmptyDataSource( const QString& uri,

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;
Expand Down

0 comments on commit b2970fb

Please sign in to comment.