From 731c5b591ac0d3c2446e76a34c363ace7e47abd5 Mon Sep 17 00:00:00 2001 From: jef Date: Sat, 29 May 2010 11:39:19 +0000 Subject: [PATCH] fix #2761 git-svn-id: http://svn.osgeo.org/qgis/trunk@13589 c8812cc2-4d05-0410-92ff-de0c093fc19c --- src/core/qgsvectorfilewriter.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/core/qgsvectorfilewriter.cpp b/src/core/qgsvectorfilewriter.cpp index a526591d79a..22ea2e33781 100644 --- a/src/core/qgsvectorfilewriter.cpp +++ b/src/core/qgsvectorfilewriter.cpp @@ -41,15 +41,19 @@ #include -QgsVectorFileWriter::QgsVectorFileWriter( const QString& vectorFileName, - const QString& fileEncoding, - const QgsFieldMap& fields, - QGis::WkbType geometryType, - const QgsCoordinateReferenceSystem* srs, - const QString& driverName ) - : mDS( NULL ), mLayer( NULL ), mGeom( NULL ), mError( NoError ) +QgsVectorFileWriter::QgsVectorFileWriter( + const QString &theVectorFileName, + const QString& fileEncoding, + const QgsFieldMap& fields, + QGis::WkbType geometryType, + const QgsCoordinateReferenceSystem* srs, + const QString& driverName ) + : mDS( NULL ) + , mLayer( NULL ) + , mGeom( NULL ) + , mError( NoError ) { - // save the layer as a shapefile + QString vectorFileName = theVectorFileName; // find driver in OGR OGRSFDriverH poDriver; @@ -67,6 +71,11 @@ QgsVectorFileWriter::QgsVectorFileWriter( const QString& vectorFileName, if ( driverName == "ESRI Shapefile" ) { + if ( !vectorFileName.endsWith( ".shp", Qt::CaseInsensitive ) ) + { + vectorFileName += ".shp"; + } + // check for unique fieldnames QSet fieldNames; QgsFieldMap::const_iterator fldIt; @@ -129,6 +138,7 @@ QgsVectorFileWriter::QgsVectorFileWriter( const QString& vectorFileName, { if ( driverName == "ESRI Shapefile" ) { + QString layerName = vectorFileName.left( vectorFileName.indexOf( ".shp", Qt::CaseInsensitive ) ); QFile prjFile( layerName + ".qpj" ); if ( prjFile.open( QIODevice::WriteOnly ) ) {