Skip to content

Instantly share code, notes, and snippets.

@jasonbot
Forked from ghisprince/export_fc_to_csv.py
Last active August 29, 2015 14:01
Show Gist options
  • Save jasonbot/bb4c88bf67b51bf66f1c to your computer and use it in GitHub Desktop.
Save jasonbot/bb4c88bf67b51bf66f1c to your computer and use it in GitHub Desktop.
def export_fc_to_csv(fc, out_csv):
"""
Export each vertex in a line or poly fc to a csv with OID
user requested at http://arcpy.wordpress.com/about/#comment-348
example
import geom_snippets
geom_snippets.export_fc_to_csv(r"c:\proj\fc1.shp", r"c:\proj\fc1.csv")
output csv looks like this
1,56019.99998067904,69118.00001450378
1,56159.99998080942,69026.0000144181
1,56359.999980995686,68913.00001431286
2,34985.00002508866,68936.00001433428
2,35178.000025268404,68805.00001421227
"""
import csv
with open(out_csv, 'w') as csvfile:
csvwriter = csv.writer(csvfile, delimiter=',', lineterminator='\n')
with arcpy.da.SearchCursor(fc,
field_names=("OID@","SHAPE@JSON")) as cursor:
for row in cursor:
geom = json.loads(row[1])
for path in geom['paths']:
for pt in path:
csvwriter.writerow([row[0]] + pt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment