Example #1
0
        public static List <NOAAStation> GetNOAAStationsList()
        {
            List <NOAAStation> stationsList = new List <NOAAStation>();

            string stations = GetNOAAStationString(NOAA_STATION_SOURCE_URL);

            //credit: https://stackoverflow.com/a/1508217
            var lines = Regex.Split(stations, "\r\n|\r|\n");

            foreach (string line in lines)
            {
                if (line.Length == 83)
                {
                    NOAAStation sta = NOAAStation.ParseStationLine(line);
                    if (sta.ICAO.Length == 4)
                    {
                        if (!stationsList.Contains(sta))
                        {
                            stationsList.Add(sta);
                        }
                        else
                        {
                            Console.WriteLine($"check this value: {sta}");
                        }
                    }
                }
            }

            return(stationsList);
        }
Example #2
0
        public static NOAAStation ParseStationLine(string line)
        {
            string output = "";
            string cd     = line.Substring(0, 3).Trim();

            output += $"cd:{cd}|";
            string station = line.Substring(3, 17).Trim();

            output += $"station:{station}|";
            string icao = line.Substring(20, 6).Trim();

            output += $"icao:{icao}|";
            string iata = line.Substring(24, 6).Trim();

            output += $"iata:{iata}|";
            string synop = line.Substring(32, 7).Trim();

            output += $"synop:{synop}|";
            string lat = line.Substring(38, 8).Trim();

            output += $"lat:{lat}|";
            string lon = line.Substring(46, 8).Trim();

            output += $"lon:{lon}|";
            string elevation = line.Substring(54, 5).Trim();

            output += $"elevation:{elevation}|";

            // Console.WriteLine($"{output}");
            // if(icao.Length == 0){
            //     icao = iata;
            // }

            NOAAStation sta = new NOAAStation {
                StateAbbreviation = cd,
                StationName       = station,
                ICAO           = icao,
                IATA           = iata,
                SynopticNumber = synop,
                Latitude       = lat,
                Longitude      = lon,
                Elevation      = elevation,
            };

            return(sta);
        }