Skip to content

Instantly share code, notes, and snippets.

@rabbleNaut
Last active August 29, 2015 13:57
Show Gist options
  • Save rabbleNaut/9663241 to your computer and use it in GitHub Desktop.
Save rabbleNaut/9663241 to your computer and use it in GitHub Desktop.
Uses Arcpy to iterate through all feature classes in a feature dataset to create and populate new fields.
'''
batchFieldUpdate.py
For each feature class in EMST_Districts on Comanche.sde, do the following:
1 - Adds new field "Feature_Type"
2 - Calculates field
if type = null add "vegetation"
'''
import arcpy
from arcpy import *
# Hardcoded path to sde. Consider creating model with input parameters for reusibility.
env.workspace = r"C:\Users\RABBEY-C\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\Comanche.sde\ENV_GIS.ENV_GIS.EMST_Districts"
#For testing locally
#"C:\Users\RABBEY-C\RA_GIS\Projects\RA_EMST\Updated_Phase_Features.gdb\District_Unions"
fcList = ListFeatureClasses()
for fc in fcList:
print "Updating feature class: %s" % fc
fieldname = "Feature_Type"
expression = "getType(!DOT_Type!)"
codeblock = """def getType(type):
if type == "ROW":
return "ROW"
elif type == "Median":
return "MEDIAN"
elif type == "Roadway":
return "ROADWAY"
else:
return 'VEGETATION'"""
AddField_management(fc, fieldname, "TEXT")
CalculateField_management(fc, fieldname, expression, "PYTHON", codeblock)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment