I am working with a Basic license of ArcMap 10.3, and I am trying to split a feature class into multiple feature classes in a geodatabase by unique values of an attribute. More specifically, I have a feature class of locations of 78 different species, and I want to create individual feature classes for each species. I have put together some code that I have found in various places (including here), and I can get it to create all the feature classes with all the fields, but each one is empty, and I can't figure out why. I am very new to arcpy and coding in general.

# Reads the feature class for different values in the attribute
cursor = arcpy.SearchCursor(inFC)
row = cursor.next()
attribute_values = set([])

strAtt = "ELCODE_BCD"
print strAtt

while row:
    row = cursor.next()

# Output a Shapefile for each different attribute
for each_attribute in attribute_values:
    # Check to see if FC exists
    strEmptyFC = "each_attribute"
    print "Checking to see if feature class exists..."
    if arcpy.Exists(strEmptyFC) :
        print strEmptyFC + " exists."
        print "Creating feature class..."
        outFC = strWS + "\\"  + each_attribute
        print outFC
        arcpy.Select_analysis (inFC, outFC, "'%s' = 'each_attribute'" %strAtt)

del strWS, inFC, cursor, row, attribute_values

I think it has to do with the where clause in the select statement.


It is indeed a problem with your where clause. With each iteration you are looking for the string "each_attribute" in your table, instead of the variable's value.

Try this for your select code:

arcpy.Select_analysis (inFC, outFC, '"{0}" = \'{1}\''.format (strAtt, each_attribute))

Your SQL uses single quotes instead of double quotes for the field name, while I've always used double quotes. Fiddle with that part as needed.

  • Excellent. Don't forget to click the check mark :) – Emil Brundage Nov 3 '15 at 22:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.