Skip to content

Instantly share code, notes, and snippets.

@cindygis
Created April 29, 2015 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cindygis/089ee93ce65264ed671e to your computer and use it in GitHub Desktop.
Save cindygis/089ee93ce65264ed671e to your computer and use it in GitHub Desktop.
Converts geometry in a feature class to JSON and writes it to a CSV file
#
# @date 29/04/2015
# @author Cindy Williams
#
# Converts geometry in a feature class to JSON,
# and writes it to a CSV file.
#
# For use in the Python window in ArcCatalog.
#
import arcpy
arcpy.env.workspace = r"C:\Some\Arb\Folder"
lyr = arcpy.management.MakeFeatureLayer("work.gdb\ftr_line")
outcsv = r"line_json.csv"
# Get geometry of first feature as JSON
lyr_json = arcpy.da.SearchCursor(lyr, "SHAPE@JSON").next()[0]
# Write JSON to CSV
with open(outcsv, 'wb') as csvw:
csvw.write(lyr_json)
@cindygis
Copy link
Author

I'm not sure why I chose to write it to a CSV file instead of a JSON file. Guess I'm so used to working with CSVs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment