static void LoadFile(string Path) { string[] data = System.IO.File.ReadAllLines(Path); for (int z = 0; z < data.Length; z++) { //search for ^130 string line = data[z]; if (Regex.IsMatch(line, "^130 ")) { //check difference Dictionary <string, double> DictToReturn = new Dictionary <string, double>(); if (line.StartsWith("130 ")) { //found start of def for (int y = (z + 1); y < data.Length; y++) { //search for final line string endLine = data[y]; if (endLine.StartsWith("113 ")) { //found end line string[] Airport = new List <string>(data).GetRange(z, (y - z)).ToArray(); List <double> Latitudes = new List <double>(); List <double> Longitudes = new List <double>(); Console.WriteLine("Reading " + Path); foreach (string obj in Airport) { if (obj.StartsWith("130 ")) { } else { try { Dictionary <string, string> dict = FileParser.ParseNode(obj); double lat = Convert.ToDouble(dict["Latitude"]); double lng = Convert.ToDouble(dict["Longitude"]); Latitudes.Add(lat); Longitudes.Add(lng); } catch (System.FormatException) { } } } double[] lats = Latitudes.ToArray(); double[] lngs = Longitudes.ToArray(); double HighestLat = lats.Max(); double HighestLng = lngs.Max(); double HighestDiffLat = 0.0; double HighestDiffLng = 0.0; for (int ii = 0; ii < lats.Length; ii++) { //try max - ii double calc = HighestLat - lats[ii]; if (calc > HighestDiffLat) { //larger value - assign HighestDiffLat = calc; } } for (int ii = 0; ii < lngs.Length; ii++) { //try max - ii double calc = HighestLng - lngs[ii]; if (calc > HighestDiffLng) { //larger value - assign HighestDiffLng = calc; } } try { DictToReturn.Add("Lng", HighestDiffLng); DictToReturn.Add("Lat", HighestDiffLat); Dictionary <string, double> DiffDict = DictToReturn; double LatDiff = Convert.ToDouble(DiffDict["Lat"]); double LngDiff = Convert.ToDouble(DiffDict["Lng"]); Console.WriteLine(LatDiff + LngDiff); if ((LatDiff > 0.05) || (LngDiff > 0.05)) { Console.WriteLine("Largest differences for airfield at path: " + Path + '\n'); } } catch (System.ArgumentException) { } } } } } } }
static void GetAllCoordinates(string[] Lines, string Path) { List <PointF> PointsEnum = new List <PointF>(); Dictionary <string, float> CoordinateDictionary = new Dictionary <string, float>(); double RunwayHeadingDouble = new double(); //loop through each line and return various coordinates for (int i = 0; i < Lines.Length; i++) { string line = Lines[i]; Console.WriteLine("Line " + i + ": " + line); //print line contents Dictionary <string, string> CurrentDictionary = FileParser.ParseContent(line, false); if (!(CurrentDictionary == null)) { if (CurrentDictionary["Format"] == "100") { //runway - has 2 points try { Dictionary <string, string> CurrentDictionaryNew = FileParser.ParseContent(line, true); float Latitude1 = float.Parse(CurrentDictionaryNew["Latitude1"], CultureInfo.InvariantCulture.NumberFormat); float Longitude1 = float.Parse(CurrentDictionaryNew["Longitude1"], CultureInfo.InvariantCulture.NumberFormat); PointF p1 = new PointF(); p1.X = Latitude1; p1.Y = Longitude1; PointsEnum.Add(p1); float Latitude2 = float.Parse(CurrentDictionaryNew["Latitude2"], CultureInfo.InvariantCulture.NumberFormat); float Longitude2 = float.Parse(CurrentDictionaryNew["Longitude2"], CultureInfo.InvariantCulture.NumberFormat); PointF p2 = new PointF(); p2.X = Latitude2; p2.Y = Longitude2; PointsEnum.Add(p2); RunwayHeadingDouble = Convert.ToDouble(CurrentDictionaryNew["RunwayNumber"]); Console.WriteLine("Added 2 new points"); } catch (System.FormatException) { /*//exception - uses Older format * Console.WriteLine("Older format"); * * * float Latitude1 = float.Parse(CurrentDictionary["Latitude1"], CultureInfo.InvariantCulture.NumberFormat); * float Longitude1 = float.Parse(CurrentDictionary["Longitude1"], CultureInfo.InvariantCulture.NumberFormat); * * PointF p1 = new PointF(); * p1.X = Latitude1; * p1.Y = Longitude1; * * PointsEnum.Add(p1); * * float Latitude2 = float.Parse(CurrentDictionary["Latitude2"], CultureInfo.InvariantCulture.NumberFormat); * float Longitude2 = float.Parse(CurrentDictionary["Longitude2"], CultureInfo.InvariantCulture.NumberFormat); * * PointF p2 = new PointF(); * p2.X = Latitude2; * p2.Y = Longitude2; * * PointsEnum.Add(p2); */ } } else { //not rwy - only 1 point float Latitude = float.Parse(CurrentDictionary["Latitude"], CultureInfo.InvariantCulture.NumberFormat); float Longitude = float.Parse(CurrentDictionary["Longitude"], CultureInfo.InvariantCulture.NumberFormat); PointF p = new PointF(); p.X = Latitude; p.Y = Longitude; PointsEnum.Add(p); } } if (line == "99") { //is a 99 - footer. delete and read outside of if Lines[i] = ""; } else if (Regex.IsMatch(line, "^1000 Ge")) { //is a header, append /AB (automatic boundary) Lines[i] = (Lines[i] + "/AB"); } if (i == (Lines.Length - 1)) { //check number of points - if there are 2, then it's a single runway apt with no edits made. Interpolate an area 5m around the airfield and add points if (PointsEnum.Count <= 2) { //commented out - creates a massive triangle /*float RunwayHeadingFloat = ConvertToFloat(RunwayHeadingDouble * 100); * List<PointF> ReturnedList = CreateBoundingBox.CalculateBoundingBox(PointsEnum, RunwayHeadingFloat); * * for (int x = 0; x < ReturnedList.Count; x++) * { * PointsEnum.Add(ReturnedList[x]); * * }*/ } //finished for loop. Create Convex Hull PointF[] ReturnedPoints = CreateConvexHull.ComputeConvexHull(PointsEnum); Console.WriteLine("Returned convex hull: " + ReturnedPoints); for (int y = 0; y < ReturnedPoints.Length; y++) { PointF point = ReturnedPoints[y]; Console.WriteLine("Point at coordinates: " + point.X + ", " + point.Y); } WriteToFile(Lines, ReturnedPoints, Path); } } }