public Stop(Coordinate coordinate, SyncromaticsStop stop, string direction) { Coordinate = coordinate; StopID = stop.ID; StopName = stop.Name.Contains("-") ? stop.Name.Split("-")[1].Trim() : stop.Name.Trim(); Direction = direction; RTPI = stop.RtpiNumber; }
private List <StopPath> ParseStopPaths(List <SyncromaticsWaypoint> waypoints, List <SyncromaticsStop> stops) { //this is REALLY messy but at least it works for now //TODO: Refactor List <StopPath> paths = new List <StopPath>(); for (int i = 0; i < stops.Count; i++) { SyncromaticsStop stop = stops[i]; //calculate stop paths int firstWaypointIndex = waypoints.FindIndex(x => x.Latitude == stop.Latitude && x.Longitude == stop.Longitude); if (i != stops.Count - 1) { int lastWayPointIndex = waypoints.FindIndex(x => x.Latitude == stops[i + 1].Latitude && x.Longitude == stops[i + 1].Longitude); List <Coordinate> coordinates = new List <Coordinate>(); for (int j = firstWaypointIndex; j < lastWayPointIndex + 1; j++) { coordinates.Add(new Coordinate(waypoints[j].Latitude, waypoints[j].Longitude)); } double totalDistance = 0.0; for (int j = 0; j < coordinates.Count; j++) { if (j != coordinates.Count - 1) { totalDistance += coordinates[j].DistanceTo(coordinates[j + 1]); } } StopPath path = new StopPath() { OriginStopID = stop.ID, DestinationStopID = stops[i + 1].ID, Path = coordinates, TotalPathDistance = totalDistance }; paths.Add(path); } else if (i == stops.Count - 1) { int lastWayPointIndex = waypoints.FindIndex(x => x.Latitude == stops[0].Latitude && x.Longitude == stops[0].Longitude); List <Coordinate> coordinates = new List <Coordinate>(); for (int j = firstWaypointIndex; j < waypoints.Count; j++) { coordinates.Add(new Coordinate(waypoints[j].Latitude, waypoints[j].Longitude)); } for (int j = 0; j <= lastWayPointIndex; j++) { coordinates.Add(new Coordinate(waypoints[j].Latitude, waypoints[j].Longitude)); } double totalDistance = 0.0; for (int j = 0; j < coordinates.Count; j++) { if (j != coordinates.Count - 1) { totalDistance += coordinates[j].DistanceTo(coordinates[j + 1]); } } StopPath path = new StopPath() { OriginStopID = stop.ID, DestinationStopID = stops[0].ID, Path = coordinates, TotalPathDistance = totalDistance }; paths.Add(path); } } return(paths); }
private List <Stop> ParseStops(List <SyncromaticsWaypoint> waypoints, List <SyncromaticsStop> syncromaticsStops) { List <Stop> stops = new List <Stop>(); for (int i = 0; i < syncromaticsStops.Count; i++) { SyncromaticsStop stop = syncromaticsStops[i]; //calculate stop paths int firstWaypointIndex = waypoints.FindIndex(x => x.Latitude == stop.Latitude && x.Longitude == stop.Longitude); if (firstWaypointIndex != -1) { SyncromaticsWaypoint waypoint = waypoints[firstWaypointIndex]; if (firstWaypointIndex != waypoints.Count - 1) { SyncromaticsWaypoint nextWaypoint = waypoints[firstWaypointIndex + 1]; Coordinate firstCoord = new Coordinate(waypoint.Latitude, waypoint.Longitude); Coordinate secondCoord = new Coordinate(nextWaypoint.Latitude, nextWaypoint.Longitude); double bearing = firstCoord.GetBearingTo(secondCoord); stops.Add(new Stop(firstCoord, stop, Coordinate.DegreesToCardinal(bearing))); } else { Console.WriteLine($"error: stop {stop.Name} does not have a valid NEXT waypoint!"); } } } /* * we are going to re-order these stops based on where the MSC and Lib is, since, combined, they are hubs * for every route. * * if a route has both the MSC and the Library as a stop point, they generally placed at opposite ends of the route. * for the purposes of this interim organization, if both are present, the msc will be first. * * msc ID: 401 * library ID: 102 */ List <Stop> tempStopsList = new List <Stop>(); int LIBIndex = stops.FindIndex(x => x.RTPI == 102); int MSCIndex = stops.FindIndex(x => x.RTPI == 401); if (MSCIndex != -1) { //route goes to msc at all (it's always first) for (int i = MSCIndex; i < stops.Count; i++) { tempStopsList.Add(stops[i]); } for (int i = 0; i < MSCIndex; i++) { tempStopsList.Add(stops[i]); } } else if (LIBIndex != -1) { //goes to lib only for (int i = LIBIndex; i < stops.Count; i++) { tempStopsList.Add(stops[i]); } for (int i = 0; i < LIBIndex; i++) { tempStopsList.Add(stops[i]); } } return(tempStopsList); }