public CircleLine(string[] _data) : base(_data[1]) { if (_data.Length == 4) { Airport apTemp = Airport.Find(_data[2]); if (apTemp != null) { centre = new double[2] { apTemp.lat, apTemp.lon }; } } else if (_data.Length == 5) { string latString = _data[2].Substring(1, _data[2].Length - 1); string[] latSplit = latString.Split('.'); Array.Resize(ref latSplit, 4); double lat = double.Parse(latSplit[0], Program.DataCulture) + double.Parse(latSplit[1], Program.DataCulture) / 60 + double.Parse(latSplit[2] + "." + latSplit[3], Program.DataCulture) / 3600; if (char.ToUpper(_data[2][0]) == 'S') { lat = -lat; } string lonString = _data[3].Substring(1, _data[3].Length - 1); string[] lonSplit = lonString.Split('.'); Array.Resize(ref lonSplit, 4); double lon = double.Parse(lonSplit[0], Program.DataCulture) + double.Parse(lonSplit[1], Program.DataCulture) / 60 + double.Parse(lonSplit[2] + "." + lonSplit[3], Program.DataCulture) / 3600; if (char.ToUpper(_data[3][0]) == 'W') { lon = -lon; } centre = new double[] { lat, lon }; } radius = double.Parse(_data.Last(), Program.DataCulture); }
static void ReadESE(string _file) { List <PolyLine> deferred = new List <PolyLine>(); bool isPositions = false; bool isAirspace = false; bool isPolyLine = false; bool isSector = false; using (FileStream fs = File.Open(_file, FileMode.Open, FileAccess.Read, FileShare.Read)) using (BufferedStream bs = new BufferedStream(fs)) using (StreamReader sr = new StreamReader(bs)) { string raw; while ((raw = sr.ReadLine()) != null) { string live = raw.Split(';')[0]; live = live.Replace('\t', ' '); if (raw.Length != 0 && raw.First() != ';') { if (raw.First() == '[') { isPositions = false; isAirspace = false; if (raw.ToUpper() == @"[POSITIONS]") { isPositions = true; } else if (raw.ToUpper() == @"[AIRSPACE]") { isAirspace = true; } } else if (isPositions) { Controller.Add(live.Split(':')); } else if (isAirspace) { if (raw.StartsWith("CIRCLE_SECTORLINE:")) { isPolyLine = false; isSector = false; SectorLine.list.Add(new CircleLine(live.Split(':'))); } else if (raw.StartsWith("SECTORLINE:")) { isPolyLine = true; isSector = false; SectorLine.list.Add(new PolyLine(live.Split(':'))); } else if (raw.StartsWith("SECTOR:")) { isPolyLine = false; isSector = true; deferred = new List <PolyLine>(); if (Controller.listSorted == null) { Controller.listSorted = Controller.Sort(Controller.list); } string[] liveparts = live.Split(':'); Sector.list.Add(new Sector(liveparts)); } //else if (isCircleLine) //{ //} else if (isPolyLine) { if (raw.StartsWith("COORD:")) { ((PolyLine)SectorLine.list.Last()).AddPoint(live.Split(':')); } } else if (isSector) { if (raw.StartsWith("OWNER:")) { string[] split = live.Split(':'); for (int i = 1; i < split.Length; i++) { string part = split[i]; if (part != "") { foreach (Controller ctl in Controller.Find(part)) { Sector.list.Last().owners.Add(ctl); } } } } else if (raw.StartsWith("ACTIVE:")) { string[] split = live.Split(':'); Airport apTemp = Airport.Find(split[1]); if (apTemp != null) { Sector.list.Last().runways.Add(Runway.Find(apTemp.ID, split[2])); } } else if (raw.StartsWith("BORDER:")) { string[] split = live.Split(':'); for (int i = 1; i < split.Length; i++) { string part = split[i]; SectorLine line = SectorLine.Find(part); Sector last = Sector.list.Last(); if (line != null && line is PolyLine) { PolyLine poly = new PolyLine((PolyLine)line); if (last.lines.Count == 0) { last.lines.Add(poly); } else { if (poly.points[0].SequenceEqual(((PolyLine)last.lines.Last()).points.Last())) { last.lines.Add(poly); } else if (poly.points.Last().SequenceEqual(((PolyLine)last.lines.Last()).points.Last())) { poly.points.Reverse(); last.lines.Add(poly); } else if (poly.points[0].SequenceEqual(((PolyLine)last.lines[0]).points[0])) { poly.points.Reverse(); last.lines.Insert(0, poly); } else if (poly.points.Last().SequenceEqual(((PolyLine)last.lines[0]).points[0])) { last.lines.Insert(0, poly); } else { deferred.Add(poly); } } bool isChanged = true; while (deferred.Count > 0 && isChanged) { isChanged = false; for (int j = deferred.Count - 1; j >= 0; j--) { PolyLine plyPly = deferred[j]; if (plyPly.points[0].SequenceEqual(((PolyLine)last.lines.Last()).points.Last())) { last.lines.Add(plyPly); deferred.RemoveAt(j); isChanged = true; } else if (plyPly.points.Last().SequenceEqual(((PolyLine)last.lines.Last()).points.Last())) { plyPly.points.Reverse(); last.lines.Add(plyPly); deferred.RemoveAt(j); isChanged = true; } else if (plyPly.points[0].SequenceEqual(((PolyLine)last.lines[0]).points[0])) { plyPly.points.Reverse(); last.lines.Insert(0, plyPly); deferred.RemoveAt(j); isChanged = true; } else if (plyPly.points.Last().SequenceEqual(((PolyLine)last.lines[0]).points[0])) { last.lines.Insert(0, plyPly); deferred.RemoveAt(j); isChanged = true; } } } } else if (line is CircleLine) { Sector.list.Last().lines.Add(line); } } } } } } } } }
static void ReadSCT(string _file) { //bool isAirport = false; bool isRunway = false; using (FileStream fs = File.Open(_file, FileMode.Open, FileAccess.Read, FileShare.Read)) using (BufferedStream bs = new BufferedStream(fs)) using (StreamReader sr = new StreamReader(bs)) { string raw; while ((raw = sr.ReadLine()) != null) { if (raw.Length != 0 && raw.First() != ';') { if (raw.First() == '[') { //isAirport = false; isRunway = false; //if (raw.ToUpper() == @"[AIRPORT]") //{ // isAirport = true; //} if (raw.ToUpper() == @"[RUNWAY]") { isRunway = true; } } //else if (isAirport) //{ // string live = raw.Split(';')[0]; // string[] split = live.Split(' '); // string sanitised = ""; // foreach (string part in split) // { // if (part != "") // { // sanitised += part + ","; // } // } // if (sanitised.Length > 0) // { // sanitised = sanitised.Substring(0, sanitised.Length - 2); // } // string[] result = sanitised.Split(','); //} else if (isRunway) { string live = raw.Split(';')[0]; live = live.Replace('\t', ' '); string[] split = live.Split(' '); string sanitised = ""; foreach (string part in split) { if (part != "") { sanitised += part + ","; } } if (sanitised.Length > 0) { sanitised = sanitised.Substring(0, sanitised.Length - 1); } string[] result = sanitised.Split(','); Airport location = Airport.Find(result[8]); if (location != null) { Runway.list.Add(new Runway(location.ID, result[0])); Runway.list.Add(new Runway(location.ID, result[1])); } } } } } }