AnsweredAssumed Answered

Create new Feature Classes from attribute selection loop

Question asked by mattlove on Jun 22, 2012
Latest reply on Jun 25, 2012 by nahmed-esristaff
I am trying to loop through year values in an attribute field of a point feature class and create new point feature classes of all features for each year. For example an FC for 2004, an FC for 2005, and FC for 2006, etc.. The attribute field "yr" is the numeric integer field containing the year values. I want to select all points with "yr" = 2004 and create a new feature class 2004_ELB and so on for the remaining years. My code is below. My SelectLayerByAttribute_management query seems to be incorrect. Beyond that I'm not clear if my loop logic is correct either. Any help is greatly appreciated.

# import system modules
import arcpy

# set workspace environment
env = arcpy.env.workspace = "C:/Files/GIS/Projects/Hypoxia/Shrimp_Hypoxia/AnalysisData.gdb"

#Set OverWrite if files already exist
arcpy.env.overwriteOutput = True

# Make a layer from the feature class
FC = arcpy.MakeFeatureLayer_management("Full_Dataset_Albers", "FC")

#Create a list of years to iterate through to enable selection of each year
yrlist = [2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011]
print yrlist

#Initiate Search Cursor to use in loop of attribute values
rows = arcpy.SearchCursor(FC)

for row in rows:
    fieldName = "yr"
    value = row.getValue(fieldName)
    for year in yrlist:
        arcpy.SelectLayerByAttribute_management (FC, "NEW_SELECTION", "yr" = yrlist)
        arcpy.MakeFeatureLayer_management(YearFC, str(year) + "_ELB")

Attachments

Outcomes