// TODO: take into account the elevation of points /// <summary> /// Calculates the horizontal distance between two points. /// </summary> /// <param name="p1">First point.</param> /// <param name="p2">Second point.</param> /// <returns>Horizontal distance (in meters).</returns> public static double CalculateHorizontalDistance(TrackPoint point1, TrackPoint point2) { double R = 6371000; // earth's mean radius in km double dLat = (point2.Location.Y - point1.Location.Y) * Math.PI / 180d; double dLong = (point2.Location.X - point1.Location.X) * Math.PI / 180d; double a = Math.Sin (dLat / 2) * Math.Sin (dLat / 2) + Math.Cos (point1.Location.Y * Math.PI / 180d) * Math.Cos (point2.Location.Y * Math.PI / 180d) * Math.Sin (dLong / 2) * Math.Sin (dLong / 2); double c = 2 * Math.Atan2 (Math.Sqrt (a), Math.Sqrt (1 - a)); double d = R * c; return d; }
private static TrackPoint ReadRoutePoint(gpxRteRtept wptType) { TrackPoint waypoint = new TrackPoint (); if (wptType.ageofdgpsdataSpecified) waypoint.AgeOfGpsData = wptType.ageofdgpsdata; waypoint.Comment = wptType.cmt; waypoint.Description = wptType.desc; waypoint.DgpsId = wptType.dgpsid; if (wptType.eleSpecified) waypoint.Elevation = (double)wptType.ele; if (wptType.fixSpecified) waypoint.FixType = wptType.fix.ToString (); if (wptType.geoidheightSpecified) waypoint.GeoidHeight = wptType.geoidheight; if (wptType.hdopSpecified) waypoint.HorizontalDilutionOfPrecision = wptType.hdop; waypoint.Location = new Point2<double> ((double)wptType.lon, (double)wptType.lat); if (wptType.magvarSpecified) waypoint.MagneticVariation = wptType.magvar; waypoint.Name = wptType.name; if (wptType.pdopSpecified) waypoint.PositionDilutionOfPrecision = wptType.pdop; //wptType.sat; waypoint.SourceOfData = wptType.src; waypoint.Symbol = wptType.sym; if (wptType.timeSpecified) waypoint.Time = wptType.time; //wptType.type; if (wptType.vdopSpecified) waypoint.VerticalDilutionOfPrecision = wptType.vdop; if (wptType.timeSpecified) waypoint.Time = wptType.time; return waypoint; }
public void AddWaypoint (TrackPoint waypoint) { Waypoints.Add (waypoint); }
public virtual void CopyToClone(TrackPoint clone) { clone.time = time; clone.location = (Point2<double>)location.Clone (); clone.Elevation = Elevation; clone.magneticVariation = magneticVariation; clone.geoidHeight = geoidHeight; if (name != null) clone.name = (string)name.Clone (); if (comment != null) clone.comment = (string)comment.Clone (); if (description != null) clone.description = (string)description.Clone (); if (sourceOfData != null) clone.sourceOfData = (string)sourceOfData.Clone (); if (link != null) clone.link = (Link)link.Clone (); if (symbol != null) clone.symbol = (string)symbol.Clone (); if (pointType != null) clone.pointType = (string)pointType.Clone (); if (fixType != null) clone.fixType = (string)fixType.Clone (); clone.numberOfSatellites = numberOfSatellites; clone.horizontalDilutionOfPrecision = horizontalDilutionOfPrecision; clone.verticalDilutionOfPrecision = verticalDilutionOfPrecision; clone.positionDilutionOfPrecision = positionDilutionOfPrecision; clone.ageOfGpsData = ageOfGpsData; clone.dgpsId = dgpsId; }
public virtual object Clone() { TrackPoint clone = new TrackPoint (); CopyToClone (clone); return clone; }
public void ReadGpxData(GpxFile gpxFile, Stream stream) { XmlSerializer serializer = new XmlSerializer(typeof(gpxType)); gpxType gpx = (gpxType)serializer.Deserialize(stream); if (gpx.trk != null) { foreach (trkType trkType in gpx.trk) { Track track = new Track(); if (trkType.trkseg != null) { foreach (trksegType trksegType in trkType.trkseg) { if (trksegType.trkpt != null) { TrackSegment segment = new TrackSegment(); foreach (wptType wptType in trksegType.trkpt) { TrackPoint waypoint = ReadTrackPoint(wptType); segment.AddPoint(waypoint); } track.AddSegment(segment); } } } gpxFile.AddTrack(track); } } if (gpx.wpt != null) { foreach (wptType wptType in gpx.wpt) { TrackPoint waypoint = ReadTrackPoint(wptType); gpxFile.AddWaypoint(waypoint); } } if (gpx.rte != null) { foreach (rteType rteType in gpx.rte) { Track route = new Track(); if (rteType.rtept != null) { TrackSegment segment = new TrackSegment(); foreach (wptType wptType in rteType.rtept) { TrackPoint waypoint = ReadTrackPoint(wptType); segment.AddPoint(waypoint); } route.AddSegment(segment); } gpxFile.AddRoute(route); } } }