[QGIS Commit] r15156 - trunk/qgis/src/plugins/spit

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Feb 11 14:17:22 EST 2011


Author: jef
Date: 2011-02-11 11:17:22 -0800 (Fri, 11 Feb 2011)
New Revision: 15156

Removed:
   trunk/qgis/src/plugins/spit/qgsdbfbase.h
Modified:
   trunk/qgis/src/plugins/spit/qgsshapefile.cpp
Log:
fix #2551

Deleted: trunk/qgis/src/plugins/spit/qgsdbfbase.h
===================================================================
--- trunk/qgis/src/plugins/spit/qgsdbfbase.h	2011-02-11 16:23:17 UTC (rev 15155)
+++ trunk/qgis/src/plugins/spit/qgsdbfbase.h	2011-02-11 19:17:22 UTC (rev 15156)
@@ -1,90 +0,0 @@
-/***************************************************************************
-    qgsbdfbase.h - Dbase IV Header
-     --------------------------------------
-    Date                 : 25-Dec-2003
-    Copyright            : (C) 2003 by Gary E.Sherman
-    email                : sherman at mrcc.com
- ***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
-/* $Id$ */
-
-// Dbase header structure
-#ifndef _MSC_VER
-#include <stdint.h>
-#else
-typedef __int32 int32_t;
-typedef __int16 int16_t;
-#endif
-
-struct DbaseHeader
-{
-  unsigned char valid_dbf;
-  char year;
-  char month;
-  char day;
-  int32_t num_recs;
-  int16_t size_hdr;
-  int16_t size_rec;
-  char reserved[3];
-  char lan[13];
-  char reserved2[4];
-};
-// Field descriptor array - defines a field and its attributes (type,
-// length, etc.
-struct FieldDescriptorArray
-{
-  char field_name[11];
-  char field_type;
-  int32_t field_addr;  /* used only in memory */
-  unsigned char field_length;
-  unsigned char field_decimal;
-  char reserved[2];
-  char work_area;
-  char lan[2];
-  char set_fields;
-  char reserved2[8];
-};
-// Typedefs
-typedef struct FieldDescriptorArray Fda;
-typedef struct DbaseHeader DbH;
-
-// Field Array class
-class DbaseFieldArray
-{
-  public:
-    DbaseFieldArray( int numberOfFields );
-    void addField( char *name, char type, unsigned char length,
-                   unsigned char decimal );
-    int getNumFields();
-    Fda  *getField( int index );
-  private:
-    struct FieldDescriptorArray *fda;
-    unsigned int fieldCount;
-    int numFields;
-
-};
-
-// Dbase file class (incomplete implementation)
-class DbaseFile
-{
-  public:
-    DbaseFile( char *fileName, int numRecords, int recordSize, DbaseFieldArray &fda );
-    void writeHeader();
-    void writeFieldDescriptors();
-    void writeRecord( const char *data );
-    void closeFile();
-    struct DbaseHeader header;
-  private:
-    char * fileName;
-    int numRecords;
-    int recordSize;
-    DbaseFieldArray fieldArray;
-    long pos;
-    bool firstRecord;
-};

Modified: trunk/qgis/src/plugins/spit/qgsshapefile.cpp
===================================================================
--- trunk/qgis/src/plugins/spit/qgsshapefile.cpp	2011-02-11 16:23:17 UTC (rev 15155)
+++ trunk/qgis/src/plugins/spit/qgsshapefile.cpp	2011-02-11 19:17:22 UTC (rev 15156)
@@ -19,9 +19,6 @@
 #include <QApplication>
 #include <ogr_api.h>
 #include <cpl_conv.h>
-#include <string>
-#include <fstream>
-#include <cstdio>
 
 #include <QFile>
 #include <QProgressDialog>
@@ -31,7 +28,6 @@
 #include <QFileInfo>
 
 #include "qgsapplication.h"
-#include "qgsdbfbase.h"
 #include "cpl_error.h"
 #include "qgsshapefile.h"
 #include "qgis.h"
@@ -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
@@ -187,59 +176,36 @@
       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 )
+      int numFields = OGR_F_GetFieldCount( feat );
+      for ( int n = 0; n < numFields; n++ )
       {
-        /* 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 ) )
-      {
-        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 'F': column_types.push_back( "float" );
+          case OFTReal:
+            column_types.push_back( "float" );
             break;
-          case 'D': column_types.push_back( "date" );
+          case OFTString:
+            column_types.push_back( QString( "varchar(%1)" ).arg( OGR_Fld_GetWidth( fld ) ) );
             break;
-          case 'C':
-            str_type = QString( "varchar(%1)" ).arg( fda.field_length );
-            column_types.push_back( str_type );
+          case OFTDate:
+            column_types.push_back( "date" );
             break;
-          case 'L': column_types.push_back( "boolean" );
+          case OFTTime:
+            column_types.push_back( "time" );
             break;
+          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;



More information about the QGIS-commit mailing list