public void _parse(string filename) { _segments = new List <Trkseg>(); var doc = XDocument.Load(filename); var gpx = XNamespace.Get("http://www.topografix.com/GPX/1/1"); var tracks = doc.Descendants(gpx + "trk"); foreach (var trk in tracks) { var segments = trk.Descendants(gpx + "trkseg"); foreach (var seg in segments) { var points = seg.Descendants(gpx + "trkpt"); var segObj = new Trkseg(); segObj.List = new List <Trkpt>(); foreach (var p in points) { string latS = p.Attribute("lat").Value; string lonS = p.Attribute("lon").Value; var latD = double.Parse(latS, CultureInfo.InvariantCulture); var lonD = double.Parse(lonS, CultureInfo.InvariantCulture); var pObj = new Trkpt(latD, lonD); segObj.List.Add(pObj); } _segments.Add(segObj); } } }
public Trkseg(XmlNode node) { foreach (XmlNode childNode in node) { switch (childNode.Name) { case "trkpt": var trackPoint = new Trkpt(childNode); TrackPoints.Add(trackPoint); break; default: throw new Exception("Unhandled for Child Object: " + childNode.Name); } } }
public static List <Trkpt> ConvertTrkptModelListToTrkptList(List <TrkptModel> trkptModels) { var trkptList = new List <Trkpt>(); foreach (var trkptModel in trkptModels) { var trkpt = new Trkpt { Lat = trkptModel.Latitude.ToString(CultureInfo.InvariantCulture), Lon = trkptModel.Longitude.ToString(CultureInfo.InvariantCulture), Time = trkptModel.Time.ToString() }; trkptList.Add(trkpt); } return(trkptList); }