Beispiel #1
0
 private void AddWaypoint(Double longitude, Double latitude, Double elevation, DateTime dt)
 {
     Waypoint wpt = new Waypoint(longitude, latitude, elevation, dt);
     try
     {
         WaypointList.Add(wpt);
     }
     catch (Exception ex)
     {
         string s = ex.ToString();
         DialogResult dlg = MessageBox.Show("Nasty error adding waypoint" + ex.Message,
             "Error adding track/waypoint",
             MessageBoxButtons.OK,
             MessageBoxIcon.Information);
     }
 }
Beispiel #2
0
        public void LoadTrack_1(string file)
        {
            XmlTextReader reader = new XmlTextReader(file);
            Waypoint wpt = new Waypoint(0L, 0L);
            Double longitude = 0L;
            Double latitude = 0L;
            Double lat_degrees = 0D;
            Double long_degrees = 0D;
            Double elevation = 0L;
            DateTime dt = new DateTime();
            String lastNodeval = "";

            int wps = 0;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element: // The node is an element.

                        switch (reader.Name)
                        {
                            case "trkpt":
                                lat_degrees = double.Parse(reader.GetAttribute("lat"));
                                long_degrees = double.Parse(reader.GetAttribute("lon"));
                                longitude = Earth.ConvertDegreesToRadians(long_degrees);
                                latitude = Earth.ConvertDegreesToRadians(lat_degrees);
                                break;
                            default:
                                break;
                        }
                        break;
                    case XmlNodeType.Text: //Display the text in each element.
                        Console.WriteLine(reader.Value);
                        lastNodeval = reader.Value;
                        break;
                    case XmlNodeType.EndElement: //Display the end of the element.
                        switch (reader.Name)
                        {
                            case "ele": elevation = double.Parse(lastNodeval);
                                break;
                            case "time":
                                Regex r = new Regex(@"(?<YEAR>\d{4})-(?<MONTH>\d{2})-(?<DAY>\d{2})T(?<HOUR>\d{2}):(?<MIN>\d{2}):(?<SEC>\d{2})Z");
                                Match m1 = r.Match(lastNodeval);

                                //Output match information if a match was found
                                if (m1.Success)
                                {

                                    int year = Int32.Parse(m1.Groups["YEAR"].Value);
                                    int month = Int32.Parse(m1.Groups["MONTH"].Value);
                                    int day = Int32.Parse(m1.Groups["DAY"].Value);
                                    int hour = Int32.Parse(m1.Groups["HOUR"].Value);
                                    int min = Int32.Parse(m1.Groups["MIN"].Value);
                                    int sec = Int32.Parse(m1.Groups["SEC"].Value);

                                    dt = new DateTime(year, month, day, hour, min, sec);
                                    Console.WriteLine("Date: " + dt.ToLongDateString() +
                                        ", Time: " + dt.ToLongTimeString());
                                }
                                break;
                            case "trkpt":
                                Console.Write("trkpt:" +
                                    " Elevation: " + elevation +
                                    " Latitude: " + latitude +
                                    " Longitude: " + longitude +
                                    "\n");
                                AddWaypoint(longitude, latitude, elevation, dt);
                                wps++;
                                break;
                            default:
                                break;
                        }
                        break;
                }
            }
        }