Adding Attribute Field to Existing Shapefile via Python Without ArcGIS – Step-by-Step

dbfogrpythonshapefile

I have a Python script that adds an attribute field to a Shapefile if doesn't exist. This is easy to do with ArcGIS (graphically or via Python), but I'm looking for something that doesn't depend on ArcGIS.

I tried this unsuccessfully with OGR, since my Shapefile contains features.

I've looked at pyshp, but similarly there is no way to modify the schema after it has been created. I haven't had a try with shapefile (for Python), but I don't see this feature advertised. I also can't see how this can be done by tinkering with the DBF file via dbfpy.

Does anyone have any ideas?

Best Answer

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.