示例#1
0
        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);
            }
        }
示例#2
0
        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();
        }