/// <summary> /// Reads one file to fill the db /// </summary> /// <param name="db">The awyDatabase to fill</param> /// <param name="fName">The qualified filename</param> /// <returns>The result string, either empty or error</returns> private static string ReadDbFile(ref awyDatabase db, string fName) { var icaoPre = Path.GetFileNameWithoutExtension(fName); string ret = ""; using (var sr = new StreamReader(fName)) { string buffer = sr.ReadLine( ); // header line buffer = sr.ReadLine( ); // header line 2 buffer = sr.ReadLine( ); while (!sr.EndOfStream) { if (buffer.StartsWith("99")) { break; } var rec = FromNative(buffer); if (rec != null && rec.IsValid) { ret += db.Add(rec); // collect adding information } buffer = sr.ReadLine( ); } // } return(ret); }
/// <summary> /// Reads the XPlane 11 earth_awy.dat file and populates the supplied database /// </summary> /// <param name="db">The awyDatabase to fill</param> /// <param name="fName">The file to read</param> /// <returns>The result string, either empty or error</returns> public static string ReadDb(ref awyDatabase db, string fName) { if (!File.Exists(fName)) { return($"File does not exist\n"); } return(ReadDbFile(ref db, fName)); }
private HashSet <string> m_trackedMarkers = new HashSet <string>( ); // track written Markers /// <summary> /// Writes a GeoJson from the database /// </summary> /// <param name="db">The database</param> /// <param name="geojFile">the filename to write to</param> /// <returns>True ??!!</returns> public bool WriteGeoJson(awyDatabase db, navDatabase ndb, Stream geojOutStream, string layer, double rangeLimitNm = -1.0, double Lat = 0, double Lon = 0) { /* * { * "type": "FeatureCollection", * "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } }, * "features": [ * entry, entry * ] * } */ string head = $"{{\n\"type\": \"FeatureCollection\",\n" + $"\"crs\": {{ \"type\": \"name\", \"properties\": {{ \"name\": \"urn:ogc:def:crs:OGC:1.3:CRS84\" }} }}," + $"\"features\": ["; string foot = $"]\n}}"; using (var sw = new StreamWriter(geojOutStream, Encoding.UTF8)) { bool doComma = false; // pesty last comma avoidance... sw.WriteLine(head); // Navs and Fixes in range var NAVTAB = ndb.GetSubtable(rangeLimitNm, Lat, Lon); // for each item in NDB get the airway(s) that is using it foreach (var rec in NAVTAB) { var AWYTAB = db.GetSubtable(rec.Key); // for each item then find it's counterpart and write an airway segment foreach (var awRec in AWYTAB) { if (awRec.Value.layer == layer) { // expected layer (hi or lo) if (rec.Key == awRec.Value.startID) { var endNav = ndb.GetTable( )[awRec.Value.endID]; if (!m_trackedMarkers.Contains(rec.Value.ident)) { m_trackedMarkers.Add(rec.Value.ident); } if (!m_trackedMarkers.Contains(endNav.ident)) { m_trackedMarkers.Add(endNav.ident); } sw.WriteLine((doComma ? "," : "") + awRec.Value.AsGeoJson(rec.Value.lat, rec.Value.lon, endNav.lat, endNav.lon)); doComma = true; // after the first line prepend records with comma } else if (rec.Key == awRec.Value.endID) { var startNav = ndb.GetTable( )[awRec.Value.endID]; if (!m_trackedMarkers.Contains(startNav.ident)) { m_trackedMarkers.Add(startNav.ident); } if (!m_trackedMarkers.Contains(rec.Value.ident)) { m_trackedMarkers.Add(rec.Value.ident); } sw.WriteLine((doComma ? "," : "") + awRec.Value.AsGeoJson(startNav.lat, startNav.lon, rec.Value.lat, rec.Value.lon)); doComma = true; // after the first line prepend records with comma } else { ; //ERROR - DEBUG BREAK } } } } sw.WriteLine(foot); } return(true); }