Skip to content

Commit 4265f9f

Browse files
committedJul 16, 2013
vector file writer: add support for DBF files (fixes #7507)
1 parent 810c11b commit 4265f9f

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed
 

‎src/core/qgsvectorfilewriter.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ QgsVectorFileWriter::QgsVectorFileWriter(
8989
dsOptions.append( "SPATIALITE=YES" );
9090
}
9191
}
92+
else if ( driverName == "DBF file" )
93+
{
94+
ogrDriverName = "ESRI Shapefile";
95+
if ( !layOptions.contains( "SHPT=NULL" ) )
96+
{
97+
layOptions.append( "SHPT=NULL" );
98+
}
99+
srs = 0;
100+
}
92101
else
93102
{
94103
ogrDriverName = driverName;
@@ -109,7 +118,7 @@ QgsVectorFileWriter::QgsVectorFileWriter(
109118
return;
110119
}
111120

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

119128
CPLSetConfigOption( "SHAPE_ENCODING", "" );
120129

121-
if ( !vectorFileName.endsWith( ".shp", Qt::CaseInsensitive ) &&
122-
!vectorFileName.endsWith( ".dbf", Qt::CaseInsensitive ) )
130+
if ( driverName == "ESRI Shapefile" && !vectorFileName.endsWith( ".shp", Qt::CaseInsensitive ) )
123131
{
124132
vectorFileName += ".shp";
125133
}
134+
else if ( driverName == "DBF file" && !vectorFileName.endsWith( ".dbf", Qt::CaseInsensitive ) )
135+
{
136+
vectorFileName += ".dbf";
137+
}
126138

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

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

733-
if ( layer == NULL )
745+
if ( !layer )
734746
{
735747
return ErrInvalidLayer;
736748
}
@@ -1023,6 +1035,10 @@ QMap<QString, QString> QgsVectorFileWriter::ogrDriverList()
10231035
CPLFree( options[0] );
10241036
delete [] options;
10251037
}
1038+
else if ( drvName == "ESRI Shapefile" )
1039+
{
1040+
writableDrivers << "DBF file";
1041+
}
10261042
writableDrivers << drvName;
10271043
}
10281044
}
@@ -1117,6 +1133,13 @@ bool QgsVectorFileWriter::driverMetadata( QString driverName, QString &longName,
11171133
glob = "*.shp";
11181134
ext = "shp";
11191135
}
1136+
else if ( driverName.startsWith( "DBF file" ) )
1137+
{
1138+
longName = "DBF File";
1139+
trLongName = QObject::tr( "DBF file" );
1140+
glob = "*.dbf";
1141+
ext = "dbf";
1142+
}
11201143
else if ( driverName.startsWith( "FMEObjects Gateway" ) )
11211144
{
11221145
longName = "FMEObjects Gateway";

0 commit comments

Comments
 (0)
Please sign in to comment.