|
19 | 19 | #include <QApplication> |
20 | 20 | #include <ogr_api.h> |
21 | 21 | #include <cpl_conv.h> |
22 | | -#include <string> |
23 | | -#include <fstream> |
24 | | -#include <cstdio> |
25 | 22 |
|
26 | 23 | #include <QFile> |
27 | 24 | #include <QProgressDialog> |
|
31 | 28 | #include <QFileInfo> |
32 | 29 |
|
33 | 30 | #include "qgsapplication.h" |
34 | | -#include "qgsdbfbase.h" |
35 | 31 | #include "cpl_error.h" |
36 | 32 | #include "qgsshapefile.h" |
37 | 33 | #include "qgis.h" |
|
40 | 36 | #include "qgspgutil.h" |
41 | 37 | #include "qgslogger.h" |
42 | 38 |
|
43 | | -// for htonl |
44 | | -#ifdef WIN32 |
45 | | -#include <winsock.h> |
46 | | -#else |
47 | | -#include <netinet/in.h> |
48 | | -#endif |
49 | | - |
50 | 39 | #if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800 |
51 | 40 | #define TO8F(x) (x).toUtf8().constData() |
52 | 41 | #else |
@@ -187,59 +176,36 @@ QString QgsShapeFile::getFeatureClass() |
187 | 176 | QgsDebugMsg( "After escaping, geom_type is : " + geom_type ); |
188 | 177 | delete[] esc_str; |
189 | 178 |
|
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++ ) |
211 | 181 | { |
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 ) ) |
214 | 185 | { |
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" ); |
220 | 191 | 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 ) ) ); |
222 | 194 | break; |
223 | | - case 'D': column_types.push_back( "date" ); |
| 195 | + case OFTDate: |
| 196 | + column_types.push_back( "date" ); |
224 | 197 | 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" ); |
228 | 200 | break; |
229 | | - case 'L': column_types.push_back( "boolean" ); |
| 201 | + case OFTDateTime: |
| 202 | + column_types.push_back( "timestamp" ); |
230 | 203 | break; |
231 | 204 | default: |
232 | 205 | column_types.push_back( "varchar(256)" ); |
233 | 206 | break; |
234 | 207 | } |
235 | 208 | } |
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 | | - } |
243 | 209 |
|
244 | 210 | } |
245 | 211 | else valid = false; |
|
0 commit comments