コード例 #1
0
        private IEnumerable <GpxTrack> SerializeTracks(GpsData data)
        {
            foreach (var track in data.Tracks)
            {
                var trk = new GpxTrack();

                SerializeTrackMetadata(track, trk, x => x.Name, (gpx, s) => gpx.name        = s);
                SerializeTrackMetadata(track, trk, x => x.Description, (gpx, s) => gpx.desc = s);
                SerializeTrackMetadata(track, trk, x => x.Comment, (gpx, s) => gpx.cmt      = s);

                trk.trkseg = new GpxTrackSegment[track.Segments.Count];
                for (var i = 0; i < track.Segments.Count; i++)
                {
                    var segment = track.Segments[i];
                    var pts     = new GpxWaypoint[segment.Waypoints.Count];
                    for (var j = 0; j < segment.Waypoints.Count; j++)
                    {
                        pts[j] = ConvertToGpxWaypoint(segment.Waypoints[j]);
                    }
                    trk.trkseg[i] = new GpxTrackSegment {
                        trkpt = pts
                    };
                }

                yield return(trk);
            }
        }
コード例 #2
0
ファイル: Gpx11Serializer.cs プロジェクト: tatepoon/Geo
        private IEnumerable <GpxTrack> SerializeTracks(GpsData data)
        {
            foreach (var track in data.Tracks)
            {
                var trk = new GpxTrack();

                SerializeTrackMetadata(track, trk, x => x.Name, (gpx, s) => gpx.name        = s);
                SerializeTrackMetadata(track, trk, x => x.Description, (gpx, s) => gpx.desc = s);
                SerializeTrackMetadata(track, trk, x => x.Comment, (gpx, s) => gpx.cmt      = s);

                trk.trkseg = new GpxTrackSegment[track.Segments.Count];
                for (var i = 0; i < track.Segments.Count; i++)
                {
                    var segment = track.Segments[i];
                    var pts     = new GpxWaypoint[segment.Fixes.Count];
                    for (var j = 0; j < segment.Fixes.Count; j++)
                    {
                        pts[j] = new GpxWaypoint
                        {
                            lat = (decimal)segment.Fixes[j].Coordinate.Latitude,
                            lon = (decimal)segment.Fixes[j].Coordinate.Longitude,
                            ele = segment.Fixes[j].Coordinate.Is3D ? (decimal)((Is3D)segment.Fixes[j].Coordinate).Elevation : 0m
                        };
                    }
                    trk.trkseg[i] = new GpxTrackSegment {
                        trkpt = pts
                    };
                }

                yield return(trk);
            }
        }
コード例 #3
0
        private GpxWaypoint ToGpxWaypoint(LatLngTime latLng)
        {
            var gpxWaypoint = new GpxWaypoint(new GpxLongitude(latLng.Lng), new GpxLatitude(latLng.Lat), latLng.Alt);

            return(latLng.Timestamp.HasValue
                ? gpxWaypoint.WithTimestampUtc(latLng.Timestamp.Value.ToUniversalTime())
                : gpxWaypoint);
        }
コード例 #4
0
        private static Waypoint ConvertWaypoint(GpxWaypoint wptType)
        {
            var point = wptType.eleSpecified ? new Point((double)wptType.lat, (double)wptType.lon, (double)wptType.ele) :
                        new Point((double)wptType.lat, (double)wptType.lon);
            var time = wptType.timeSpecified ? wptType.time : (DateTime?)null;

            return(new Waypoint(point, time, wptType.name, wptType.cmt, wptType.desc));
        }
コード例 #5
0
        private Coordinate CreateGeoPosition(GpxWaypoint waypoint)
        {
            double lat = waypoint.Latitude;
            double lon = waypoint.Longitude;

            return(waypoint.ElevationInMeters.HasValue
                ? new CoordinateZ(lon, lat, (double)waypoint.ElevationInMeters)
                : new CoordinateZ(lon, lat));
        }
コード例 #6
0
 private LatLng ToLatLng(GpxWaypoint point)
 {
     return(new LatLng
     {
         Lat = point.Latitude,
         Lng = point.Longitude,
         Alt = point.ElevationInMeters
     });
 }
コード例 #7
0
 private LatLngTime ToLatLngTime(GpxWaypoint point)
 {
     return(new LatLngTime
     {
         Lat = point.Latitude,
         Lng = point.Longitude,
         Alt = point.ElevationInMeters,
         Timestamp = point.TimestampUtc?.ToLocalTime()
     });
 }
コード例 #8
0
        private static TrackWaypoint ConvertWaypoint(GpxWaypoint gpxWaypoint)
        {
            TrackWaypoint waypoint = new TrackWaypoint();

            waypoint.Altitude    = (float)gpxWaypoint.Elevation;
            waypoint.Latitude    = (float)gpxWaypoint.Lat;
            waypoint.Longitude   = (float)gpxWaypoint.Lon;
            waypoint.Name        = gpxWaypoint.Name;
            waypoint.Description = gpxWaypoint.Description;

            return(waypoint);
        }
コード例 #9
0
        void LoadGPX(string path)
        {
            try {
                var file = GpxFile.ReadFrom(XmlReader.Create(path), null);
                textBoxDesc.Text = file.Metadata.Description;
                if (DateTime.TryParse(file.Metadata.Name, out DateTime dt))
                {
                    dateTimePicker1.Value = dt;
                }

                var geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326);

                double      fullDist = 0;
                GpxWaypoint prev_wp  = null;

                TimeSpan timeSpan     = new TimeSpan();
                TimeSpan timeSpanMove = new TimeSpan();

                foreach (var track in file.Tracks)
                {
                    foreach (var seg in track.Segments)
                    {
                        foreach (var wp in seg.Waypoints)
                        {
                            if (prev_wp != null)
                            {
                                var distance = gps2m(wp.Latitude.Value, wp.Longitude.Value, prev_wp.Latitude.Value, prev_wp.Longitude.Value);
                                //var distance = point.Distance(prevPoint);
                                fullDist += distance;
                                if (wp.TimestampUtc.HasValue && prev_wp.TimestampUtc.HasValue)
                                {
                                    timeSpan = timeSpan.Add(wp.TimestampUtc.Value - prev_wp.TimestampUtc.Value);
                                    if (distance > 1e-06)
                                    {
                                        timeSpanMove = timeSpan.Add(wp.TimestampUtc.Value - prev_wp.TimestampUtc.Value);
                                    }
                                }
                            }
                            prev_wp = wp;
                        }
                    }
                }

                numericUpDownHours.Value   = timeSpan.Hours;
                numericUpDownMinutes.Value = timeSpan.Minutes;

                numericUpDownDistance.Value = (decimal)(0.001 * fullDist);
                currentTrackPath            = path;
            } catch (Exception ex) {
                MessageBox.Show($"Load treck error:\n{ex.Message}");
            }
        }
コード例 #10
0
 private MarkerData ToMarkerData(GpxWaypoint point)
 {
     return(new MarkerData
     {
         Latlng = ToLatLng(point),
         Title = point.Name,
         Type = point.Classification,
         Description = point.Description,
         Urls = point.Links.Select(l => new LinkData {
             MimeType = l.ContentType, Url = l.HrefString, Text = l.Text
         })
                .ToList()
     });
 }
コード例 #11
0
        /// <summary>
        /// Calculates the distance between two geographic coordinates.
        /// </summary>
        public static double CalculateDistanceMeters(GpxWaypoint point1, GpxWaypoint point2)
        {
            // Method implementation from
            // https://stackoverflow.com/questions/60700865/find-distance-between-2-coordinates-in-net-core

            var d1   = point1.Latitude * (Math.PI / 180.0);
            var num1 = point1.Longitude * (Math.PI / 180.0);
            var d2   = point2.Latitude * (Math.PI / 180.0);
            var num2 = point2.Longitude * (Math.PI / 180.0) - num1;
            var d3   = Math.Pow(Math.Sin((d2 - d1) / 2.0), 2.0) +
                       Math.Cos(d1) * Math.Cos(d2) * Math.Pow(Math.Sin(num2 / 2.0), 2.0);

            return(6376500.0 * (2.0 * Math.Atan2(Math.Sqrt(d3), Math.Sqrt(1.0 - d3))));
        }
コード例 #12
0
        public void Check_CalculateDistance()
        {
            var point1 = new GpxWaypoint();

            point1.Latitude  = 49.638005001470447;
            point1.Longitude = 12.266169972717762;

            var point2 = new GpxWaypoint();

            point2.Latitude  = 49.6377810370177;
            point2.Longitude = 12.265615006908774;

            var distance = GeoCalculator.CalculateDistanceMeters(point1, point2);

            Assert.AreEqual(47.0, Math.Round(distance, 0));
        }
コード例 #13
0
        public static SqlGeography AsGeography(this GpxWaypoint point)
        {
            SqlGeographyBuilder builder = new SqlGeographyBuilder();

            builder.SetSrid(SridHelper.GeodeticWGS84);

            builder.BeginGeography(OpenGisGeographyType.Point);

            builder.BeginFigure(point.Latitude, point.Longitude);

            builder.EndFigure();

            builder.EndGeography();

            return(builder.ConstructedGeography);
        }
コード例 #14
0
 public LoadedGpxFileWaypointInfo(LoadedGpxFile gpxFile, GpxWaypoint rawWaypoint)
 {
     this.File            = gpxFile;
     this.RawWaypointData = rawWaypoint;
 }
コード例 #15
0
 /// <summary>
 /// Invoked when the reader has moved past a GPX wpt element.
 /// </summary>
 /// <param name="waypoint">
 /// The <see cref="GpxWaypoint"/> instance that represents what we read, guaranteed non-
 /// <see langword="null"/>.
 /// </param>
 /// <remarks>
 /// This is not guaranteed to be called for every GPX file.
 /// </remarks>
 public virtual void VisitWaypoint(GpxWaypoint waypoint)
 {
 }