private void OpenGpxRibbonButton_Click(object sender, RoutedEventArgs e) { Gpx gpxFile = new Gpx(); string gpxFilename = OpenGpxDialog(); if (gpxFilename == null) { return; } XElement gpxXe = XElement.Load(gpxFilename); var trkList = gpxXe.Elements().Where(el => el.Name.LocalName == "trk").ToList(); foreach (var trkXe in trkList) { Track track = new Track(); foreach (var trksegXe in trkXe.Elements().Where(el => el.Name.LocalName == "trkseg").ToList()) { TrackSegment segment = new TrackSegment(); foreach (var trkptXe in trksegXe.Elements().Where(el => el.Name.LocalName == "trkpt").ToList()) { double latValue = double.Parse(trkptXe.Attribute("lat").Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture); double longValue = double.Parse(trkptXe.Attribute("lon").Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture); DateTime time = DateTime.Parse(trkptXe.Elements().First(el => el.Name.LocalName == "time").Value); segment.AddPoint(new TrackPoint { Latitude = latValue, Longtitude = longValue, Time = time }); } track.AddSegment(segment); LocationCollection locations = new LocationCollection(); foreach (var point in segment.GetPoints()) { locations.Add(new Location { Latitude = point.Latitude, Longitude = point.Longtitude }); } MapPolyline line = CreateMapLine(locations); TracksMap.Children.Add(line); } gpxFile.AddTrack(track); } }
private void Waypoints2TrackRibbonButton_Click(object sender, RoutedEventArgs e) { Gpx gpxFile = new Gpx(); string gpxFilename = OpenGpxDialog(); if (gpxFilename == null) { return; } XElement gpxXe = XElement.Load(gpxFilename); Track track = new Track(); TrackSegment segment = new TrackSegment(); var rteList = gpxXe.Elements().Where(el => el.Name.LocalName == "rte").ToList(); if (rteList.Count != 0) { foreach (var rteXe in rteList) { var rteptList = rteXe.Elements().Where(el => el.Name.LocalName == "rtept").ToList(); foreach (var rteptXe in rteptList) { double latValue = double.Parse(rteptXe.Attribute("lat").Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture); double longValue = double.Parse(rteptXe.Attribute("lon").Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture); segment.AddPoint(new TrackPoint { Latitude = latValue, Longtitude = longValue }); } } track.AddSegment(segment); gpxFile.AddTrack(track); } var trkList = gpxXe.Elements().Where(el => el.Name.LocalName == "trk").ToList(); foreach (var trkXe in trkList) { var trksegList = trkXe.Elements().Where(el => el.Name.LocalName == "trkseg").ToList(); foreach (var trksegXe in trksegList) { var trkptList = trksegXe.Elements().Where(el => el.Name.LocalName == "trkpt").ToList(); foreach (var trkptXe in trkptList) { double latValue = double.Parse(trkptXe.Attribute("lat").Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture); double longValue = double.Parse(trkptXe.Attribute("lon").Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture); segment.AddPoint(new TrackPoint { Latitude = latValue, Longtitude = longValue }); } } track.AddSegment(segment); gpxFile.AddTrack(track); } LocationCollection locations = new LocationCollection(); foreach (var point in segment.GetPoints()) { locations.Add(new Location { Latitude = point.Latitude, Longitude = point.Longtitude }); } MapPolyline line = CreateMapLine(locations); TracksMap.Children.Add(line); StartEndDateWindow window = new StartEndDateWindow(track); window.ShowDialog(); }
public Track(Gpx.GpxTrack oldtrk) : this() { Comment = oldtrk.Comment; Description = oldtrk.Description; Name = oldtrk.Name; number = oldtrk.Number.ToString(); srcField = oldtrk.Source; foreach (Gpx.GpxTrackSegment oldseg in oldtrk.Segments) { TrackSegment seg = new TrackSegment(); foreach (Gpx.GpxPoint pt in oldseg.TrackPoints) { seg.WayPoints.Add(new WayPoint(pt)); } TrackSegments.Add(seg); } }
public WayPoint (Gpx.GpxPoint pt) { ageofdgpsdata = (pt.AgeOfData != null) ? (decimal)pt.AgeOfData : 0; ageofdgpsdataSpecified = pt.AgeOfData != null; Comment = pt.Comment; Description = pt.Description; dgpsid = pt.DgpsId.ToString(); Elevation = (pt.Elevation != null) ? (decimal)pt.Elevation : 0; fix = (pt.FixType != null) ? (Fix)Enum.Parse(typeof(Fix), pt.FixType) : Fix.none; geoidheight = (pt.GeoidHeight != null) ? (decimal)pt.GeoidHeight : 0; hdop = (pt.Hdop != null) ? (decimal)pt.Hdop : 0; Latitude = (decimal)pt.Latitude; Longitude = (decimal)pt.Longitude; MagneticVariation = (pt.MagneticVar != null) ? (decimal)pt.MagneticVar: 0; Name = pt.Name; pdop = (pt.Pdop != null) ? (decimal)pt.Pdop : 0; NumberOfSatellites = pt.Satelites.ToString(); SourceOfData = pt.Source; Symbol = pt.Symbol; Time = (pt.Time != null) ? (DateTime)pt.Time : DateTime.Now; Classification = pt.Type; }
public Task <Tuple <List <Track>, List <Point> > > LoadTrackAndSlicepointsAsync(string sourceFileName, string slicepointSourceFileName) { return(Task.FromResult(Tuple.Create( Gpx.LoadGpxTracks(sourceFileName), Gpx.LoadGpxWaypoints(slicepointSourceFileName)))); }