示例#1
0
bool SubareaNet::Get_Location_Data (Location_File &file, Location_Data &data)
{
	//---- find the highest ID ----

	int id = file.Location ();
	if (id > max_location) max_location = id;

	id = file.Zone ();
	if (id > max_zone) max_zone = id;

	//---- do standard processing ----

	if (Data_Service::Get_Location_Data (file, data)) {

		//---- check the subarea boundary ----

		Link_Data *link_ptr = &link_array [data.Link ()];

		if (link_ptr->Type () == 0)  return (false);

		//---- copy the fields to the subarea file ----

		Db_Header *new_file = System_File_Header (NEW_LOCATION);

		new_file->Copy_Fields (file);

		if (!new_file->Write ()) {
			Error (String ("Writing %s") % new_file->File_Type ());
		}
		nlocation++;
		return (true);
	}
	return (false);
}
示例#2
0
bool TransitNet::Location_Processing (Db_File *fh)
{
	int zone;

	if (Network_Service::Location_Processing (fh)) {
		Location_File *file = (Location_File *) fh;

		int id = file->Location ();
		if (id > max_location) max_location = id;

		zone = file->Zone ();

		if (zone > 0) {
			Location_Data *location_ptr = location_data.New_Record ();

			Dir_Path_Data *dir_ptr = dir_data.Get (location_ptr->Link_Dir ());

			if (dir_ptr != NULL) {
				dir_ptr->Zone (zone);
			}
		}

		Location_File *new_file = (Location_File *) Network_Db_Base (NEW_ACTIVITY_LOCATION);

		new_file->Copy_Fields (file);

		if (!new_file->Write ()) {
			Error ("Writing %s", new_file->File_Type ());
		}
		nlocation++;
		return (true);
	}
	return (false);
}
示例#3
0
bool ArcNet::Location_Processing (Db_File *fh)
{
	int link, dir;
	double offset;

	XYZ_Point *pt_ptr;
	Offset_Data offset_rec;
	Link_Data *link_ptr;
	Location_Data *location_ptr;

	Location_File *file = (Location_File *) fh;

	if (First_Record ()) {
		arcview_location.Num_Points (1);

		if (!location_offset.Max_Records (file->Num_Records ())) {
			Error ("Insufficient Memory for Location Points");
		}
	}

	if (Network_Service::Location_Processing (file)) {
		arcview_location.Copy_Fields (file);

		location_ptr = location_data.New_Record ();

		link = location_ptr->Link ();
		dir = location_ptr->Dir ();
		offset = UnRound (location_ptr->Offset ());		

		link_ptr = link_data.Get (link);

		Link_Shape (link_ptr, dir, &points, offset, 0.0, location_side);

		pt_ptr = points [1];

		arcview_location.points.Set (1, pt_ptr);

		if (!arcview_location.Write_Record ()) {
			Error ("Writing ArcView Activity Location File");
		}

		//---- save the location offset data ----

		offset_rec.ID (location_ptr->ID ());
		offset_rec.Link (link);
		offset_rec.Dir (dir);
		offset_rec.Offset (offset);
		offset_rec.X (pt_ptr->x);
		offset_rec.Y (pt_ptr->y);
		offset_rec.Z (pt_ptr->z);

		if (!location_offset.Add (&offset_rec)) {
			Error ("Saving Activity Location Offsets");
		}
	}
	return (false);
}
示例#4
0
bool SubareaNet::Location_Processing (Db_File *fh)
{
    static Location_File *new_file;

    int id;
    Location_Data *location_ptr;
    Link_Data *link_ptr;

    Location_File *file = (Location_File *) fh;

    if (First_Record ()) {
        new_file = (Location_File *) Network_Db_Base (NEW_ACTIVITY_LOCATION);

        if (!location_data.Max_Records (file->Num_Records ())) goto mem_error;
    }

    id = file->Location ();
    if (id == 0) return (false);

    location_ptr = location_data.New_Record ();
    if (location_ptr == NULL) goto mem_error;

    location_ptr->ID (id);

    if (id > max_location) max_location = id;

    id = file->Zone ();

    if (id > max_zone) max_zone = id;

    link_ptr = link_data.Get (file->Link ());

    if (link_ptr != NULL && link_ptr->Type () > 0) {

        //---- copy the fields to the subarea file ----

        new_file->Copy_Fields (file);

        if (!new_file->Write ()) {
            Error ("Writing %s", new_file->File_Type ());
        }
        nlocation++;
        return (true);
    }
    return (false);

mem_error:
    Error ("Insufficient Memory for Activity Location Data");
    return (false);
}
示例#5
0
void Data_Service::Initialize_Locations (Location_File &file)
{
	Required_File_Check (file, LINK);
	
	int percent = System_Data_Reserve (LOCATION);

	if (location_array.capacity () == 0 && percent > 0) {
		int num = file.Num_Records ();

		if (percent != 100) {
			num = (int) ((double) num * percent / 100.0);
		}
		if (num > 1) {
			location_array.reserve (num);
			if (num > (int) location_array.capacity ()) Mem_Error (file.File_ID ());
		}
	}
}
示例#6
0
void Data_Service::Read_Locations (void)
{
	Location_File *file = (Location_File *) System_File_Handle (LOCATION);

	int num;
	bool zone_flag = System_Data_Flag (ZONE);

	Int_Map_Stat map_stat;
	Location_Data location_rec;

	//---- store the location data ----

	Show_Message (String ("Reading %s -- Record") % file->File_Type ());
	Set_Progress ();

	Initialize_Locations (*file);

	while (file->Read ()) {
		Show_Progress ();

		location_rec.Clear ();

		if (Get_Location_Data (*file, location_rec)) {
			map_stat = location_map.insert (Int_Map_Data (location_rec.Location (), (int) location_array.size ()));

			if (!map_stat.second) {
				Warning ("Duplicate Location Number = ") << location_rec.Location ();
				continue;
			} else {
				if (!file->Setback_Flag () && location_rec.Setback () == 0) {
					location_rec.Setback (Internal_Units (100.0, FEET));
				}
				location_array.push_back (location_rec);

				if (!zone_flag && location_rec.Zone () > Max_Zone_Number ()) {
					Max_Zone_Number (location_rec.Zone ());
				}
			}
		}
	}
	End_Progress ();
	file->Close ();

	Print (2, String ("Number of %s Records = %d") % file->File_Type () % Progress_Count ());

	num = (int) location_array.size ();

	if (num && num != Progress_Count ()) {
		Print (1, String ("Number of %s Data Records = %d") % file->File_ID () % num);
	}
	if (num > 0) System_Data_True (LOCATION);
}
示例#7
0
bool Data_Service::Get_Location_Data (Location_File &file, Location_Data &location_rec)
{
	int link, dir, offset;
	double setback;
	Link_Data *link_ptr;

	//---- read and save the data ----

	location_rec.Location (file.Location ());

	if (location_rec.Location () == 0) return (false);

	//---- check/convert the link number and direction  ----
	
	link = file.Link ();
	dir = file.Dir ();
	offset = Round (file.Offset ());

	link_ptr = Set_Link_Direction (file, link, dir, offset);

	location_rec.Link (link);
	location_rec.Dir (dir);
	location_rec.Offset (offset);

	setback = file.Setback ();
	location_rec.Setback (setback);

	if (Location_XY_Flag ()) {
		Points points;

		Link_Shape (link_ptr, dir, points, UnRound (offset), 0.0, setback);

		if (points.size () > 0) {
			location_rec.X (points [0].x);
			location_rec.Y (points [0].y);
		} else {
			Node_Data *node_ptr = &node_array [link_ptr->Anode ()];
		
			location_rec.X (node_ptr->X ());
			location_rec.Y (node_ptr->Y ());
		}
	}
	location_rec.Zone (file.Zone ());

	if (location_rec.Zone () > 0 && System_Data_Flag (ZONE)) {
		Int_Map_Itr map_itr = zone_map.find (location_rec.Zone ());
		if (map_itr == zone_map.end ()) {
			Warning (String ("Location %d Zone %d was Not Found") % location_rec.Location () % location_rec.Zone ());
			return (false);
		}
		location_rec.Zone (map_itr->second);
	} else if (location_rec.Zone () == 0) {
		location_rec.Zone (-1);

		//---- delete extra activity location used for transit stops ----

		if (file.Version () <= 40) return (false);
	}
	location_rec.Notes (file.Notes ());

	return (true);
}
示例#8
0
bool LinkSum::Get_Location_Data (Location_File &file, Location_Data &data)
{
	int i, field, link, lvalue1, lvalue2, zone;
	double dvalue1, dvalue2;
	String buffer;

	Db_Field *fld;
	Link_Location loc_rec;
	Int_Itr int_itr;
	Int_Map_Itr map_itr;

	//---- get the link number ----

	link = file.Link ();
	if (link == 0) return (false);
	data.Link (link);

	//---- sum the activities on links ----

	if (activity_flag) {
		if (!link_db.Read_Record (link)) {
			Error (String ("Reading Link Database Record %d") % link);
		}

		//---- sum the data fields ----

		for (i=1, int_itr = field_list.begin (); int_itr != field_list.end (); int_itr++, i++) {
			field = *int_itr;

			fld = file.Field (field);

			if (fld->Type () == DB_INTEGER) {
				lvalue1 = file.Get_Integer (field);
				lvalue2 = link_db.Get_Integer (i);

				lvalue2 += lvalue1;
				link_db.Put_Field (i, lvalue2);
			} else if (fld->Type () == DB_DOUBLE) {
				dvalue1 = file.Get_Double (field);
				dvalue2 = link_db.Get_Double (i);

				dvalue2 += dvalue1;
				link_db.Put_Field (i, dvalue2);
			} else if (fld->Type () == DB_STRING) {
				link_db.Put_Field (i, file.Get_String (field));
			}
		}

		//---- save the changes ----

		if (!link_db.Write_Record (link)) {
			Error (String ("Writing Link Database Record %d") % link);
		}
	}

	//---- add a link location record ----

	if (zone_flag || group_flag) {
		zone = file.Zone ();

		if (zone > 0) {
			map_itr = link_map.find (link);
			if (map_itr == link_map.end ()) return (false);
			link = map_itr->second;

			loc_rec.link = link;
			loc_rec.location = i = file.Location ();
			loc_rec.zone = zone;
			loc_rec.count = 0;

			link_location.insert (Link_Loc_Map_Data (Int2_Key (link, i), loc_rec));
		}
	}

	//---- don't save the location data ----

	return (false);
}
示例#9
0
bool Converge_Service::Get_Location_Data (Location_File &file, Location_Data &data)
{
	if (Data_Service::Get_Location_Data (file, data)) {
		if (capacity_flag) {
			int next, num;
			double share, total;
			Loc_Cap_Data loc_cap_data;
			Int_Itr itr;

			loc_cap_data.capacity = file.Get_Integer (loc_cap_field);
			loc_cap_data.demand = 0;
			loc_cap_data.failed = 0;
			num = 0;

			for (itr = next_des_field.begin (); itr != next_des_field.end (); itr++) {
				next = file.Get_Integer (*itr);
				if (next > 0) {
					loc_cap_data.next_des.push_back (next);
					num++;
				}
			}
			if (num > 1) {
				if (des_share_field.size () > 0) {
					total = 0.0;

					for (next=0; next < num; next++) {
						if (next < (int) des_share_field.size ()) {
							share = file.Get_Double (des_share_field [next]);
							if (share == 0) share = 1.0;
						} else {
							share = 1.0;
						}
						loc_cap_data.shares.push_back (share);
						total += share;
					}
					if (total != 1.0) {
						if (total > 0.0) {
							for (next=0; next < num; next++) {
								loc_cap_data.shares [next] /= total;
							}
						} else {
							share = 1.0 / num;
							for (next=0; next < num; next++) {
								loc_cap_data.shares [next] = share;
							}
						}
					}
				} else {
					share = 1.0 / num;
					for (next=0; next < num; next++) {
						loc_cap_data.shares.push_back (share);
					}
				}
			}
			loc_cap_array.push_back (loc_cap_data);
		}
		if (fuel_flag) {
			Loc_Fuel_Data loc_fuel_data;
			Int_Itr itr;

			loc_fuel_data.supply = Round (file.Get_Integer (loc_fuel_field));
			loc_fuel_data.consumed = 0;
			loc_fuel_data.failed = 0;
			loc_fuel_data.ran_out = 0;

			loc_fuel_array.push_back (loc_fuel_data);
		}
		return (true);
	}
	return (false);
}