Skip to content
Permalink
Browse files

vector file writer: add support for DBF files (fixes #7507)

  • Loading branch information
jef-n committed Jul 16, 2013
1 parent 810c11b commit 4265f9fe69bb02476f17146d359acff344c582d0
Showing with 28 additions and 5 deletions.
  1. +28 −5 src/core/qgsvectorfilewriter.cpp
@@ -89,6 +89,15 @@ QgsVectorFileWriter::QgsVectorFileWriter(
dsOptions.append( "SPATIALITE=YES" );
}
}
else if ( driverName == "DBF file" )
{
ogrDriverName = "ESRI Shapefile";
if ( !layOptions.contains( "SHPT=NULL" ) )
{
layOptions.append( "SHPT=NULL" );
}
srs = 0;
}
else
{
ogrDriverName = driverName;
@@ -109,7 +118,7 @@ QgsVectorFileWriter::QgsVectorFileWriter(
return;
}

if ( driverName == "ESRI Shapefile" )
if ( ogrDriverName == "ESRI Shapefile" )
{
if ( layOptions.join( "" ).toUpper().indexOf( "ENCODING=" ) == -1 )
{
@@ -118,11 +127,14 @@ QgsVectorFileWriter::QgsVectorFileWriter(

CPLSetConfigOption( "SHAPE_ENCODING", "" );

if ( !vectorFileName.endsWith( ".shp", Qt::CaseInsensitive ) &&
!vectorFileName.endsWith( ".dbf", Qt::CaseInsensitive ) )
if ( driverName == "ESRI Shapefile" && !vectorFileName.endsWith( ".shp", Qt::CaseInsensitive ) )
{
vectorFileName += ".shp";
}
else if ( driverName == "DBF file" && !vectorFileName.endsWith( ".dbf", Qt::CaseInsensitive ) )
{
vectorFileName += ".dbf";
}

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM < 1700
// check for unique fieldnames
@@ -270,7 +282,7 @@ QgsVectorFileWriter::QgsVectorFileWriter(

if ( srs )
{
if ( driverName == "ESRI Shapefile" )
if ( ogrDriverName == "ESRI Shapefile" )
{
QString layerName = vectorFileName.left( vectorFileName.indexOf( ".shp", Qt::CaseInsensitive ) );
QFile prjFile( layerName + ".qpj" );
@@ -730,7 +742,7 @@ QgsVectorFileWriter::writeAsVectorFormat( QgsVectorLayer* layer,
QgsCoordinateTransform* ct = 0;
int shallTransform = false;

if ( layer == NULL )
if ( !layer )
{
return ErrInvalidLayer;
}
@@ -1023,6 +1035,10 @@ QMap<QString, QString> QgsVectorFileWriter::ogrDriverList()
CPLFree( options[0] );
delete [] options;
}
else if ( drvName == "ESRI Shapefile" )
{
writableDrivers << "DBF file";
}
writableDrivers << drvName;
}
}
@@ -1117,6 +1133,13 @@ bool QgsVectorFileWriter::driverMetadata( QString driverName, QString &longName,
glob = "*.shp";
ext = "shp";
}
else if ( driverName.startsWith( "DBF file" ) )
{
longName = "DBF File";
trLongName = QObject::tr( "DBF file" );
glob = "*.dbf";
ext = "dbf";
}
else if ( driverName.startsWith( "FMEObjects Gateway" ) )
{
longName = "FMEObjects Gateway";

0 comments on commit 4265f9f

Please sign in to comment.
You can’t perform that action at this time.