I have an ESRI shapefile .shp (with all associated files like .shx, .dbf and many more) which I want to edit - I need to remove the first record and save the file.
For this purpose I installed pyshp and tried to parse and edit the shapefile. This is what I have tried:
import shapefile
e = shapefile.Editor('location/of/my/shp')
e.shapes()
# example output
>>> [<shapefile._Shape instance at 0x7fc5e18d93f8>,
<shapefile._Shape instance at 0x7fc5e18d9440>,
<shapefile._Shape instance at 0x7fc5e18d9488>,
<shapefile._Shape instance at 0x7fc5e18d94d0>,
<shapefile._Shape instance at 0x7fc5e18d9518>]
From here I want to delete the first entry <shapefile._Shape instance at 0x7fc5e18d93f8> and then save the file:
e.delete(0) # I tried e.delete(shape=0) too
e.save()
However the record is still available in the newly saved file.
Unfortunately the documentation doesn't go in depth about these things.
How can I accomplish my goal? How to check that the deletion has been successful before saving the file?
I'm not familiarized with
pyshpbut this can be easily solved usingogr, which allows to work with vector data and makes part of thegdallibrary.