public List<airport> readAirports(String airportFilename) { /////////////////////////////////////////////////////////////////////////////////////// //read the List of airports from a file /////////////////////////////////////////////////////////////////////////////////////// List<airport> apts = new List<airport>(); StreamReader sr = new StreamReader(airportFilename); while (!sr.EndOfStream) { String []values = sr.ReadLine().Split(new char[]{':'}); airport apt = new airport(); apt.name = values[0]; apt.City = values[1]; apt.ICAO_designator = values[2]; try { apt.lat = Convert.ToDouble(values[3]); apt.lon = Convert.ToDouble(values[4]); apt.altitude = Convert.ToDouble(values[5]); apt.easting = Convert.ToDouble(values[6]); apt.northing = Convert.ToDouble(values[7]); apt.distanceToPolyCenterMi = Convert.ToDouble(values[8]); } catch { System.Windows.Forms.MessageBox.Show("could not convert airport info"); } apts.Add(apt); } return apts; }
public List<airport> airportsWitin50kmRadius(double latDeg, double lonDeg, double latDegPT, double lonDegPT) { /////////////////////////////////////////////////////////////////////////////////////////////// //this procedure uses the Places API to get all airports within 50km of a lat/lon point //this must be called multiple times to get airports near the client polygon /////////////////////////////////////////////////////////////////////////////////////////////// List<airport> airports = new List<airport>(); //returned list of airports airport apt = new airport(); apt.City = "unknown"; apt.distanceToPolyCenterMi = 0.0; apt.ICAO_designator = "unknown"; apt.name = "unknown"; apt.lat = 0.0; apt.lon = 0.0; apt.altitude = 0.0; double Northing = 0.0, Easting = 0.0; utm.LLtoUTM(latDegPT * Deg2Rad, lonDegPT * Deg2Rad, ref Northing, ref Easting, ref UTMZone, false); String ss = uriPreamble + latDeg.ToString() + "," + lonDeg.ToString() + uriEndString; //below commented code gets the Places response in a local xml so you can view it. //WebClient ww = new WebClient(); //Uri uri = new Uri(ss); //String downloadedData = ww.DownloadString(uri); //perform the web download -- blocking call //the below call reads the URL response directly into a xml text reader for processing XmlTextReader textReader = new XmlTextReader(ss); //assume the Google Places API response has name, vicinity (city), lat, lng in that order. while (textReader.Read()) { textReader.MoveToElement(); String m = textReader.Value; if (textReader.IsStartElement() && textReader.Name == "name") //first { textReader.Read(); //must replace any "&" else kml will fail apt.name = ((String)textReader.Value).Replace(Convert.ToChar("&"), Convert.ToChar("A")); //Constants.Log(" airportName " + apt.name); } else if (textReader.IsStartElement() && textReader.Name == "vicinity") //second { textReader.Read(); apt.City = ((String)textReader.Value).Replace(Convert.ToChar("&"), Convert.ToChar("A")); } else if (textReader.IsStartElement() && textReader.Name == "lat") //third { textReader.Read(); apt.lat = Convert.ToDouble(textReader.Value); } else if (textReader.IsStartElement() && textReader.Name == "lng") //last -- when here have a complete set for one airport { textReader.Read(); apt.lon = Convert.ToDouble(textReader.Value); //have filled in name, City, lat above //the airport structure also has distance from the poly center --- compute this below double aptNorthing = 0.0, aptEasting = 0.0; //get the UTM for this airport location utm.LLtoUTM(apt.lat * Deg2Rad, apt.lon * Deg2Rad, ref aptNorthing, ref aptEasting, ref UTMZone, true); //compute the distance from mean poly center computed eleswhere double dist2 = (Northing - aptNorthing) * (Northing - aptNorthing) + (Easting - aptEasting) * (Easting - aptEasting); double distMeters = Math.Sqrt(dist2); //convert to miles apt.distanceToPolyCenterMi = distMeters / .3048 / 5280.0; apt.northing = aptNorthing; apt.easting = aptEasting; //add this airport to the list to return airports.Add(apt); } } return airports; }