Created
December 7, 2015 16:31
-
-
Save mfurlend/58b6312f28868299330a to your computer and use it in GitHub Desktop.
arcGIS shape filename -> array of field names as PHP array
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
import arcpy | |
import json | |
from arcpy import env | |
env.workspace = "E:/master_regions_unpacked" | |
txtFile = open("E:/master_regions/regionArray","w") | |
txt = [] | |
files = arcpy.ListFiles("*.dbf") | |
for file in files: | |
txt.append("'"+str(file).split(".")[0]+"'=>array(") | |
rows = arcpy.SearchCursor(file) | |
txtinner = [] | |
for row in rows: | |
txtinner.append(json.dumps(row.NAME)) | |
txt.append((', ').join(txtinner)) | |
txt.append("),\n") | |
text= "var $masterRegions => array(\n " +('').join(txt)[:-2] + " \n);" | |
print text | |
txtFile.write(text) | |
txtFile.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment