I'm trying to create a layer for each county (based on a layer of all counties) and join only those census tracts located in that county. However, the result I'm getting is a layer named for each county but has all counties and census tracks.
coFC = r"C:\TenCounties"
coField = "County_Name"
censusFC = r"C:CT.shp"
# Get a unique list of the counties
values = [row[0] for row in arcpy.da.SearchCursor(coFC, (coField))]
list_of_counties = set(values)
# Create a feature layer for the Census Tracts
arcpy.MakeFeatureLayer_management(censusFC, "lyr_Census")
for county in list_of_counties:
print county
# Create a feature layer that contains just the current county
newout_name = arcpy.ValidateTableName(county)
arcpy.MakeFeatureLayer_management(coFC, newout_name, "\"County_Name\" = '{0}'".format(county))
# Select the census tracts that are located in the current county
arcpy.SelectLayerByLocation_management("lyr_Census", "INTERSECT", newout_name)
#Create a layer for each County
rcpy.CopyFeatures_management(coFC, "lyr_" + newout_name)
coFCwhen it should be"lyr_Census". – PolyGeo Nov 05 '15 at 01:48CopyFeatures, you are passing the original shapefile,coFC. You probably intend to be using the result from select. Edit: argh! beaten by two seconds. – Paul Nov 05 '15 at 01:48