Adding attribute field to existing Shapefile via Python without ArcGIS

you should have a look on these questions since it has been answered already : How to add custom Feature attributes to Shapefile using Python?

https://stackoverflow.com/questions/4215658/adding-custom-feature-attributes-to-esri-shapefile-with-python

If you want as result, only one shapefile, just delete your input files at the end of your script.


Thanks to a rather brain-dead format called DBF, adding fields to shapefiles with existing attribute data isn't possible without rewriting or adding padding to the DBF. I don't know of a ready-made solution, but what I would do is write a script to create a new shapefile based on an existing one and add the extra field(s) to the new shapefile. Then copy the geometry/attribute data from old to new shapefile. And as a final step, remove the old shapefile, and rename the new one. All of this is fairly easily accomplished using OGR python bindings.

Alternately, you can use dbfpy to do the above with just the DBF file. Order of steps remains the same:

  1. Create a new DBF with identical structure to original
  2. Create new attribute fields in the new DBF
  3. Copy data from original DBF to new DBF
  4. Remove old DBF, rename new DBF to old DBF

You don't need to make any changes to the shapefile (.shp) itself or any of the other files, as they do not reference attribute information contained in the DBF. You do however need to keep the order of records exactly the same in the old and the new DBF.


Here's a solution. Better late than never:

http://geospatialpython.com/2013/04/add-field-to-existing-shapefile.html?m=1