public void SaveToMap(string content, _LonLat coords) { // Get coords by area _LonLat byArea = RoundCoordsByArea(coords); // Align to zero double lon = byArea.Longitude + 180; double lat = byArea.Latitude + 90; // Round it int lonInt = (int)Math.Round(lon); int latInt = (int)Math.Round(lat); // Save to map if (WorldMap[lonInt][latInt] == null || WorldMap[lonInt][latInt].Length < content.Length) { WorldMap[lonInt][latInt] = content; } }
private void Clean(DataContainer dataContainer, _InternalData internalData) { string prefix = "3/5 Cleaning..."; Utils.DrawMessage(prefix, Utils.CreateProgressBar(Utils.ProgressBarLength, 0), ConsoleColor.Gray); // Parsing try { // Only if needed if (Reload || !File.Exists(SerializedFile)) { // Get station count int stations = File.ReadAllLines(Path.Combine(Folder, "Stations.csv")).Length; // Count when we update progress bar int drawEvery = Utils.PercentIntervalByLength(stations); // Get minimal date DateTime minimalDate = dataContainer.GetMinimalDate(); int minimalDateInt = int.Parse(minimalDate.ToString("yyyyMM")); // Clean data int currentCount = 0; Compression.DecompressTgzStream(Path.Combine(Folder, "Weather.tar.gz"), (file, content) => { // Examine only data files if (Path.GetExtension(file) != ".dly") { return; } // Split to lines List <string> lines = content.Split(new char[] { '\n' }).ToList(); // Remove blank lines lines.RemoveAll(x => String.IsNullOrWhiteSpace(x)); // Remove lines of data we dont want lines.RemoveAll(x => !internalData.Wanted.Contains(x.Substring(17, 4))); // Remove all too old data lines.RemoveAll(x => int.Parse(x.Substring(11, 6)) < minimalDateInt); // Check if source is long enough (in years) if (lines.Where(x => int.Parse(x.Substring(11, 4)) >= DateTime.Today.Year - 1).Count() == 0) { return; } // Remove all info if there is not enough of data (many unknown data) foreach (string w in internalData.Wanted) { // Select only lines of current info string[] ofInfo = lines.Where(x => x.Substring(17, 4) == w).ToArray(); // Check ratio of known and unknown values int unknownValues = ofInfo.Select(x => Regex.Matches(x, "-9999").Count).Sum(); int knownValues = ofInfo.Length * 31 - unknownValues; // If not much, remove this lines if (unknownValues / (double)(knownValues + unknownValues) > 0.1) { lines.RemoveAll(x => x.Substring(17, 4) == w); } } // No data left if (lines.Count < 10) { return; } // Get station coords _LonLat coords = internalData.StationPlaces[Path.GetFileNameWithoutExtension(file)]; // Place to world map internalData.SaveToMap(String.Join("\n", lines), coords); if (++currentCount % drawEvery == 0) { Utils.DrawMessage(prefix, Utils.CreateProgressBar(Utils.ProgressBarLength, (double)currentCount / stations * 100.0), ConsoleColor.Gray); } }); } } catch (Exception ex) { Console.WriteLine(); Utils.DrawMessage("", ex.Message, ConsoleColor.Red); Console.WriteLine(); System.Environment.Exit(1); } Utils.DrawMessage(prefix, Utils.CreateProgressBar(Utils.ProgressBarLength, 100), ConsoleColor.Green); Console.WriteLine(); }
private _LonLat RoundCoordsByArea(_LonLat coords) { // Default resoltuion int roundLonTo = 180; int roundLatTo = 90; // North America //if (coords.Longitude > -120 && coords.Longitude < -60 && // coords.Latitude > 10 && coords.Latitude < 70) //{ // roundLonTo = 10; // roundLatTo = 5; //} //// North east America if (coords.Longitude > -90 && coords.Longitude < -60 && coords.Latitude > 30 && coords.Latitude < 55) { roundLonTo = 5; roundLatTo = 3; } //// Europe //if (coords.Longitude > -15 && coords.Longitude < 20 && // coords.Latitude > 37 && coords.Latitude < 55) //{ // roundLonTo = 15; // roundLatTo = 9; //} //// Russia / Asia //else if (coords.Longitude > 25 && coords.Longitude < 135 && // coords.Latitude > 10 && coords.Latitude < 70) //{ // roundLonTo = 50; // roundLatTo = 30; //} //// Japan //else if (coords.Longitude > 130 && coords.Longitude < 148 && // coords.Latitude > 30 && coords.Latitude < 40) //{ // roundLonTo = 9; // roundLatTo = 5; //} //// Australia //else if (coords.Longitude > 110 && coords.Longitude < 150 && // coords.Latitude > -40 && coords.Latitude < -10) //{ // roundLonTo = 20; // roundLatTo = 15; //} //// Africa //else if (coords.Longitude > -15 && coords.Longitude < 45 && // coords.Latitude > -30 && coords.Latitude < 30) //{ // roundLonTo = 30; // roundLatTo = 30; //} //// North west America //else if (coords.Longitude > -90 && coords.Longitude < -60 && // coords.Latitude > 30 && coords.Latitude < 55) //{ // roundLonTo = 15; // roundLatTo = 15; //} //// North east America //else if (coords.Longitude > -120 && coords.Longitude < -90 && // coords.Latitude > 10 && coords.Latitude < 70) //{ // roundLonTo = 15; // roundLatTo = 30; //} //// South America //else if (coords.Longitude > -75 && coords.Longitude < -45 && // coords.Latitude > -50 && coords.Latitude < 10) //{ // roundLonTo = 15; // roundLatTo = 20; //} //// Antartida //else if (coords.Longitude > -180 && coords.Longitude < 180 && // coords.Latitude > -90 && coords.Latitude < -70) //{ // roundLonTo = 180; // roundLatTo = 20; //} return(new _LonLat(LocalUtils.Round(coords.Longitude, roundLonTo), LocalUtils.Round(coords.Latitude, roundLatTo))); }