Re: [gdal-dev] Adding field to Shapefile via Python

2011-03-20 Thread Even Rouault
Le dimanche 20 mars 2011 23:47:44, Mike Toews a écrit : > Ok, I found the issue. Rather than adding a new field def'n: > layer_defn.AddFieldDefn(new_field) > > it needs to instead be created on the layer: > layer.CreateField(new_field) > > The documentation is misleading, as I thought I couldn't

Re: [gdal-dev] Adding field to Shapefile via Python

2011-03-20 Thread Mike Toews
Ok, I found the issue. Rather than adding a new field def'n: layer_defn.AddFieldDefn(new_field) it needs to instead be created on the layer: layer.CreateField(new_field) The documentation is misleading, as I thought I couldn't add a field to an existing shapefile if there were features in it. I w

Re: [gdal-dev] Adding field to Shapefile via Python

2011-03-17 Thread Chaitanya kumar CH
Mike, A new field cannot be added to a feature definition while there are any features based on that feature definition. See the docs for OGRFeatureDefn::AddFieldDefn() http://www.gdal.org/ogr/classOGRFeatureDefn.html#40e681d8464b42f1a1fac655f16ac3dd On Fri, Mar 18, 2011 at 11:01 AM, Mike Toews

[gdal-dev] Adding field to Shapefile via Python

2011-03-17 Thread Mike Toews
In a Python script, I am updating an exiting shapefile with data by adding a column. However, my changes don't seem to be saved. Here is what I have: from osgeo import ogr obs_file = 'myfile.shp' source = ogr.Open(obs_file, 1) layer = source.GetLayer() layer_defn = layer.GetLayerDefn() new_field