Esempio n. 1
0
        static void Main(string[] args)
        {
            GPXLoader            gpxLoader = new GPXLoader();
            string               tracks    = gpxLoader.LoadGPXTracks(@"D:\Tanulós\Futóverseny Project\LoadGpxTry2.0\trackek\Éva_Kolcsrn+Srecz_2020-08-15_13-08-53.GPX").ToString();
            RunnerDataProcessing rdp       = new RunnerDataProcessing();

            Console.WriteLine(tracks);
            Console.ReadKey();
        }
Esempio n. 2
0
        /// <summary>
        /// When passed a file, open it and parse all tracks
        /// and track segments from it.
        /// </summary>
        /// <param name="sFile">Fully qualified file name (local)</param>
        /// <returns>string containing line delimited waypoints from the
        /// file (for test)</returns>
        public List <TrackDto> LoadGPXTracks(string sFile)
        {
            XDocument            gpxDoc = GetGpxDoc(sFile);
            XNamespace           gpx    = GetGpxNameSpace();
            RunnerDataProcessing rdp    = new RunnerDataProcessing();
            var tracks = from track in gpxDoc.Descendants(gpx + "trk")
                         select new
            {
                Name = track.Element(gpx + "name") != null?
                       track.Element(gpx + "name").Value : null,
                Segs = (from trackpoint in track.Descendants(gpx + "trkpt")
                        select new
                {
                    Latitude = trackpoint.Attribute("lat").Value,
                    Longitude = trackpoint.Attribute("lon").Value,
                    Elevation = trackpoint.Element(gpx + "ele") != null ? trackpoint.Element(gpx + "ele").Value : null,
                    Time = trackpoint.Element(gpx + "time") != null ? trackpoint.Element(gpx + "time").Value : null
                })
            };

            List <TrackDto> tracksAsList = new List <TrackDto>();

            foreach (var trk in tracks)
            {
                // Populate track data objects.
                foreach (var trkSeg in trk.Segs)
                {
                    TrackDto trackDto = new TrackDto
                    {
                        Latitude   = double.Parse(trkSeg.Latitude, System.Globalization.CultureInfo.InvariantCulture),
                        Longitude  = double.Parse(trkSeg.Longitude, System.Globalization.CultureInfo.InvariantCulture),
                        Coordinate = new Coordinate(double.Parse(trkSeg.Latitude, System.Globalization.CultureInfo.InvariantCulture), double.Parse(trkSeg.Longitude, System.Globalization.CultureInfo.InvariantCulture)),
                        Elevation  = double.Parse(trkSeg.Elevation, System.Globalization.CultureInfo.InvariantCulture),
                        Time       = convertIsoToDateTime(trkSeg.Time)
                    };
                    tracksAsList.Add(trackDto);
                }
            }

            #region MakeNewRunner
            Runner runner = new Runner
            {
                Name          = rdp.getNameFromFileName(Path.GetFileName(sFile)),
                DateofRunning = tracksAsList.First().Time.Date,
                RunTime       = Convert.ToDateTime((tracksAsList.Last().Time - tracksAsList.First().Time).ToString()),
                ElevationUp   = rdp.ElevationUp(tracksAsList),
                ElevationDown = rdp.ElevationDown(tracksAsList),
                Distance      = rdp.CountDistance(tracksAsList) / 1000
            };
            #endregion

            return(tracksAsList); // Return as List
        }