Created
April 29, 2015 09:11
-
-
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
This file contains hidden or 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
# | |
# @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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.