[FWTools] CreateField on existing shape file

Frank Warmerdam warmerdam at pobox.com
Thu Jun 21 13:11:05 EDT 2007


Bijoy Nair wrote:
> Hi,
> I am trying to add a new field on an existing shape file using ogr 
> python bindings but it seems to fail. The same steps work correctly when 
> a new shape file is created and a field is added to it.
> 
>  >>> from gdal import ogr
>  >>> ds = ogr.Open('d:/temp/delete-dublin-shapes',update = 1)
>  >>> lyr = ds.GetLayerByName('Zones')
>  >>> field = ogr.FieldDefn('Project',ogr.OFTString)
>  >>> field.SetWidth(100)
>  >>> lyr.CreateField(field)
> 6

Bijoy,

I believe the OGR Shapefile driver does not support creating fields on
a shapefile that already has records.  Is that the case for you?

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 FWTools mailing list