ahhh, I think I get it, basically {} are indexes it seems. Soooo, taking what you worked out, what if I wanted to take it a step further and instead create a new unique union feature for each YEAR, like above but ALSO on another string field entitled "AGENCY_GEAR". So output files would be:
gear1_2003_union
gear2_2003_union
gear1_2004_union
gear2_2004_union, etc
Would you nest for loops, separate selection clause, or combined selection clause ? Aimlessly stabbed below, where I used the same function to gather unique values of the AGENCY_GEAR.:
import arcpy
#Set the data environment
arcpy.env.overwriteOutput = True
arcpy.env.workspace = r'C:\Data\working\AK_Fishing_VMS\2021_Delivery\ArcPro_proj\ArcPro_proj.gdb'
trawlBuffs = r'C:\Data\working\AK_Fishing_VMS\2021_Delivery\ArcPro_proj\ArcPro_proj.gdb\buffers\buff_test_subset'
fishnet = r'C:\Data\working\AK_Fishing_VMS\2021_Delivery\ArcPro_proj\ArcPro_proj.gdb\fishnets\vms_net1k'
unionOut = r'C:\Data\working\AK_Fishing_VMS\2021_Delivery\ArcPro_proj\ArcPro_proj.gdb\unions\union'
# function to get unique values for the YEAR field found within the trawlBuffs fc
def unique_values(table, field):
with arcpy.da.SearchCursor(table, [field]) as cursor:
return sorted({row[0] for row in cursor})
# Get the unique values for the field 'YEAR' found within the 'trawl_buffs' featureclass table
yearVals = unique_values(trawlBuffs, "YEAR")
unique_year = set(yearVals)
# Get the unique values for the field 'AGENCY_GEAR' found within the 'trawl_buffs' featureclass table
gearVals = unique_values(trawlBuffs, "AGENCY_GEAR")
unique_gear = set(gearVals)
#loop through the years, create selection, union, make permanent
for year in unique_year:
yearSelectionClause = '{0} = {1}'.format('YEAR', year)
for gear in unique_gear:
gearSelectionClause = '{0} = "{1}"'.format('AGENCY_GEAR', gear)
new_layer = str([year, gear]) + "_union"
arcpy.MakeFeatureLayer_management(trawlBuffs, new_layer)
arcpy.SelectLayerByAttribute_management(new_layer, "NEW_SELECTION", newSelectionClause)
out_feat = unionOut + str(year)
arcpy.Union_analysis([fishnet, new_layer], out_feat)