private static void LoadData() { //Load Routes. var routeLines = File.ReadAllLines("google_transit/routes.txt").ToList(); //Remove header line. routeLines.RemoveAt(0); foreach (var line in routeLines) { var lineParts = Regex.Split(line, ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"); routes.Add(new Route { RouteId = lineParts[4], RouteShortName = lineParts[6], Trips = new List<Trip>() }); } //A route has many trips (e.g. The same number runs multiple times). var tripLines = File.ReadAllLines("google_transit/trips.txt").ToList(); tripLines.RemoveAt(0); //Use a dictionary since it will be WAY faster later to find all these trips when we have to add stops to them. Dictionary<string, Trip> tripLookup = new Dictionary<string, Trip>(); foreach (var line in tripLines) { var lineParts = Regex.Split(line, ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"); Trip newTrip = new Trip { RouteId = lineParts[1], TripId = lineParts[6], StopTimes = new List<TripStopTime>() }; routes.Single(x => x.RouteId == newTrip.RouteId).Trips.Add(newTrip); tripLookup.Add(newTrip.TripId, newTrip); } //For each trip, load in the time they hit each stop. var stopTimeLines = File.ReadAllLines("google_transit/stop_times.txt").ToList(); stopTimeLines.RemoveAt(0); foreach (var line in stopTimeLines) { var lineParts = Regex.Split(line, ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"); //Sometimes the trip ends after midnight. (Or sometimes longer), so just skip these ones for now. if (int.Parse(lineParts[2].Split(':')[0]) > 23) { continue; } TripStopTime stopTime = new TripStopTime { TripId = lineParts[0], StopId = lineParts[3], Time = DateTime.Parse(lineParts[2]) }; //Z appended so it comes through as UTC. tripLookup[stopTime.TripId].StopTimes.Add(stopTime); } //Load stop data. var stopLines = File.ReadAllLines("google_transit/stops.txt").ToList(); stopLines.RemoveAt(0); foreach (var line in stopLines) { var lineParts = Regex.Split(line, ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"); Stop newStop = new Stop { StopId = lineParts[3], StopLat = double.Parse(lineParts[0]), StopLng = double.Parse(lineParts[2]) }; stopLookup.Add(newStop.StopId, newStop); } }