/// <summary> /// Writes a geojson file from the given database into the open stream /// Selects items to write from the given selection criteria /// </summary> /// <param name="db">The navDatabase to dump</param> /// <param name="geojOutStream">The open outstream</param> /// <param name="rangeLimitNm">Range Limit in nm</param> /// <param name="Lat">Center Lat (decimal)</param> /// <param name="Lon">Center Lon (decimal)</param> /// <param name="navTypes">Type of nav items to include</param> /// <returns>True ??!!</returns> public static bool WriteGeoJson(navDatabase db, Stream geojOutStream, double rangeLimitNm = -1.0, double Lat = 0, double Lon = 0, NavTypes[] navTypes = null) { /* * { * "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)) { sw.WriteLine(head); if (rangeLimitNm > 0) { WriteFile(sw, db.GetSubtable(rangeLimitNm, Lat, Lon, navTypes)); } else { WriteFile(sw, db.GetSubtable( )); } sw.WriteLine(foot); } return(true); }
/// <summary> /// Reads all data from the given file /// </summary> /// <param name="db">The navDatabase to fill from the file</param> /// <param name="csvFile">The file to read</param> /// <returns>The result string, either empty or error</returns> public static string ReadDb(ref navDatabase db, string csvFile) { if (!File.Exists(csvFile)) { return($"File does not exist\n"); } return(ReadDbFile(ref db, csvFile)); }
/// <summary> /// Reads one db file /// </summary> /// <param name="db">The navDatabase to fill from the file</param> /// <param name="fName">The qualified filename</param> /// <returns>The result string, either empty or error</returns> private static string ReadDbFile(ref navDatabase 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( ); while (!sr.EndOfStream) { var rec = FromNative(buffer); if (rec.IsValid) { ret += db.Add(rec); // collect adding information } buffer = sr.ReadLine( ); } // } return(ret); }