Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. public List<string> LoadGPXTracks(string sFile)
  2. {
  3. XDocument gpxDoc = GetGpxDoc(sFile);
  4. XNamespace gpx = GetGpxNameSpace();
  5. var tracks = from track in gpxDoc.Descendants(gpx + "trk")
  6. select new
  7. {
  8. Name = track.Element(gpx + "name") != null ?
  9. track.Element(gpx + "name").Value : null,
  10. Segs = (
  11. from trackpoint in track.Descendants(gpx + "trkpt")
  12. select new
  13. {
  14. Latitude = trackpoint.Attribute("lat").Value,
  15. Longitude = trackpoint.Attribute("lon").Value,
  16. Elevation = trackpoint.Element(gpx + "ele") != null ?
  17. trackpoint.Element(gpx + "ele").Value : null,
  18. Time = trackpoint.Element(gpx + "time") != null ?
  19. trackpoint.Element(gpx + "time").Value : null
  20. }
  21. )
  22. };
  23.  
  24. // StringBuilder sb = new StringBuilder();
  25. List<string> stringList = new List<string>();
  26.  
  27. foreach (var trk in tracks)
  28. {
  29. stringList.Add(trk);
  30. // Populate track data objects.
  31. foreach (var trkSeg in trk.Segs)
  32. {
  33. // Populate detailed track segments
  34. // in the object model here.
  35. /*sb.Append(
  36. string.Format("Track:{0} - Latitude:{1} Longitude:{2} " +
  37. "Elevation:{3} Date:{4}\n",
  38. trk.Name, trkSeg.Latitude,
  39. trkSeg.Longitude, trkSeg.Elevation,
  40. trkSeg.Time));
  41. */
  42.  
  43. /* stringList.Add(trkSeg.Latitude);
  44. stringList.Add(trkSeg.Longitude);
  45. stringList.Add(trkSeg.Elevation);
  46. */
  47. }
  48. }
  49.  
  50. return stringList;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement