[Shapelib] can't DBFAddField after DBFCloneEmpty
Frank Warmerdam
warmerdam at pobox.com
Mon Mar 17 16:31:38 EDT 2008
Jeff D. Hamann wrote:
> shapelib'ers:
>
> I have been trying to use the DBFAddField() after calling
> DBFCloneEmpty() with little success. I have been able to generate empty
> files with new fields, but what I need to accomplish to append and
> populate fields to an existing shapefile.
>
> hDBF_Soln = DBFCreate( "results/shapes/test.dbf" );
> bid_idx = DBFAddField( hDBF_Soln, "bid", FTInteger, 3, 0 );
> period_idx = DBFAddField( hDBF_Soln, "period", FTInteger, 3, 0 );
>
> works fine:
>
> hDBF_Soln = DBFCloneEmpty( hDBF, "results/shapes/test.dbf" );
> period_idx = DBFAddField( hDBF_Soln, "period", FTInteger, 3, 0 );
>
> does not. Shouldn't these be the same if the original shapefile only
> contains one field names "bid"?
Jeff,
Shapelib's dbf code does not support adding fields to .dbf files with
records already in the file. You will either need to create a new file,
with the old + new fields, and copy over the existing records or use
something else.
I will note it wouldn't be that hard to modify DBFAddField() to reshuffle
the file to add in fields in a file with records. So if you are skilled,
and so inclined feel free to take a crack at the code.
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 | President OSGeo, http://osgeo.org
More information about the Shapelib
mailing list