Skip to content

Commit 09300f6

Browse files
author
jef
committed
fix #2551
git-svn-id: http://svn.osgeo.org/qgis/trunk@15156 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent f1a655f commit 09300f6

File tree

2 files changed

+18
-142
lines changed

2 files changed

+18
-142
lines changed

src/plugins/spit/qgsdbfbase.h

-90
This file was deleted.

src/plugins/spit/qgsshapefile.cpp

+18-52
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
#include <QApplication>
2020
#include <ogr_api.h>
2121
#include <cpl_conv.h>
22-
#include <string>
23-
#include <fstream>
24-
#include <cstdio>
2522

2623
#include <QFile>
2724
#include <QProgressDialog>
@@ -31,7 +28,6 @@
3128
#include <QFileInfo>
3229

3330
#include "qgsapplication.h"
34-
#include "qgsdbfbase.h"
3531
#include "cpl_error.h"
3632
#include "qgsshapefile.h"
3733
#include "qgis.h"
@@ -40,13 +36,6 @@
4036
#include "qgspgutil.h"
4137
#include "qgslogger.h"
4238

43-
// for htonl
44-
#ifdef WIN32
45-
#include <winsock.h>
46-
#else
47-
#include <netinet/in.h>
48-
#endif
49-
5039
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
5140
#define TO8F(x) (x).toUtf8().constData()
5241
#else
@@ -187,59 +176,36 @@ QString QgsShapeFile::getFeatureClass()
187176
QgsDebugMsg( "After escaping, geom_type is : " + geom_type );
188177
delete[] esc_str;
189178

190-
QString file( fileName );
191-
file.replace( file.length() - 3, 3, "dbf" );
192-
// open the dbf file
193-
std::ifstream dbf( file.toUtf8(), std::ios::in | std::ios::binary );
194-
// read header
195-
DbaseHeader dbh;
196-
dbf.read(( char * )&dbh, sizeof( dbh ) );
197-
// Check byte order
198-
if ( htonl( 1 ) == 1 )
199-
{
200-
/* DbaseHeader is stored in little-endian format.
201-
* The num_recs, size_hdr and size_rec fields must be byte-swapped when read
202-
* on a big-endian processor. Currently only size_hdr is used.
203-
*/
204-
unsigned char *byte = reinterpret_cast<unsigned char *>( &dbh.size_hdr );
205-
unsigned char t = *byte; *byte = *( byte + 1 ); *( byte + 1 ) = t;
206-
}
207-
208-
Fda fda;
209-
QString str_type = "varchar(";
210-
for ( int field_count = 0, bytes_read = sizeof( dbh ); bytes_read < dbh.size_hdr - 1; field_count++, bytes_read += sizeof( fda ) )
179+
int numFields = OGR_F_GetFieldCount( feat );
180+
for ( int n = 0; n < numFields; n++ )
211181
{
212-
dbf.read(( char * )&fda, sizeof( fda ) );
213-
switch ( fda.field_type )
182+
OGRFieldDefnH fld = OGR_F_GetFieldDefnRef( feat, n );
183+
column_names.push_back( codec->toUnicode( OGR_Fld_GetNameRef( fld ) ) );
184+
switch ( OGR_Fld_GetType( fld ) )
214185
{
215-
case 'N':
216-
if (( int )fda.field_decimal > 0 )
217-
column_types.push_back( "float" );
218-
else
219-
column_types.push_back( "int" );
186+
case OFTInteger:
187+
column_types.push_back( "int" );
188+
break;
189+
case OFTReal:
190+
column_types.push_back( "float" );
220191
break;
221-
case 'F': column_types.push_back( "float" );
192+
case OFTString:
193+
column_types.push_back( QString( "varchar(%1)" ).arg( OGR_Fld_GetWidth( fld ) ) );
222194
break;
223-
case 'D': column_types.push_back( "date" );
195+
case OFTDate:
196+
column_types.push_back( "date" );
224197
break;
225-
case 'C':
226-
str_type = QString( "varchar(%1)" ).arg( fda.field_length );
227-
column_types.push_back( str_type );
198+
case OFTTime:
199+
column_types.push_back( "time" );
228200
break;
229-
case 'L': column_types.push_back( "boolean" );
201+
case OFTDateTime:
202+
column_types.push_back( "timestamp" );
230203
break;
231204
default:
232205
column_types.push_back( "varchar(256)" );
233206
break;
234207
}
235208
}
236-
dbf.close();
237-
int numFields = OGR_F_GetFieldCount( feat );
238-
for ( int n = 0; n < numFields; n++ )
239-
{
240-
QString s = codec->toUnicode( OGR_Fld_GetNameRef( OGR_F_GetFieldDefnRef( feat, n ) ) );
241-
column_names.push_back( s );
242-
}
243209

244210
}
245211
else valid = false;

0 commit comments

Comments
 (0)