I hacked together a quick script yesterday to add a category to each highway section based on the sections it intersects. The script will automatically decide what the max number of categories is as it goes along. Its not necessarily the most efficient/clean method, but I didn't any more free time to look into it. I'm also fairly new at python/arcpy, so the code could use a bit of cleanup:
import arcpy
from arcpy import env
# Set the workspace
env.workspace = "C:/Projects/Misc/HighwaySymbology"
# Create a copy of the highways shapefile
arcpy.CopyFeatures_management("highways.shp", "highways_out.shp")
# Add a category field
arcpy.AddField_management("highways_out.shp", "hwycat", "LONG", 9)
# Create a feature layer
fl = arcpy.MakeFeatureLayer_management("highways_out.shp", "Highways")
# Create the update cursor
rows = arcpy.UpdateCursor("highways_out.shp")
# Create the in-memory layer to select with
arcpy.MakeFeatureLayer_management("highways_out.shp", "HwySelection")
# Loop through every highway segment, one by one
for row in rows:
arcpy.SelectLayerByAttribute_management("HwySelection", "NEW_SELECTION", "FID = " + str(row.FID))
arcpy.SelectLayerByLocation_management("Highways", "INTERSECT", "HwySelection", "", "NEW_SELECTION")
numSelHwys = int(arcpy.GetCount_management("Highways").getOutput(0))
# Number of selected highways should always be > 1,
# as it will at least select the current highway
if numSelHwys > 1:
# Loop through all sections of the road and find the
# lowest unused highway category
selHwys = arcpy.SearchCursor("Highways")
hwyCategories = []
for selHwyRow in selHwys:
# Skip the current highway
if selHwyRow.FID == row.FID:
continue
if selHwyRow.hwycat > 0:
hwyCategories.append(selHwyRow.hwycat)
# Sort the list and find the first available category
hwyCategories.sort()
lastCat = 0
for cat in hwyCategories[:]:
if cat - lastCat > 1:
break
else:
lastCat = cat
lastCat += 1
row.hwycat = lastCat
rows.updateRow(row)
else:
# No adjoining segments, set the category to 1
row.hwycat = 1
rows.updateRow(row)
print
print "DONE"