コード例 #1
0
ファイル: Utils.cs プロジェクト: eitanbehar/gpx
        public static double Distance(Trackpoint tp1, Trackpoint tp2)
        {
            //=ACOS(SIN(lat1)*SIN(lat2)+COS(lat1)*COS(lat2)*COS(lon2-lon1))*6371
            double dist = Math.Acos(Math.Sin(DegreeToRadian(tp1.LatitudeDegrees)) * Math.Sin(DegreeToRadian(tp2.LatitudeDegrees)) +
                                    Math.Cos(DegreeToRadian(tp1.LatitudeDegrees)) * Math.Cos(DegreeToRadian(tp2.LatitudeDegrees)) * Math.Cos(DegreeToRadian(tp2.LongitudeDegrees - tp1.LongitudeDegrees))) * 6371;

            return(dist);
        }
コード例 #2
0
ファイル: Utils.cs プロジェクト: eitanbehar/gpx
        public static void SetPoint(Trackpoint tp1, Trackpoint tp2, double Distance, double deltaLon, double deltaLat)
        {
            if (Distance <= 0)
            {
                tp2.LongitudeDegrees = tp1.LongitudeDegrees;
                tp2.LatitudeDegrees  = tp1.LatitudeDegrees;
                return;
            }

            double dist = 0;

            do
            {
                tp2.LongitudeDegrees += deltaLon;
                tp2.LatitudeDegrees  += deltaLat;
                dist = Utils.Distance(tp1, tp2);
            } while (dist < Distance);
        }
コード例 #3
0
        static void OnMesg(object sender, MesgEventArgs e)
        {
            string activityType = e.mesg.Name;

            if (activityType != "FileId" && activityType != "Record")
            {
                return;
            }

            Console.WriteLine("OnMesg: Received Mesg with global ID#{0}, its name is {1}", e.mesg.Num, activityType);

            Trackpoint tp = new Trackpoint();

            for (byte i = 0; i < e.mesg.GetNumFields(); i++)
            {
                foreach (var field in e.mesg.fields)
                {
                    string fieldValue = field.GetValue().ToString();
                    string fieldName  = field.GetName().ToString();
                    string recordType = e.mesg.fields[i].Num.ToString();
                    //Console.WriteLine("\tField{0} Index{1} (\"{2}\" Field#{4}) Value: {3}", i, 0, fieldName, fieldValue, recordType);

                    switch (activityType)
                    {
                    case "FileId":

                        switch (fieldName)
                        {
                        case "TimeCreated":
                            Dynastream.Fit.DateTime dt = new Dynastream.Fit.DateTime(uint.Parse(fieldValue));
                            tcx.Id        = Trackpoint.ConvertDate(dt.GetDateTime());
                            tcx.StartTime = dt.GetDateTime();
                            break;

                        default:
                            break;
                        }

                        break;

                    case "Record":

                        switch (fieldName)
                        {
                        case "Timestamp":
                            Dynastream.Fit.DateTime dt = new Dynastream.Fit.DateTime(uint.Parse(fieldValue));
                            tp.Time = dt.GetDateTime();
                            break;

                        case "HeartRate":
                            tp.HeartRateBpm = int.Parse(fieldValue);
                            if (tp.HeartRateBpm > 220)
                            {
                                tp.HeartRateBpm = 0;
                            }
                            break;

                        case "PositionLat":
                            tp.LatitudeDegrees = double.Parse(fieldValue);
                            break;

                        case "PositionLong":
                            tp.LongitudeDegrees = double.Parse(fieldValue);
                            break;

                        case "Altitude":
                            tp.AltitudeMeters = double.Parse(fieldValue);
                            if (tp.AltitudeMeters > 12000)
                            {
                                tp.AltitudeMeters = 0;
                            }
                            break;

                        case "Distance":
                            tp.Distance = double.Parse(fieldValue);
                            break;

                        //case "Power":
                        //    tp.Power = double.Parse(fieldValue);
                        //    break;
                        //case "Grade":
                        //    tp.Grade = double.Parse(fieldValue);
                        //    break;
                        case "Speed":
                            tp.Speed = double.Parse(fieldValue);
                            break;

                        //case "Resistance":
                        //    tp.Resistance = double.Parse(fieldValue);
                        //    break;
                        case "Cadence":
                            tp.Cadence = double.Parse(fieldValue);
                            if (tp.Cadence > 250)
                            {
                                tp.Cadence = 0;
                            }
                            break;

                        default:
                            break;
                        }

                        break;

                    default:
                        break;
                    }
                }
            }

            if (activityType == "Record")
            {
                tcx.TrackpointList.Add(tp);
            }
        }
コード例 #4
0
ファイル: Tcx.cs プロジェクト: eitanbehar/gpx
        public void Save(String Filename)
        {
            XElement xTrack = new XElement("Track");

            foreach (Trackpoint trackPoint in TrackpointList)
            {
                xTrack.Add(trackPoint.GetTrackpoint());
            }

            XNamespace ns = "HeartRateInBeatsPerMinute_t";

            XElement xTcx = new XElement("Activities",
                                         new XElement("Activity", new XAttribute("Sport", Sport),
                                                      new XElement("Id", Id),
                                                      new XElement("Lap", new XAttribute("StartTime", Trackpoint.ConvertDate(StartTime)),
                                                                   new XElement("DistanceMeters", DistanceMeters),
                                                                   new XElement("Calories", Calories),
                                                                   new XElement(ns + "AverageHeartRateBpm",
                                                                                new XElement("Value", AvgHeartRate)),
                                                                   new XElement(ns + "MaximumHeartRateBpm",
                                                                                new XElement("Value", MaxHeartRate)),
                                                                   new XElement("TotalTimeSeconds", TotalTimeSeconds),
                                                                   xTrack)));

            xTcx.Save(Filename);
        }