I have data in a table that represents values over 3 different categories (Average Day, Weekday, Weekend) and 5 different time periods (All Day, Morning, Mid-Day, Afternoon, and Evening). The data is by block group and there is a one to many relationship (i.e. duplicate block group IDs in the table), so a simple join to my block group feature class is not the answer.
I created the model below to help me visualize the data in separate map layers. The model iterates through the unique combination of categories and times (e.g. "0: Average Day (M-Su), 0: All Day (12am-12am)", "0: Average Day (M-Su), 1: Morning (6am-10am)", etc.) and creates a table with unique block groups by day type and time that I can join to the main block group feature class and export each iteration into a new feature class. The %n% variable names the output feature class with a unique number. Normally, I would use %Value%, but the field data (shown above) is rather long and contains spaces, dashes, and parentheses that we would not want that in the feature class name. The model below works perfectly the first time that I run it, but when I give it a new input table (I have lots of tables to process), the iteration no longer gives me all of the output data. It looks like it is overwriting the data for each iteration and just giving me a single output feature class. Any ideas on how to fix this? It seems like it should be pretty simple and I have no idea why the iteration doesn't continue to work with the new input data.
I also tried to convert this to Python code and I'm getting stuck on how to create a unique number for each string in the unique set of field values. (FYI - I am not a developer/programmer so my Python skills are minimal.)
# Import arcpy module
from arcpy import env
# Load required toolboxes
arcpy.ImportToolbox("C:\\Program Files (x86)\\ArcGIS\Desktop10.3\\ArcToolbox\\Toolboxes\\Data Management Tools.tbx")
# Set up workspace environment
arcpy.env.workspace = "c:\\test\\TimeDatabyBG.gdb"
arcpy.env.overwriteOutput = True
# Script arguments
InTable = arcpy.GetParameterAsText(0)
InName = arcpy.GetParameterAsText(1)
Field = arcpy.GetParameterAsText(2)
OutTable = arcpy.GetParameterAsText(3)
OutWorkspace = arcpy.GetParameterAsText(4)
Blockgroups = arcpy.GetParameterAsText(5)
OutFC = arcpy.GetParameterAsText(6)
# InTable example = "c:\\test\\TimeDatabyBG.gdb\\tbl_CA_RanchoSanta_Origins"
# InName example = "CA_RanchoSanta"
# Field example = "Day_Type_Part"
# OutTable example = os.path.join(OutWorkspace, "InName")
# OutWorkspace example = "c:\\test\\TimeDatabyBG.gdb\\"
# Blockgroups example = "c:\\test\\TimeDatabyBG.gdb\\"bg_prj"
# OutFC example = os.path.join(OutWorkspace, "BG_" + InName + iterated number
# or "c:\\test\\TimeDatabyBG.gdb\\"BG_CA_RanchoSanta_1"
cursor = arcpy.da.SearchCursor(InTable, Field)
values = [row for row in arcpy.da.SearchCursor(InTable, Field)]
uniqueValues = set(values)
#the script works up to this point in that it can print out a list of the unique values in the "Day_Type_Part" field, but I don't know how to translate this into a unique selection and value for the name of the output table in the line below.
# Process: Copy Rows
# Process: Add Join
arcpy.AddJoin_management(Blockgroups, "ID", OutTable, "BG_ID", "KEEP_COMMON")
# Process: Copy Features
arcpy.CopyFeatures_management(Blockgroups, OutFC, "", "0", "0", "0")
# Process: Remove Join
Any help will be greatly appreciated!