コード例 #1
0
 internal void AddWaypoint(NamedGpsLogEntry e)
 {
     this.waypoints.Add(e);
 }
コード例 #2
0
        public static GpsLog FromNmeaGprmcFile(string filename)
        {
            GpsLog log = new GpsLog();

            FileStream fs          = File.OpenRead(filename);
            TextReader tr          = new StreamReader(fs);
            String     inputString = tr.ReadToEnd();

            tr.Close();

            Regex regexGprmc = new Regex(REGEX_NMEA_GPRMC);
            Match match      = regexGprmc.Match(inputString);

            while (match.Success)
            {
                try
                {
                    GpsLogEntry e = new GpsLogEntry();

                    e.Latitude = Convert(match.Groups["lat"].Value);
                    if (match.Groups["latdir"].Value == "S")
                    {
                        e.Latitude *= -1;
                    }

                    e.Longitude = Convert(match.Groups["lon"].Value);
                    if (match.Groups["londir"].Value == "W")
                    {
                        e.Longitude *= -1;
                    }

                    string time = match.Groups["time"].Value;
                    int    h    = int.Parse(time.Substring(0, 2));
                    int    min  = int.Parse(time.Substring(2, 2));
                    int    s    = int.Parse(time.Substring(4, 2));

                    string date = match.Groups["date"].Value;
                    int    d    = int.Parse(date.Substring(0, 2));
                    int    m    = int.Parse(date.Substring(2, 2));
                    int    y    = int.Parse(date.Substring(4, 2));
                    if (y > 80)
                    {
                        y += 1900;
                    }
                    else
                    {
                        y += 2000;
                    }

                    e.Time = new DateTime(y, m, d, h, min, s); // TODO  ms?

                    log.AddEntry(e);
                }
                catch { }

                match = match.NextMatch();
            }

            Regex regexGpwpl = new Regex(REGEX_NMEA_GPWPL);

            match = regexGpwpl.Match(inputString);
            while (match.Success)
            {
                try
                {
                    NamedGpsLogEntry e = new NamedGpsLogEntry();

                    e.Latitude = Convert(match.Groups["lat"].Value);
                    if (match.Groups["latdir"].Value == "S")
                    {
                        e.Latitude *= -1;
                    }

                    e.Longitude = Convert(match.Groups["lon"].Value);
                    if (match.Groups["londir"].Value == "W")
                    {
                        e.Longitude *= -1;
                    }

                    e.Name = match.Groups["name"].Value.Trim();

                    log.Waypoints.Add(e);
                }
                catch {}

                match = match.NextMatch();
            }

            return(log);
        }