Mike,<br><br>A new field cannot be added to a feature definition while there are any features based on that feature definition.<br>See the docs for OGRFeatureDefn::AddFieldDefn()<br><a href="http://www.gdal.org/ogr/classOGRFeatureDefn.html#40e681d8464b42f1a1fac655f16ac3dd">http://www.gdal.org/ogr/classOGRFeatureDefn.html#40e681d8464b42f1a1fac655f16ac3dd</a><br>
<br><div class="gmail_quote">On Fri, Mar 18, 2011 at 11:01 AM, Mike Toews <span dir="ltr">&lt;<a href="mailto:mwtoews@gmail.com">mwtoews@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
In a Python script, I am updating an exiting shapefile with data by<br>
adding a column. However, my changes don&#39;t seem to be saved. Here is<br>
what I have:<br>
<br>
from osgeo import ogr<br>
obs_file = &#39;myfile.shp&#39;<br>
<br>
source = ogr.Open(obs_file, 1)<br>
layer = source.GetLayer()<br>
layer_defn = layer.GetLayerDefn()<br>
<br>
new_field = ogr.FieldDefn(&#39;MYFLD&#39;, ogr.OFTInteger)<br>
layer_defn.AddFieldDefn(new_field)<br>
<br>
source = None<br>
<br>
However, when I check the resulting file, I do not see the new field.<br>
<br>
I have also tried inserting the following (before &quot;source=None&quot;)<br>
<br>
feature = layer.GetNextFeature()<br>
feature.GetField(&#39;EXIST&#39;) # an existing float field with data<br>
feature.SetField(&#39;EXIST&#39;, 111.1) # works<br>
feature.SetField(&#39;MYFLD&#39;, 123) # does nothing<br>
layer.SetFeature(feature)<br>
<br>
Which successfully updates the data in the existing field, but not the<br>
added field.<br>
<br>
Where did I go wrong? Thanks in advance.<br>
<br>
-Mike<br>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Best regards,<br>Chaitanya kumar CH.<br>/tʃaɪθənjə/ /kʊmɑr/ <br>+91-9494447584<br>17.2416N 80.1426E<br>