Skip to content

Instantly share code, notes, and snippets.

@mfurlend
Created January 28, 2014 16:09
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 mfurlend/8670637 to your computer and use it in GitHub Desktop.
Save mfurlend/8670637 to your computer and use it in GitHub Desktop.
arcGIS shape filename -> array of field names as PHP array
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