Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix #2551
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15156 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Feb 11, 2011
1 parent 95abbd6 commit b701015
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 142 deletions.
90 changes: 0 additions & 90 deletions src/plugins/spit/qgsdbfbase.h

This file was deleted.

70 changes: 18 additions & 52 deletions src/plugins/spit/qgsshapefile.cpp
Expand Up @@ -19,9 +19,6 @@
#include <QApplication>
#include <ogr_api.h>
#include <cpl_conv.h>
#include <string>
#include <fstream>
#include <cstdio>

#include <QFile>
#include <QProgressDialog>
Expand All @@ -31,7 +28,6 @@
#include <QFileInfo>

#include "qgsapplication.h"
#include "qgsdbfbase.h"
#include "cpl_error.h"
#include "qgsshapefile.h"
#include "qgis.h"
Expand All @@ -40,13 +36,6 @@
#include "qgspgutil.h"
#include "qgslogger.h"

// for htonl
#ifdef WIN32
#include <winsock.h>
#else
#include <netinet/in.h>
#endif

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8F(x) (x).toUtf8().constData()
#else
Expand Down Expand Up @@ -187,59 +176,36 @@ QString QgsShapeFile::getFeatureClass()
QgsDebugMsg( "After escaping, geom_type is : " + geom_type );
delete[] esc_str;

QString file( fileName );
file.replace( file.length() - 3, 3, "dbf" );
// open the dbf file
std::ifstream dbf( file.toUtf8(), std::ios::in | std::ios::binary );
// read header
DbaseHeader dbh;
dbf.read(( char * )&dbh, sizeof( dbh ) );
// Check byte order
if ( htonl( 1 ) == 1 )
{
/* DbaseHeader is stored in little-endian format.
* The num_recs, size_hdr and size_rec fields must be byte-swapped when read
* on a big-endian processor. Currently only size_hdr is used.
*/
unsigned char *byte = reinterpret_cast<unsigned char *>( &dbh.size_hdr );
unsigned char t = *byte; *byte = *( byte + 1 ); *( byte + 1 ) = t;
}

Fda fda;
QString str_type = "varchar(";
for ( int field_count = 0, bytes_read = sizeof( dbh ); bytes_read < dbh.size_hdr - 1; field_count++, bytes_read += sizeof( fda ) )
int numFields = OGR_F_GetFieldCount( feat );
for ( int n = 0; n < numFields; n++ )
{
dbf.read(( char * )&fda, sizeof( fda ) );
switch ( fda.field_type )
OGRFieldDefnH fld = OGR_F_GetFieldDefnRef( feat, n );
column_names.push_back( codec->toUnicode( OGR_Fld_GetNameRef( fld ) ) );
switch ( OGR_Fld_GetType( fld ) )
{
case 'N':
if (( int )fda.field_decimal > 0 )
column_types.push_back( "float" );
else
column_types.push_back( "int" );
case OFTInteger:
column_types.push_back( "int" );
break;
case OFTReal:
column_types.push_back( "float" );
break;
case 'F': column_types.push_back( "float" );
case OFTString:
column_types.push_back( QString( "varchar(%1)" ).arg( OGR_Fld_GetWidth( fld ) ) );
break;
case 'D': column_types.push_back( "date" );
case OFTDate:
column_types.push_back( "date" );
break;
case 'C':
str_type = QString( "varchar(%1)" ).arg( fda.field_length );
column_types.push_back( str_type );
case OFTTime:
column_types.push_back( "time" );
break;
case 'L': column_types.push_back( "boolean" );
case OFTDateTime:
column_types.push_back( "timestamp" );
break;
default:
column_types.push_back( "varchar(256)" );
break;
}
}
dbf.close();
int numFields = OGR_F_GetFieldCount( feat );
for ( int n = 0; n < numFields; n++ )
{
QString s = codec->toUnicode( OGR_Fld_GetNameRef( OGR_F_GetFieldDefnRef( feat, n ) ) );
column_names.push_back( s );
}

}
else valid = false;
Expand Down

0 comments on commit b701015

Please sign in to comment.