public override int GetHashCode() { return(Airway.GetHashCode() ^ Distance.GetHashCode() ^ Type.GetHashCode() ^ InnerWaypoints.HashCodeByElem()); }
static List <Airway> GetOrderedAirways(List <string> awys) { List <Airway> airways = new List <Airway>(); foreach (string line in awys) { string awyline = new string(line.Trim().TakeWhile(c => c != ';').ToArray()); if (awyline.Length <= 0) { continue; } string[] awy = awyline.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (awy.Length != 5) { continue; } string name = new string(awy[0].TakeWhile(c => c != '(').ToArray());//strip (xx) shit vatpac adds. Airway airway = airways.SingleOrDefault(a => a.Name == name); if (airway == null) { airway = new Airway(name); airways.Add(airway); } string point1 = ""; if (awy[1] == awy[2])//then not a lat lon { point1 = awy[1]; } else { point1 = ConvertSectorLatLonToISO(awy[1]) + ConvertSectorLatLonToISO(awy[2]); } string point2 = ""; if (awy[3] == awy[4])//then not a lat lon { point2 = awy[3]; } else { point2 = ConvertSectorLatLonToISO(awy[3]) + ConvertSectorLatLonToISO(awy[4]); } airway.UnorderedPoints.Add(new PointPair(point1, point2)); } foreach (Airway a in airways) { if (a.UnorderedPoints.Count < 1) { continue; } List <PointPair> ordered = new List <PointPair>(); List <PointPair> cantFit = new List <PointPair>(); ordered.Add(a.UnorderedPoints[0]);//start with first item for (int i = 1; i < a.UnorderedPoints.Count; i++) { if (InsertPoint(a.UnorderedPoints[i], ordered, cantFit)) { bool testCants = true; while (testCants) { testCants = false; for (int j = 0; j < cantFit.Count; j++) { if (InsertPoint(cantFit[j], ordered, cantFit)) { j--; testCants = true; } } } } } ordered.Reverse(); a.OrderedPoints = ordered; } return(airways); }
public static void Main() { Airway airway; AwyIntxn awyintxn; AwyPt awypt; int number; string line; while ((line = Console.ReadLine()) != null) { if (line.StartsWith("AWY1")) { string awyname = line.Substring(4, 5).Trim(); // eg "V1" string awytype = line.Substring(9, 1).Trim(); // eg "A" "H" or blank int seq = int.Parse(line.Substring(10, 5)); // eg "140" string copnm = line.Substring(107, 3).Trim(); // eg "024" usually blank string key = awytype + "-" + awyname; if (!airways.TryGetValue(key, out airway)) { airway = new Airway(); airway.awyname = awyname; airway.awytype = awytype; airways[key] = airway; } if (!airway.awypts.TryGetValue(seq, out awypt)) { awypt = new AwyPt(); awypt.seq = seq; airway.awypts[seq] = awypt; } awypt.copnm = copnm; } if (line.StartsWith("AWY2")) { string awyname = line.Substring(4, 5).Trim(); // eg "V1" string awytype = line.Substring(9, 1).Trim(); // eg "A" "H" or blank int seq = int.Parse(line.Substring(10, 5)); // eg "140" string fixid = line.Substring(15, 30).Trim(); // eg "BOSOX" "LAWRENCE" string fixtype = line.Substring(45, 19).Trim(); // eg "VORTAC" "REP-PT" double fixlat = ParseLL(line.Substring(83, 14), 'N', 'S'); // eg "30-20-19.965N" double fixlon = ParseLL(line.Substring(97, 14), 'E', 'W'); // eg "081-30-35.738W" string navid = line.Substring(116, 4).Trim(); // navaid id (might be blank) string key = awytype + "-" + awyname; if (!airways.TryGetValue(key, out airway)) { airway = new Airway(); airway.awyname = awyname; airway.awytype = awytype; airways[key] = airway; } if (!airway.awypts.TryGetValue(seq, out awypt)) { awypt = new AwyPt(); awypt.seq = seq; airway.awypts[seq] = awypt; } if (fixid.Contains("BORDER")) { airway.awypts.Remove(seq); } string fixtable = "FIX"; if (int.TryParse(fixid, out number)) { if (!awyintxns.TryGetValue(number, out awyintxn)) { awyintxn = new AwyIntxn(); awyintxn.number = number; awyintxn.type = fixtype; awyintxn.lat = fixlat; awyintxn.lon = fixlon; awyintxns[number] = awyintxn; } else if ((awyintxn.lat != fixlat) || (awyintxn.lon != fixlon)) { throw new Exception("conflicting definitions of intersection " + number); } fixid = number.ToString(); fixtable = "INT"; } else if (navid != "") { fixid = navid; fixtable = "NAV"; } awypt.fixid = fixid; awypt.fixtable = fixtable; awypt.lat = fixlat; awypt.lon = fixlon; } } StreamWriter intxnfile = new StreamWriter("intersections.csv"); foreach (AwyIntxn ai in awyintxns.Values) { intxnfile.WriteLine(ai.number + "," + ai.type + "," + ai.lat + "," + ai.lon); } intxnfile.Close(); StreamWriter airwayfile = new StreamWriter("airways.csv"); foreach (Airway awy in airways.Values) { airwayfile.WriteLine(awy.awyname + "," + awy.awytype + "," + awy.awypts.Count); foreach (AwyPt pt in awy.awypts.Values) { airwayfile.WriteLine("," + pt.fixid + "," + pt.fixtable + "," + pt.lat + "," + pt.lon + "," + pt.copnm); } } airwayfile.Close(); }