1

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:
 attribute_values.add(row.getValue(strAtt)) 
 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."
 else:
 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.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Nov 3, 2015 at 18:41

1 Answer 1

2

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.

answered Nov 3, 2015 at 21:01
1
  • Excellent. Don't forget to click the check mark :) Commented Nov 3, 2015 at 22:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.