Saturday, 11 February 2017

python - Updating Attributes using Pyshp



Is it possible to update an attribute field in a shapefile using pyshp ?


I went through their documentation and all they show is how to create new attribute rather than editing or updating an already existing one.


If updating is not possible, is there any other recommended Python library for doing the same ?



Answer



You can use dbfpy to directly access and edit the attributes in the shape file's dbf file.


from dbfpy import dbf

db = dbf.Dbf("your_file.dbf")

#Editing a value, assuming you want to edit the first field of the first record

rec = db[0]
rec["FIRST_FIELD"] = "New value"
rec.store()
del rec
db.close()

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...