index = ordered_ABBs.index(ABB_list) start_ratio = sum([ordered_ABBs[i][1] for i in xrange(index)]) ABB_list.append(start_ratio) # Append start_ratio to track "how far along" each segment begins... for ABB, length_ratio, start_ratio in ordered_ABBs: index = ordered_ABBs.index([ABB, length_ratio, start_ratio]) if ABB_tuple in split_dict_ABB: # Check if key exists yet or not split_dict_ABB[ABB_tuple].append((ABB, index, start_ratio, length_ratio)) else: split_dict_ABB[ABB_tuple] = [(ABB, index, start_ratio, length_ratio)] # ----------------------------------------------------------------------------- # Update route systems. # ----------------------------------------------------------------------------- # Build dict to store all arc geometries for mix-and-match route-building. vertices_comprising = MHN.build_geometry_dict(temp_arcs, 'ABB') arcpy.AddMessage('\nRebuilding route systems (in memory):') def update_route_system(header, itin, vertices_comprising, split_dict_ABB, new_ABB_values, common_id_field, order_field=None): ''' A method for updating any of the MHN's route systems: hwyproj, bus_base, bus_current, and bus_future. order_field argument allows for separate treatment of hwyproj and the bus routes. ''' # Copy itinerary table to memory for non-destructive editing header_name = MHN.break_path(header)['name'] itin_name = MHN.break_path(itin)['name'] arcpy.AddMessage('-- ' + header_name + '...') itin_copy_path = MHN.mem itin_copy_name = itin_name + '_copy' itin_copy = os.path.join(itin_copy_path, itin_copy_name)
route_arcs[route_id] = [arc_id] else: route_arcs[route_id].append(arc_id) arc_attr = [arc_attr_dict[field] for field in itin_fields] cursor.insertRow(arc_attr) raw_itin.close() os.remove(itin_csv) # Validate segment travel times. MHN.validate_itin_times(temp_itin_table) # Update itinerary F_MEAS & T_MEAS. MHN.calculate_itin_measures(temp_itin_table) # Build dict to store all arc geometries for mix-and-match route-building. vertices_comprising = MHN.build_geometry_dict(MHN.arc, 'ABB') # Generate route features one at a time. arcs_traversed_by = {} field_list = ['ABB', common_id_field] with arcpy.da.SearchCursor(temp_itin_table, field_list) as itin_cursor: for row in itin_cursor: abb = row[0] common_id = row[1] if common_id in arcs_traversed_by: arcs_traversed_by[common_id].append(abb) else: arcs_traversed_by[common_id] = [abb] common_id_list = sorted(route_arcs.keys()) with arcpy.da.InsertCursor(temp_routes_fc, ['SHAPE@', common_id_field]) as routes_cursor:
route_id = arc_attr_dict[common_id_field] arc_id = arc_attr_dict['ABB'] if route_id not in route_arcs.keys(): route_arcs[route_id] = [arc_id] else: route_arcs[route_id].append(arc_id) arc_attr = [arc_attr_dict[field] for field in itin_fields] cursor.insertRow(arc_attr) raw_itin.close() os.remove(itin_csv) # Update itinerary F_MEAS & T_MEAS. MHN.calculate_itin_measures(temp_itin_table) # Build dict to store all arc geometries for mix-and-match route-building. vertices_comprising = MHN.build_geometry_dict(MHN.arc, 'ABB') # Generate route features one at a time. arcs_traversed_by = {} field_list = ['ABB', common_id_field] with arcpy.da.SearchCursor(temp_itin_table, field_list) as itin_cursor: for row in itin_cursor: abb = row[0] common_id = row[1] if common_id in arcs_traversed_by: arcs_traversed_by[common_id].append(abb) else: arcs_traversed_by[common_id] = [abb] common_id_list = sorted(route_arcs.keys()) with arcpy.da.InsertCursor(temp_routes_fc, ['SHAPE@', common_id_field]) as routes_cursor:
start_ratio ) # Append start_ratio to track "how far along" each segment begins... for ABB, length_ratio, start_ratio in ordered_ABBs: index = ordered_ABBs.index([ABB, length_ratio, start_ratio]) if ABB_tuple in split_dict_ABB: # Check if key exists yet or not split_dict_ABB[ABB_tuple].append( (ABB, index, start_ratio, length_ratio)) else: split_dict_ABB[ABB_tuple] = [(ABB, index, start_ratio, length_ratio)] # ----------------------------------------------------------------------------- # Update route systems. # ----------------------------------------------------------------------------- # Build dict to store all arc geometries for mix-and-match route-building. vertices_comprising = MHN.build_geometry_dict(temp_arcs, 'ABB') arcpy.AddMessage('\nRebuilding route systems (in memory):') def update_route_system(header, itin, vertices_comprising, split_dict_ABB, new_ABB_values, common_id_field, order_field=None): ''' A method for updating any of the MHN's route systems: hwyproj, bus_base, bus_current, and bus_future. order_field argument allows for separate treatment of hwyproj and the bus routes. '''