Skip to content

Instantly share code, notes, and snippets.

@ghisprince
Last active December 7, 2015 15:01
Show Gist options
  • Save ghisprince/10208459 to your computer and use it in GitHub Desktop.
Save ghisprince/10208459 to your computer and use it in GitHub Desktop.
Export each vertex in a line or poly fc to a csv with OID
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
import json
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