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 |
298 |
|
|
299 |
abyHeader[0] = 0x03; /* memo field? - just copying */ |
abyHeader[0] = 0x03; /* memo field? - just copying */ |
300 |
|
|
301 |
/* date updated on close, record count preset at zero */ |
/* write out a dummy date */ |
302 |
|
abyHeader[1] = 95; /* YY */ |
303 |
|
abyHeader[2] = 7; /* MM */ |
304 |
|
abyHeader[3] = 26; /* DD */ |
305 |
|
|
306 |
abyHeader[8] = psDBF->nHeaderLength % 256; |
/* record count preset at zero */ |
307 |
abyHeader[9] = psDBF->nHeaderLength / 256; |
|
308 |
|
abyHeader[8] = (unsigned char) (psDBF->nHeaderLength % 256); |
309 |
|
abyHeader[9] = (unsigned char) (psDBF->nHeaderLength / 256); |
310 |
|
|
311 |
abyHeader[10] = psDBF->nRecordLength % 256; |
abyHeader[10] = (unsigned char) (psDBF->nRecordLength % 256); |
312 |
abyHeader[11] = psDBF->nRecordLength / 256; |
abyHeader[11] = (unsigned char) (psDBF->nRecordLength / 256); |
313 |
|
|
314 |
/* -------------------------------------------------------------------- */ |
/* -------------------------------------------------------------------- */ |
315 |
/* Write the initial 32 byte file header, and all the field */ |
/* Write the initial 32 byte file header, and all the field */ |
355 |
} |
} |
356 |
|
|
357 |
/************************************************************************/ |
/************************************************************************/ |
358 |
|
/* DBFUpdateHeader() */ |
359 |
|
/************************************************************************/ |
360 |
|
|
361 |
|
void SHPAPI_CALL |
362 |
|
DBFUpdateHeader( DBFHandle psDBF ) |
363 |
|
|
364 |
|
{ |
365 |
|
unsigned char abyFileHeader[32]; |
366 |
|
|
367 |
|
if( psDBF->bNoHeader ) |
368 |
|
DBFWriteHeader( psDBF ); |
369 |
|
|
370 |
|
DBFFlushRecord( psDBF ); |
371 |
|
|
372 |
|
fseek( psDBF->fp, 0, 0 ); |
373 |
|
fread( abyFileHeader, 32, 1, psDBF->fp ); |
374 |
|
|
375 |
|
abyFileHeader[4] = (unsigned char) (psDBF->nRecords % 256); |
376 |
|
abyFileHeader[5] = (unsigned char) ((psDBF->nRecords/256) % 256); |
377 |
|
abyFileHeader[6] = (unsigned char) ((psDBF->nRecords/(256*256)) % 256); |
378 |
|
abyFileHeader[7] = (unsigned char) ((psDBF->nRecords/(256*256*256)) % 256); |
379 |
|
|
380 |
|
fseek( psDBF->fp, 0, 0 ); |
381 |
|
fwrite( abyFileHeader, 32, 1, psDBF->fp ); |
382 |
|
|
383 |
|
fflush( psDBF->fp ); |
384 |
|
} |
385 |
|
|
386 |
|
/************************************************************************/ |
387 |
/* DBFOpen() */ |
/* DBFOpen() */ |
388 |
/* */ |
/* */ |
389 |
/* Open a .dbf file. */ |
/* Open a .dbf file. */ |
542 |
/* write access. */ |
/* write access. */ |
543 |
/* -------------------------------------------------------------------- */ |
/* -------------------------------------------------------------------- */ |
544 |
if( psDBF->bUpdated ) |
if( psDBF->bUpdated ) |
545 |
{ |
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 ); |
|
|
} |
|
546 |
|
|
547 |
/* -------------------------------------------------------------------- */ |
/* -------------------------------------------------------------------- */ |
548 |
/* Close, and free resources. */ |
/* Close, and free resources. */ |
730 |
|
|
731 |
if( eType == FTString ) |
if( eType == FTString ) |
732 |
{ |
{ |
733 |
pszFInfo[16] = nWidth % 256; |
pszFInfo[16] = (unsigned char) (nWidth % 256); |
734 |
pszFInfo[17] = nWidth / 256; |
pszFInfo[17] = (unsigned char) (nWidth / 256); |
735 |
} |
} |
736 |
else |
else |
737 |
{ |
{ |
738 |
pszFInfo[16] = nWidth; |
pszFInfo[16] = (unsigned char) nWidth; |
739 |
pszFInfo[17] = nDecimals; |
pszFInfo[17] = (unsigned char) nDecimals; |
740 |
} |
} |
741 |
|
|
742 |
/* -------------------------------------------------------------------- */ |
/* -------------------------------------------------------------------- */ |
937 |
|
|
938 |
pszValue = DBFReadStringAttribute( psDBF, iRecord, iField ); |
pszValue = DBFReadStringAttribute( psDBF, iRecord, iField ); |
939 |
|
|
940 |
|
if( pszValue == NULL ) |
941 |
|
return TRUE; |
942 |
|
|
943 |
switch(psDBF->pachFieldType[iField]) |
switch(psDBF->pachFieldType[iField]) |
944 |
{ |
{ |
945 |
case 'N': |
case 'N': |
1211 |
/* as is to the field position in the record. */ |
/* as is to the field position in the record. */ |
1212 |
/************************************************************************/ |
/************************************************************************/ |
1213 |
|
|
1214 |
int DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, int iField, |
int SHPAPI_CALL |
1215 |
|
DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, int iField, |
1216 |
void * pValue ) |
void * pValue ) |
1217 |
|
|
1218 |
{ |
{ |
1535 |
|
|
1536 |
while (++i < len) |
while (++i < len) |
1537 |
if (isalpha(string[i]) && islower(string[i])) |
if (isalpha(string[i]) && islower(string[i])) |
1538 |
string[i] = toupper ((int)string[i]); |
string[i] = (char) toupper ((int)string[i]); |
1539 |
} |
} |
1540 |
|
|
1541 |
/************************************************************************/ |
/************************************************************************/ |
1568 |
} |
} |
1569 |
return(-1); |
return(-1); |
1570 |
} |
} |
|
|
|
|
/************************************************************************/ |
|
|
/* 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; |
|
|
} |
|