Skip to content

Commit

Permalink
vector file writer: add support for DBF files (fixes #7507)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jul 16, 2013
1 parent 810c11b commit 4265f9f
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions src/core/qgsvectorfilewriter.cpp
Expand Up @@ -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;
Expand All @@ -109,7 +118,7 @@ QgsVectorFileWriter::QgsVectorFileWriter(
return;
}

if ( driverName == "ESRI Shapefile" )
if ( ogrDriverName == "ESRI Shapefile" )
{
if ( layOptions.join( "" ).toUpper().indexOf( "ENCODING=" ) == -1 )
{
Expand All @@ -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
Expand Down Expand Up @@ -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" );
Expand Down Expand Up @@ -730,7 +742,7 @@ QgsVectorFileWriter::writeAsVectorFormat( QgsVectorLayer* layer,
QgsCoordinateTransform* ct = 0;
int shallTransform = false;

if ( layer == NULL )
if ( !layer )
{
return ErrInvalidLayer;
}
Expand Down Expand Up @@ -1023,6 +1035,10 @@ QMap<QString, QString> QgsVectorFileWriter::ogrDriverList()
CPLFree( options[0] );
delete [] options;
}
else if ( drvName == "ESRI Shapefile" )
{
writableDrivers << "DBF file";
}
writableDrivers << drvName;
}
}
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit 4265f9f

Please sign in to comment.