Skip to content

Instantly share code, notes, and snippets.

@gka
Created January 15, 2014 23:23
Show Gist options
  • Select an option

  • Save gka/8446787 to your computer and use it in GitHub Desktop.

Select an option

Save gka/8446787 to your computer and use it in GitHub Desktop.
extract a shapefile's attribute table to TSV
import sys, shapefile
if len(sys.argv) < 2:
print "Usage: shp2tsv.py SHAPEFILE\n"
exit(-1)
sf = shapefile.Reader(sys.argv[1])
recs = sf.records()
fields = []
for f in sf.fields[1:]:
fields.append(f[0])
print '\t'.join(fields)
for rec in recs:
print '\t'.join(map(str,rec))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment