can't DBFAddField after DBFCloneEmpty

View: New views
2 Messages — Rating Filter:   Alert me  

can't DBFAddField after DBFCloneEmpty

by Jeff Hamann :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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"?

Any advice would be greatly appreciated.

Thanks,
Jeff.





_______________________________________________
Shapelib mailing list
Shapelib@...
http://lists.maptools.org/mailman/listinfo/shapelib

Re: can't DBFAddField after DBFCloneEmpty

by Frank Warmerdam-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org

_______________________________________________
Shapelib mailing list
Shapelib@...
http://lists.maptools.org/mailman/listinfo/shapelib