int Data_Service::Put_Lane_Use_Data (Lane_Use_File &file, Lane_Use_Data &data) { double rate, toll; Dir_Data *dir_ptr; Link_Data *link_ptr; Veh_Type_Data *veh_type_ptr; dir_ptr = &dir_array [data.Dir_Index ()]; link_ptr = &link_array [dir_ptr->Link ()]; file.Link (link_ptr->Link ()); file.Dir (dir_ptr->Dir ()); file.Lanes (Make_Lane_Range (dir_ptr, data.Low_Lane (), data.High_Lane ())); file.Use (data.Use ()); file.Type (data.Type ()); if (data.Min_Veh_Type () < 0) { file.Min_Veh_Type (0); } else if (veh_type_array.size () > 0) { veh_type_ptr = &veh_type_array [data.Min_Veh_Type ()]; file.Min_Veh_Type (veh_type_ptr->Type ()); } else { file.Min_Veh_Type (data.Min_Veh_Type ()); } if (data.Max_Veh_Type () < 0) { file.Max_Veh_Type (0); } else if (veh_type_array.size () > 0) { veh_type_ptr = &veh_type_array [data.Max_Veh_Type ()]; file.Max_Veh_Type (veh_type_ptr->Type ()); } else { file.Max_Veh_Type (data.Max_Veh_Type ()); } file.Min_Traveler (MAX (data.Min_Traveler (), 0)); file.Max_Traveler (MAX (data.Max_Traveler (), 0)); file.Start (data.Start ()); file.End (data.End ()); file.Length (UnRound (data.Length ())); file.Offset (UnRound (data.Offset ())); toll = UnRound (data.Toll ()); rate = UnRound (data.Toll_Rate ()); if (rate > 0) { if (Metric_Flag ()) { rate /= 1000.0; } else { rate /= MILETOFEET; } toll -= DTOI (rate * link_ptr->Length ()); } file.Toll (DTOI (toll)); file.Toll_Rate (rate); file.Min_Delay (UnRound (data.Min_Delay ())); file.Max_Delay (UnRound (data.Max_Delay ())); file.Speed (UnRound (data.Speed ())); file.Speed_Factor (UnRound (data.Spd_Fac ()) / 10.0); file.Capacity (data.Capacity ()); file.Cap_Factor (UnRound (data.Cap_Fac ()) / 10.0); file.Notes (data.Notes ()); if (!file.Write ()) { Error (String ("Writing %s") % file.File_Type ()); } return (1); }
bool Data_Service::Get_Lane_Use_Data (Lane_Use_File &file, Lane_Use_Data &lane_use_rec) { int link, dir, lanes, offset, dir_index, low, high; double rate; Link_Data *link_ptr; Int_Map_Itr map_itr; //---- check/convert the link number and direction ---- link = file.Link (); if (link <= 0) return (false); dir = file.Dir (); offset = Round (file.Offset ()); link_ptr = Set_Link_Direction (file, link, dir, offset); if (link_ptr == 0) return (false); if (dir) { dir_index = link_ptr->BA_Dir (); } else { dir_index = link_ptr->AB_Dir (); } if (dir_index < 0) { Warning (String ("Lane Use %d Link %d Direction %s was Not Found") % Progress_Count () % link_ptr->Link () % ((dir) ? "BA" : "AB")); return (false); } lane_use_rec.Dir_Index (dir_index); //---- set the restriction type ---- lane_use_rec.Type (file.Type ()); lane_use_rec.Use (file.Use ()); //---- convert the vehicle type range ---- low = file.Min_Veh_Type (); high = file.Max_Veh_Type (); if (low > 0) { map_itr = veh_type_map.find (low); if (map_itr == veh_type_map.end ()) { map_itr = veh_type_map.lower_bound (low); if (map_itr == veh_type_map.end ()) { Warning (String ("Lane Use %d Vehicle Type %d was Not Found") % Progress_Count () % low); low = -1; } else { low = map_itr->second; } } else { low = map_itr->second; } } else { low = -1; } if (high > 0) { map_itr = veh_type_map.find (high); if (map_itr == veh_type_map.end ()) { int h = high; while (h > 0) { map_itr = veh_type_map.find (--h); if (map_itr != veh_type_map.end ()) break; } if (h >= 0) { high = map_itr->second; } else { Warning (String ("Lane Use %d Vehicle Type %d was Not Found") % Progress_Count () % high); high = -1; } } else { high = map_itr->second; } if (high >= 0 && low < 0) low = 0; } else { high = -1; } if (low > high) { if (high == -1) { high = low; } else { Warning (String ("Lane Use %d Vehicle Type Range %d-%d is Illegal") % Progress_Count () % file.Min_Veh_Type () % file.Max_Veh_Type ()); high = low; } } lane_use_rec.Min_Veh_Type (low); lane_use_rec.Max_Veh_Type (high); //---- convert the traveler type range ---- low = file.Min_Traveler (); high = file.Max_Traveler (); if (low <= 0) low = -1; if (high > 0) { if (low < 0) low = 0; } else { high = -1; } if (low > high) { if (high == -1) { high = low; } else { Warning (String ("Lane Use %d Traveler Type Range %d-%d is Illegal") % Progress_Count () % file.Min_Traveler () % file.Max_Traveler ()); high = low; } } lane_use_rec.Min_Traveler (low); lane_use_rec.Max_Traveler (high); //----- length and offset ---- lane_use_rec.Length (file.Length ()); if (lane_use_rec.Length () > 0) { if (offset > 0 || lane_use_rec.Length () < link_ptr->Length ()) { lane_use_rec.Offset (offset); } else { lane_use_rec.Offset (0); lane_use_rec.Length (0); } } else { lane_use_rec.Offset (0); } //---- lane number ---- lanes = file.Lanes (); if (file.Version () <= 40 && lanes > 0) { low = high = lanes - 1; } else { Convert_Lane_Range (dir_index, lanes, low, high); } lane_use_rec.Low_Lane (low); lane_use_rec.High_Lane (high); //----- optional fields ---- lane_use_rec.Start (file.Start ()); lane_use_rec.End (file.End ()); if (lane_use_rec.End () == 0) lane_use_rec.End (Model_End_Time ()); lane_use_rec.Toll (Round (file.Toll ())); lane_use_rec.Toll_Rate (file.Toll_Rate ()); if (lane_use_rec.Toll_Rate () > 0) { rate = UnRound (lane_use_rec.Toll_Rate ()); if (Metric_Flag ()) { rate /= 1000.0; } else { rate /= MILETOFEET; } lane_use_rec.Toll (lane_use_rec.Toll () + DTOI (rate * link_ptr->Length ())); } lane_use_rec.Min_Delay (file.Min_Delay ()); lane_use_rec.Max_Delay (file.Max_Delay ()); lane_use_rec.Speed (file.Speed ()); lane_use_rec.Spd_Fac (file.Speed_Factor ()); lane_use_rec.Capacity (file.Capacity ()); lane_use_rec.Cap_Fac (file.Cap_Factor ()); lane_use_rec.Notes (file.Notes ()); return (true); }
bool ArcNet::Get_Lane_Use_Data (Lane_Use_File &file, Lane_Use_Data &lane_use_rec) { int dir, center, lane, lane1, lane2, index, type, pocket; double length, offset, start, end, side, width, setbacka, setbackb, off, len; bool dir_flag, left_flag; Link_Data *link_ptr; Dir_Data *dir_ptr; Pocket_Data *pocket_ptr; Points_Itr pt_itr; if (Data_Service::Get_Lane_Use_Data (file, lane_use_rec)) { if (arcview_lane_use.Is_Open ()) { if (time_flag) { if (lane_use_rec.Start () > time || time > lane_use_rec.End ()) return (false); } arcview_lane_use.Copy_Fields (file); arcview_lane_use.parts.clear (); arcview_lane_use.clear (); dir_ptr = &dir_array [lane_use_rec.Dir_Index ()]; dir = dir_ptr->Dir (); link_ptr = &link_array [dir_ptr->Link ()]; offset = UnRound (lane_use_rec.Offset ()); length = UnRound (lane_use_rec.Length ()); if (offset == 0.0 && length == 0.0) { offset = 0.0; length = UnRound (link_ptr->Length ()); } start = offset; end = start + length; length = UnRound (link_ptr->Length ()); if (dir == 0) { setbacka = UnRound (link_ptr->Aoffset ()); setbackb = UnRound (link_ptr->Boffset ()); dir_flag = (link_ptr->BA_Dir () >= 0); } else { setbacka = UnRound (link_ptr->Boffset ()); setbackb = UnRound (link_ptr->Aoffset ()); dir_flag = (link_ptr->AB_Dir () >= 0); } if (start < setbacka) start = setbacka; side = length - setbackb; if (end > side) end = side; length = end - start; offset = start; //---- draw the lanes ---- if (lanes_flag) { if (center_flag) { if (!dir_flag) { center = dir_ptr->Lanes () + dir_ptr->Left () + dir_ptr->Right () + 1; } else { center = 1; } } else { center = 1; } //---- set the lane range ---- lane1 = lane_use_rec.Low_Lane (); lane2 = lane_use_rec.High_Lane (); width = lane_width / 2.0; for (lane = lane1; lane <= lane2; lane++) { side = (2 + 2 * lane - center) * width; left_flag = (lane < dir_ptr->Left ()); off = offset; len = length; if (left_flag || lane >= (dir_ptr->Left () + dir_ptr->Lanes ())) { for (index = dir_ptr->First_Pocket (); index >= 0; index = pocket_ptr->Next_Index ()) { pocket_ptr = &pocket_array [index]; type = pocket_ptr->Type (); pocket = pocket_ptr->Lanes (); if (type == LEFT_TURN || type == LEFT_MERGE) { if (!left_flag) continue; if (lane < (dir_ptr->Left () - pocket)) continue; } else { if (left_flag) continue; if (lane >= dir_ptr->Left () + dir_ptr->Lanes () + pocket) continue; } off = UnRound (pocket_ptr->Offset ()); len = UnRound (pocket_ptr->Length ()); if (off > end || (off + len) < start) continue; len += off; if (off < start) off = start; if (len > end) len = end; len -= off; if (len < 0) len = 0; break; } if (index < 0) continue; } Link_Shape (link_ptr, dir, points, off, len, side); arcview_lane_use.parts.push_back ((int) arcview_lane_use.size ()); for (pt_itr = points.begin (); pt_itr != points.end (); pt_itr++) { arcview_lane_use.push_back (*pt_itr); } } } else { arcview_lane_use.parts.push_back ((int) arcview_lane_use.size ()); Link_Shape (link_ptr, dir, arcview_lane_use, offset, length, 0.0); } if (arcview_lane_use.size () > 0) { if (!arcview_lane_use.Write_Record ()) { Error (String ("Writing %s") % arcview_lane_use.File_Type ()); } } } } return (false); }