Last active
October 16, 2015 02:55
-
-
Save DenisCarriere/88beaf719eaf3a43bcb3 to your computer and use it in GitHub Desktop.
Read attributes as Dictionary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# coding: utf8 | |
import shapefile | |
# pip install pyshp | |
def process(infile): | |
shp = shapefile.Reader(infile) | |
# Get rid of extra garbage in field list | |
# Remove the deletion flag from field list | |
fields = list((i[0]) for i in shp.fields[1:]) | |
# Loop inside each feature within the Shapefile | |
for feature in shp.iterShapeRecords(): | |
json = dict((fields[k], v) for k, v in enumerate(feature.record)) | |
print(json) | |
if __name__ == '__main__': | |
process('/home/ubuntu/data/Example.shp') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment