[Thuban-list] Re: Shapelib: dbfopen.c addition

Frank Warmerdam warmerdam at pobox.com
Thu Dec 4 15:09:47 CET 2003


Markus Neteler wrote:
> Frank,
> 
> while trying to get Thuban (from Intevation) running,
> I found that they have added a function to dbfopen.c in shapelib.
> Maybe interesting for you to add into CVS?
> Author should be Bernhard Herzog.
> 
> Function attached.
> 
> Best regards
> 
>  Markus
> 
> 
> 
> ------------------------------------------------------------------------
> 
> /************************************************************************/
> /*                          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;
> }

Markus,

I see there is already a DBFUpdateHeader() function which accomplishing
pretty much the same as DBFCommit(), but also ensures that the header is
in a consistent state (the record count appears there).  I think it would
be best if Thuban used that instead if possible.  I have cc:ed the Thuban
list in case they want to change their code.

DBFUpdateHeader() looks like:

/************************************************************************/
/*                          DBFUpdateHeader()                           */
/************************************************************************/

void SHPAPI_CALL
DBFUpdateHeader( DBFHandle psDBF )

{
     unsigned char		abyFileHeader[32];

     if( psDBF->bNoHeader )
         DBFWriteHeader( psDBF );

     DBFFlushRecord( psDBF );

     fseek( psDBF->fp, 0, 0 );
     fread( abyFileHeader, 32, 1, psDBF->fp );

     abyFileHeader[4] = (unsigned char) (psDBF->nRecords % 256);
     abyFileHeader[5] = (unsigned char) ((psDBF->nRecords/256) % 256);
     abyFileHeader[6] = (unsigned char) ((psDBF->nRecords/(256*256)) % 256);
     abyFileHeader[7] = (unsigned char) ((psDBF->nRecords/(256*256*256)) % 256);

     fseek( psDBF->fp, 0, 0 );
     fwrite( abyFileHeader, 32, 1, psDBF->fp );

     fflush( psDBF->fp );
}

Best regards,

-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent





More information about the Thuban-list mailing list

This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)