[Shapelib] .dbf files

Mateusz Loskot mateusz at loskot.net
Thu Jun 14 09:49:52 PDT 2007


Brian Peschel wrote:
> Kemp Kernstine wrote:
>>> How does one write records to a .dbf file for shapefiles. I am able
>>> to create the .dbf file and write a field to the file using
>>> DBFcreate() and DBFaddField() from the Shapelib, however there is no
>>> write record function. Is this a function build into C? Do I need to
>>> have a field for every record?
>>>     
>>
>> Just use one of DBFWrite* function with shape index pointing to
>> new/next record position, and it will be created automatically
>> (if it does not exists):
>>
>>
>> // Calculate index of next (new) record
>> iRecord = DBFGetRecordCount( hDBF );
>>
>> // Write value to 1st field and (implicitly) create new record
>> DBFWriteStringAttribute(hDBF, iRecord, 0, "My data" );
>>
>> Cheers
>>   
> I believe you need to call DBFClose(DBFHandle psDBF) for the data to
> actually be written to the file.

Yes, exactly.
I gave only essential snippet.

BTW, here is the DBFClose semantic explained:

http://shapelib.maptools.org/dbf_api.html

Cheers
-- 
Mateusz Loskot
http://mateusz.loskot.net



More information about the Shapelib mailing list