Esempio n. 1
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 static List <Track> LoadGpxTracks(string sFile)
        {
            try
            {
                var gpxDoc = XDocument.Load(sFile);
                var gpx    = gpxDoc.Root.Name.Namespace;

                var trkList = (from track in gpxDoc.Descendants(gpx + @"trk")
                               select new Track
                {
                    Name = track.Element(gpx + @"name")?.Value ?? track.Element(gpx + @"desc")?.Value,

                    Segments = (
                        from tracksegment in track.Descendants(gpx + @"trkseg")
                        select new TrackSeg
                    {
                        Pts =
                            (
                                from trackpoint in tracksegment.Descendants(gpx + @"trkpt")
                                select new Point
                        {
                            Lat = Geo.DecodeGeoDegrees(trackpoint.Attribute(@"lat")?.Value),
                            Lon = Geo.DecodeGeoDegrees(trackpoint.Attribute(@"lon")?.Value),
                            ElevationGpx =
                                trackpoint.Element(gpx + @"ele") != null
                                                ? double.Parse(
                                    Geo.CleanupLatLonHgtForConversion(trackpoint.Element(gpx + @"ele")?
                                                                      .Value))
                                    : (double?)null,
                                    DateTimeGpx = GetDateTimeFromWpt(trackpoint)
                        }
                            ).ToList()
                    }
                        ).ToList()
                }).ToList();

                foreach (var trk in trkList)
                {
                    if (trk.Segments == null)
                    {
                        continue;
                    }

                    foreach (var seg in trk.Segments)
                    {
                        seg.RecalcBounds();
                    }
                }

                return(trkList);
            }
            catch (Exception)
            {
                return(new List <Track>()); //empty.
            }
        }
Esempio n. 2
0
        public static Point?Parse(string lat, string lon)
        {
            if (!Geo.TryDecodeGeoDegrees(lat, out var latDegrees))
            {
                return(null);
            }

            if (!Geo.TryDecodeGeoDegrees(lon, out var lonDegrees))
            {
                return(null);
            }

            return(new Point(latDegrees, lonDegrees));
        }