AROACH220

List feature class for Loop and Add Field, Calculate Field

Discussion created by AROACH220 on Dec 13, 2011
Latest reply on Dec 13, 2011 by kimo
I am trying to automate a process where I have several Feature Classes and I want to perform a Spatial Join to one file.  I then want to create a field and then populate it in the original Feature Class with a field from the joined feature class. 

import arcpy
from arcpy import env
import os

# The workspace environment needs to be set before ListFeatureClasses
#    to identify which workspace the list will be based on
#   
env.workspace = "e:/Project"
out_workspace = "e:/Project/Results"


# Loop through a list of feature classes in the workspace
#
for fc in arcpy.ListFeatureClasses():
    
    output = os.path.join(out_workspace, fc)

 # Spatial Join the FC to the cooresponding pop nbrhd file

    target_features = fc
    join_features = "e:/Project/PopularNeighborhoods"
    out_feature_class = output

    arcpy.SpatialJoin_analysis(target_features, join_features, out_feature_class)

    target_explore = fc

    arcpy.AddField_management(target_explore, "popular_Hood", "Text", 50, "", "", "", "NULLABLE", "NON_REQUIRED")


I know the that calculate portion of the script isn't in there, but I wanted to see if I could get it to create new files with the added field and it isn't working. Any help would be greatly appreciated.

Outcomes