[Gdal-dev] easy ogr question...

Frank Warmerdam warmerdam at pobox.com
Tue Sep 19 12:26:49 EDT 2006


Will Cadell wrote:
> hi guys... am i just stupid or is there another way to add a field to a
> shapefile other than:
>    
>     ds = ogr.open("c:\shapefile.shp", True)
>    
>     new_field = ogr.FieldDefn()
>     new_field.SetName(new_field_name)
>     new_field.SetType(new_field_type)
>     new_field.SetWidth(new_field_width)
>    
>     layer = ds.GetLayer(0)
>     layer.CreateField(new_field)
>    
>     ds.destroy
> 
> because this doesn't work for me...

Will,

This does seem like the correct approach.  Are there any features in the
shapefile already?  I'm pretty sure that adding a field only works when
there are no features yet.  If you aren't getting an error message then
there is a clear bug here, and a bug report in bugzilla would be appreciated.

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 Gdal-dev mailing list