Exemple #1
0
		/// <summary>
		/// Create a new Track by loading from a GPX file.
		/// </summary>
		/// <param name="filespec">The filespec of a GPX file.</param>
		public Track(string gpxfile)
		{
			Points = new List<TrackPoint>();
			XmlDocument x = new XmlDocument();
			x.Load(gpxfile);
			if(x.DocumentElement.Name != "gpx")
				throw new ApplicationException("Document element should be 'gpx'");
			string ns = "http://www.topografix.com/GPX/1/0";
			string ver = x.DocumentElement.GetAttribute("version");
			if(ver != null && ver == "1.1")
				ns = "http://www.topografix.com/GPX/1/1";
			XmlNamespaceManager nsmgr = new XmlNamespaceManager(x.NameTable);
			nsmgr.AddNamespace("gpx", ns);
			if(x.GetElementsByTagName("name").Count > 0)
				Name = x.GetElementsByTagName("name") [0].InnerText;
			else
				Name = Path.GetFileNameWithoutExtension(gpxfile);
			foreach(XmlNode point in x.SelectNodes("//gpx:trkpt",nsmgr)) {
				TrackPoint p = new TrackPoint();
				p.Lat = XmlConvert.ToDouble(point.SelectSingleNode("@lat").Value);
				p.Lon = XmlConvert.ToDouble(point.SelectSingleNode("@lon").Value);
				p.Elevation = XmlConvert.ToDouble(point.SelectSingleNode("gpx:ele", nsmgr).InnerText);
				p.Time = DateTime.Parse(point.SelectSingleNode("gpx:time", nsmgr).InnerText).ToUniversalTime();
				Points.Add(p);
			}
		}
Exemple #2
0
		public object Clone()
		{
			TrackPoint copy = new TrackPoint();
			copy.Lat = Lat;
			copy.Lon = Lon;
			copy.Elevation = Elevation;
			copy.Time = Time;
			return copy;
		}