Select to view content in your preferred language

Help with time series data by block groups automation

4350
11
Jump to solution
02-25-2016 10:57 AM
SusanZwillinger
Frequent Contributor

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

import arcpy

from arcpy import env

import os

# 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"

# Iteration

cursor = arcpy.da.SearchCursor(InTable, Field)

values = [row[0] for row in arcpy.da.SearchCursor(InTable, Field)]

uniqueValues = set(values)

print(uniqueValues)

#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

arcpy.CopyRows_management(InTable, OutTable)

# 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

arcpy.RemoveJoin_management(Blockgroups, "")

Any help will be greatly appreciated!

Thanks,

-Susan-

0 Kudos
11 Replies
SusanZwillinger
Frequent Contributor

Thanks, Ciro.  It is good to know why the model was not working properly. 

I still hope that Esri will log this as a bug because the row selection should work with any text field, regardless of whether there are numbers, parentheses and other characters in the text.

0 Kudos
CiroRomero
Emerging Contributor

Hello Susan,

After performing additional tests I was able to discard the possibility that the special characters caused the issue. Yesterday I was able to replicate your same model and it ran successfully. Today I uncompressed the zip file that you posted above, clicked on the ModelTest.mxd, removed the layers from the table of contents, added them again, I fixed the input and output paths on the model, and the model run successfully several times.

Recorded video: http://screencast-o-matic.com/watch/cDeQFq1Dzb

I believe that having removed the layers from the table of contents, and having added them again may have helped.

Regards,

Ciro

0 Kudos