public static GpsFile ConvertToFile(GpxFile gpxFile)
        {
            GpsFile gpsFile = new GpsFile();

            gpsFile.Name = gpxFile.Filename.Split('\\').Last();

            gpsFile.Tracks.AddRange(GpsUtils.ConvertToTracks(gpxFile, string.Empty));
            gpsFile.Waypoints.AddRange(GpsUtils.ConvertToWaypoints(gpxFile));
            gpsFile.Routes.AddRange(GpsUtils.ConvertToRoutes(gpxFile));

            gpsFile.TrackSummary = new GpsTrackSummary();

            GpsUtils.CalculateNodeData(gpsFile.Tracks, gpsFile.TrackSummary);

            return(gpsFile);
        }
        public static List <GpsTrack> ConvertToTracks(GpxFile gpxFile, string sourceName)
        {
            List <GpsTrack> gpsTrack = new List <GpsTrack>();

            if (gpxFile == null)
            {
                return(gpsTrack);
            }

            foreach (GpxTrackNode trackNode in gpxFile.RootNode.Tracks)
            {
                // Add a new track
                gpsTrack.Add(new GpsTrack());
                gpsTrack.Last().Name     = trackNode.Name;
                gpsTrack.Last().Segments = new List <GpsTrackSegment>();

                foreach (GpxSegmentNode segment in trackNode.Segments)
                {
                    // Add a new Segment
                    gpsTrack.Last().Segments.Add(new GpsTrackSegment());
                    gpsTrack.Last().Segments.Last().Name = trackNode.Name;
                    gpsTrack.Last().Segments.Last().Points = new List <GpsTrackPoint>();

                    foreach (GpxPointNode pointNode in trackNode.Segments.First().Points)
                    {
                        // Add each point
                        gpsTrack.Last().Segments.Last().Points.Add(new GpsTrackPoint());
                        gpsTrack.Last().Segments.Last().Points.Last().Time = pointNode.Time;
                        gpsTrack.Last().Segments.Last().Points.Last().Latitude.Numeric = pointNode.Lat;
                        gpsTrack.Last().Segments.Last().Points.Last().Longitude.Numeric = pointNode.Lon;
                        gpsTrack.Last().Segments.Last().Points.Last().Altitude = pointNode.Ele;
                        gpsTrack.Last().Segments.Last().Points.Last().Dimension = GpsPosition.Dimensions.ThreeDimensional;
                        gpsTrack.Last().Segments.Last().Points.Last().Source = sourceName;
                    }
                }

                GpsUtils.CalculateNodeData(gpsTrack.Last().Segments, gpsTrack.Last());
            }

            return(gpsTrack);
        }
 public static void CalculateNodeData(List <GpsTrackSegment> segments, GpsTrackSummary nodeSummary)
 {
     GpsUtils.CalculateNodeData(segments.SelectMany(x => x.Points).ToList(), nodeSummary);
 }