/// <summary> /// Writes one file from the given sub table /// </summary> /// <param name="sw">Stream to write to</param> /// <param name="subTable">The subtable to write out</param> private static void WriteFile(StreamWriter sw, apTable subTable) { foreach (var rec in subTable) { sw.WriteLine(rec.Value.AsCsv( )); } }
/// <summary> /// Write one geojson file from the supplied table /// </summary> /// <param name="sw">An open streamwriter</param> /// <param name="subTable">The apTable to write out</param> private static void WriteFile(StreamWriter sw, apTable subTable) { int i = 1; // have to count to avoid the last comma ??!! foreach (var rec in subTable) { sw.WriteLine(rec.Value.AsGeoJson( ) + ((i++ < subTable.Count) ? "," : "")); // adds commas but not for the last one } }
/// <summary> /// Adds a table to this table (omitting key dupes) /// </summary> /// <param name="subtable">A table to add to this table</param> public string AddSubtable(apTable subtable) { string ret = ""; foreach (var rec in subtable) { try { ret += this.Add(rec.Value); } catch { } } return(ret); }
/// <summary> /// Exec INSERT statements for an airport subtable /// </summary> /// <param name="sqConnection">The db connection</param> /// <param name="subTable">The subtable to dump</param> /// <returns>The result string, either empty or error</returns> private static string WriteFile(SQLiteConnection sqConnection, apTable subTable) { using (SQLiteCommand sqlite_cmd = sqConnection.CreateCommand( )) { foreach (var rec in subTable) { try { sqlite_cmd.CommandText = "INSERT INTO airports (apt_icao_code, apt_iata_code, iso_country, iso_region, lat, lon, elevation, apt_type, apt_name)" + $" VALUES ('{rec.Value.apt_icao_code}','{rec.Value.apt_iata_code}','{rec.Value.iso_country}'" + $",'{rec.Value.iso_region}','{rec.Value.lat}','{rec.Value.lon}','{rec.Value.elevation}'" + $",'{rec.Value.apt_type}','{rec.Value.apt_name}');"; sqlite_cmd.ExecuteNonQuery( ); } catch (SQLiteException sqex) { return($"ERROR - writing route: {sqex.Message}\n"); } } } return(""); }
/// <summary> /// Returns a subtable with items that match the given criteria /// </summary> /// <param name="rangeLimitNm">Range Limit in nm</param> /// <param name="Lat">Center Lat (decimal)</param> /// <param name="Lon">Center Lon (decimal)</param> /// <param name="aptTypes">Type of airport items to include</param> /// <returns>A table with selected records</returns> public apTable GetSubtable(double rangeLimitNm, double Lat, double Lon, AptTypes[] aptTypes = null) { if (aptTypes == null) { aptTypes = new AptTypes[] { AptTypes.All } } ; var nT = new apTable( ); var myLoc = new LatLon(Lat, Lon); foreach (var rec in this) { var dist = myLoc.DistanceTo(new LatLon(double.Parse(rec.Value.lat), double.Parse(rec.Value.lon)), ConvConsts.EarthRadiusNm); if ((dist <= rangeLimitNm) && (rec.Value.IsTypeOf(aptTypes))) { nT.Add(rec.Value); } } return(nT); } }
/// <summary> /// cTor: init the database /// </summary> public apDatabase() { m_db = new apTable( ); }
/// <summary> /// Create an ICAO table from the given table /// </summary> /// <param name="table">The source to fill from</param> public apTable(apTable table) { this.AddSubtable(table); }