34 |
****************************************************************************** |
****************************************************************************** |
35 |
* |
* |
36 |
* $Log$ |
* $Log$ |
37 |
* Revision 1.2 2003/10/02 15:15:16 bh |
* Revision 1.3 2004/05/17 15:47:57 bh |
38 |
* Update to shapelib 1.2.10 |
* Update to newest shapelib and get rid of Thuban specific extensions, |
39 |
|
* i.e. use the new DBFUpdateHeader instead of our DBFCommit kludge |
40 |
|
* |
41 |
|
* * libraries/shapelib/shpopen.c: Update to version from current |
42 |
|
* shapelib CVS. |
43 |
|
* |
44 |
|
* * libraries/shapelib/shapefil.h: Update to version from current |
45 |
|
* shapelib CVS. |
46 |
|
* |
47 |
|
* * libraries/shapelib/dbfopen.c: Update to version from current |
48 |
|
* shapelib CVS. |
49 |
|
* (DBFCommit): Effectively removed since shapelib itself has |
50 |
|
* DBFUpdateHeader now which is better for what DBFCommit wanted to |
51 |
|
* achieve. |
52 |
|
* We're now using an unmodified version of dbfopen. |
53 |
|
* |
54 |
|
* * libraries/pyshapelib/dbflib_wrap.c, libraries/pyshapelib/dbflib.py: |
55 |
|
* Update from dbflib.i |
56 |
|
* |
57 |
|
* * libraries/pyshapelib/dbflib.i (DBFInfo_commit): New. Implementation of |
58 |
|
* the commit method. This new indirection is necessary because we use the |
59 |
|
* DBFUpdateHeader function now which is not available in shapelib <= |
60 |
|
* 1.2.10 |
61 |
|
* (DBFFile::commit): Use DBFInfo_commit as implementation |
62 |
|
* (pragma __class__): New. Kludge to remove the commit method when |
63 |
|
* the DBFUpdateHeader function isn't available |
64 |
|
* (_have_commit): New. Helper for the pragma kludge. |
65 |
|
* |
66 |
|
* * libraries/pyshapelib/setup.py (dbf_macros): New. Return the |
67 |
|
* preprocessor macros needed to compile the dbflib wrapper. Determine |
68 |
|
* whether DBFUpdateHeader is available and define the right value of |
69 |
|
* HAVE_UPDATE_HEADER |
70 |
|
* (extensions): Use dbf_macros for the dbflibc extension |
71 |
|
* |
72 |
|
* * setup.py (extensions): Add the HAVE_UPDATE_HEADER macro with |
73 |
|
* value '1' to the Lib.dbflibc extension. This simply reflects the |
74 |
|
* shapelib and pyshapelib updates |
75 |
|
* |
76 |
|
* Revision 1.53 2003/12/29 00:00:30 fwarmerdam |
77 |
|
* mark DBFWriteAttributeDirectly as SHPAPI_CALL |
78 |
|
* |
79 |
|
* Revision 1.52 2003/07/08 15:20:03 warmerda |
80 |
|
* avoid warnings about downcasting to unsigned char |
81 |
|
* |
82 |
|
* Revision 1.51 2003/07/08 13:50:15 warmerda |
83 |
|
* DBFIsAttributeNULL check for pszValue==NULL - bug 360 |
84 |
|
* |
85 |
|
* Revision 1.50 2003/04/21 18:58:25 warmerda |
86 |
|
* ensure current record is flushed at same time as header is updated |
87 |
|
* |
88 |
|
* Revision 1.49 2003/04/21 18:30:37 warmerda |
89 |
|
* added header write/update public methods |
90 |
* |
* |
91 |
* Revision 1.48 2003/03/10 14:51:27 warmerda |
* Revision 1.48 2003/03/10 14:51:27 warmerda |
92 |
* DBFWrite* calls now return FALSE if they have to truncate |
* DBFWrite* calls now return FALSE if they have to truncate |
255 |
static char * pszStringField = NULL; |
static char * pszStringField = NULL; |
256 |
|
|
257 |
/************************************************************************/ |
/************************************************************************/ |
258 |
|
/* DBFSet_atof_function() */ |
259 |
|
/* */ |
260 |
|
/* This makes it possible to initialise a different atof() function */ |
261 |
|
/* which might be necessary because the standard atof() might be */ |
262 |
|
/* sensitive to locale settings. */ |
263 |
|
/* */ |
264 |
|
/* If the calling application uses a locale with different decimal_point*/ |
265 |
|
/* it should better also give us a locale agnostic atof() function. */ |
266 |
|
/* */ |
267 |
|
/* As far as I can see from Python PEP331 and GNU libc documentation */ |
268 |
|
/* there is no standard for such a function yet. */ |
269 |
|
/* */ |
270 |
|
/* [email protected] 20060924 */ |
271 |
|
/************************************************************************/ |
272 |
|
|
273 |
|
static double (* atof_function)(const char *nptr) = &atof; |
274 |
|
|
275 |
|
void SHPAPI_CALL |
276 |
|
DBFSetatof_function( double (* new_atof_function)(const char *nptr)) |
277 |
|
{ |
278 |
|
atof_function = new_atof_function; |
279 |
|
} |
280 |
|
|
281 |
|
/************************************************************************/ |
282 |
/* SfRealloc() */ |
/* SfRealloc() */ |
283 |
/* */ |
/* */ |
284 |
/* A realloc cover function that will access a NULL pointer as */ |
/* A realloc cover function that will access a NULL pointer as */ |
322 |
|
|
323 |
abyHeader[0] = 0x03; /* memo field? - just copying */ |
abyHeader[0] = 0x03; /* memo field? - just copying */ |
324 |
|
|
325 |
/* date updated on close, record count preset at zero */ |
/* write out a dummy date */ |
326 |
|
abyHeader[1] = 95; /* YY */ |
327 |
|
abyHeader[2] = 7; /* MM */ |
328 |
|
abyHeader[3] = 26; /* DD */ |
329 |
|
|
330 |
|
/* record count preset at zero */ |
331 |
|
|
332 |
abyHeader[8] = psDBF->nHeaderLength % 256; |
abyHeader[8] = (unsigned char) (psDBF->nHeaderLength % 256); |
333 |
abyHeader[9] = psDBF->nHeaderLength / 256; |
abyHeader[9] = (unsigned char) (psDBF->nHeaderLength / 256); |
334 |
|
|
335 |
abyHeader[10] = psDBF->nRecordLength % 256; |
abyHeader[10] = (unsigned char) (psDBF->nRecordLength % 256); |
336 |
abyHeader[11] = psDBF->nRecordLength / 256; |
abyHeader[11] = (unsigned char) (psDBF->nRecordLength / 256); |
337 |
|
|
338 |
/* -------------------------------------------------------------------- */ |
/* -------------------------------------------------------------------- */ |
339 |
/* Write the initial 32 byte file header, and all the field */ |
/* Write the initial 32 byte file header, and all the field */ |
379 |
} |
} |
380 |
|
|
381 |
/************************************************************************/ |
/************************************************************************/ |
382 |
|
/* DBFUpdateHeader() */ |
383 |
|
/************************************************************************/ |
384 |
|
|
385 |
|
void SHPAPI_CALL |
386 |
|
DBFUpdateHeader( DBFHandle psDBF ) |
387 |
|
|
388 |
|
{ |
389 |
|
unsigned char abyFileHeader[32]; |
390 |
|
|
391 |
|
if( psDBF->bNoHeader ) |
392 |
|
DBFWriteHeader( psDBF ); |
393 |
|
|
394 |
|
DBFFlushRecord( psDBF ); |
395 |
|
|
396 |
|
fseek( psDBF->fp, 0, 0 ); |
397 |
|
fread( abyFileHeader, 32, 1, psDBF->fp ); |
398 |
|
|
399 |
|
abyFileHeader[4] = (unsigned char) (psDBF->nRecords % 256); |
400 |
|
abyFileHeader[5] = (unsigned char) ((psDBF->nRecords/256) % 256); |
401 |
|
abyFileHeader[6] = (unsigned char) ((psDBF->nRecords/(256*256)) % 256); |
402 |
|
abyFileHeader[7] = (unsigned char) ((psDBF->nRecords/(256*256*256)) % 256); |
403 |
|
|
404 |
|
fseek( psDBF->fp, 0, 0 ); |
405 |
|
fwrite( abyFileHeader, 32, 1, psDBF->fp ); |
406 |
|
|
407 |
|
fflush( psDBF->fp ); |
408 |
|
} |
409 |
|
|
410 |
|
/************************************************************************/ |
411 |
/* DBFOpen() */ |
/* DBFOpen() */ |
412 |
/* */ |
/* */ |
413 |
/* Open a .dbf file. */ |
/* Open a .dbf file. */ |
553 |
void SHPAPI_CALL |
void SHPAPI_CALL |
554 |
DBFClose(DBFHandle psDBF) |
DBFClose(DBFHandle psDBF) |
555 |
{ |
{ |
556 |
|
if( psSHP == NULL ) |
557 |
|
return; |
558 |
|
|
559 |
/* -------------------------------------------------------------------- */ |
/* -------------------------------------------------------------------- */ |
560 |
/* Write out header if not already written. */ |
/* Write out header if not already written. */ |
561 |
/* -------------------------------------------------------------------- */ |
/* -------------------------------------------------------------------- */ |
569 |
/* write access. */ |
/* write access. */ |
570 |
/* -------------------------------------------------------------------- */ |
/* -------------------------------------------------------------------- */ |
571 |
if( psDBF->bUpdated ) |
if( psDBF->bUpdated ) |
572 |
{ |
DBFUpdateHeader( psDBF ); |
|
unsigned char abyFileHeader[32]; |
|
|
|
|
|
fseek( psDBF->fp, 0, 0 ); |
|
|
fread( abyFileHeader, 32, 1, psDBF->fp ); |
|
|
|
|
|
abyFileHeader[1] = 95; /* YY */ |
|
|
abyFileHeader[2] = 7; /* MM */ |
|
|
abyFileHeader[3] = 26; /* DD */ |
|
|
|
|
|
abyFileHeader[4] = psDBF->nRecords % 256; |
|
|
abyFileHeader[5] = (psDBF->nRecords/256) % 256; |
|
|
abyFileHeader[6] = (psDBF->nRecords/(256*256)) % 256; |
|
|
abyFileHeader[7] = (psDBF->nRecords/(256*256*256)) % 256; |
|
|
|
|
|
fseek( psDBF->fp, 0, 0 ); |
|
|
fwrite( abyFileHeader, 32, 1, psDBF->fp ); |
|
|
} |
|
573 |
|
|
574 |
/* -------------------------------------------------------------------- */ |
/* -------------------------------------------------------------------- */ |
575 |
/* Close, and free resources. */ |
/* Close, and free resources. */ |
757 |
|
|
758 |
if( eType == FTString ) |
if( eType == FTString ) |
759 |
{ |
{ |
760 |
pszFInfo[16] = nWidth % 256; |
pszFInfo[16] = (unsigned char) (nWidth % 256); |
761 |
pszFInfo[17] = nWidth / 256; |
pszFInfo[17] = (unsigned char) (nWidth / 256); |
762 |
} |
} |
763 |
else |
else |
764 |
{ |
{ |
765 |
pszFInfo[16] = nWidth; |
pszFInfo[16] = (unsigned char) nWidth; |
766 |
pszFInfo[17] = nDecimals; |
pszFInfo[17] = (unsigned char) nDecimals; |
767 |
} |
} |
768 |
|
|
769 |
/* -------------------------------------------------------------------- */ |
/* -------------------------------------------------------------------- */ |
853 |
/* -------------------------------------------------------------------- */ |
/* -------------------------------------------------------------------- */ |
854 |
if( chReqType == 'N' ) |
if( chReqType == 'N' ) |
855 |
{ |
{ |
856 |
dDoubleField = atof(pszStringField); |
dDoubleField = (*atof_function)(pszStringField); |
857 |
|
|
858 |
pReturnField = &dDoubleField; |
pReturnField = &dDoubleField; |
859 |
} |
} |
964 |
|
|
965 |
pszValue = DBFReadStringAttribute( psDBF, iRecord, iField ); |
pszValue = DBFReadStringAttribute( psDBF, iRecord, iField ); |
966 |
|
|
967 |
|
if( pszValue == NULL ) |
968 |
|
return TRUE; |
969 |
|
|
970 |
switch(psDBF->pachFieldType[iField]) |
switch(psDBF->pachFieldType[iField]) |
971 |
{ |
{ |
972 |
case 'N': |
case 'N': |
1238 |
/* as is to the field position in the record. */ |
/* as is to the field position in the record. */ |
1239 |
/************************************************************************/ |
/************************************************************************/ |
1240 |
|
|
1241 |
int DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, int iField, |
int SHPAPI_CALL |
1242 |
|
DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, int iField, |
1243 |
void * pValue ) |
void * pValue ) |
1244 |
|
|
1245 |
{ |
{ |
1562 |
|
|
1563 |
while (++i < len) |
while (++i < len) |
1564 |
if (isalpha(string[i]) && islower(string[i])) |
if (isalpha(string[i]) && islower(string[i])) |
1565 |
string[i] = toupper ((int)string[i]); |
string[i] = (char) toupper ((int)string[i]); |
1566 |
} |
} |
1567 |
|
|
1568 |
/************************************************************************/ |
/************************************************************************/ |
1595 |
} |
} |
1596 |
return(-1); |
return(-1); |
1597 |
} |
} |
|
|
|
|
/************************************************************************/ |
|
|
/* DBFCommit() */ |
|
|
/* */ |
|
|
/* Write any changes made into the file. */ |
|
|
/* */ |
|
|
/************************************************************************/ |
|
|
int SHPAPI_CALL |
|
|
DBFCommit( DBFHandle psDBF ) |
|
|
|
|
|
{ |
|
|
DBFFlushRecord( psDBF ); |
|
|
if (fflush( psDBF->fp ) == EOF) |
|
|
return FALSE; |
|
|
|
|
|
return TRUE; |
|
|
} |
|