Пример #1
0
    public Position clone() 
    {
      Position newPos = new Position();
      newPos.latitude_fractional=latitude_fractional;
      newPos.latitude_sexagesimal=latitude_sexagesimal;
      newPos.latitude_decimal=latitude_decimal;
      newPos.latitude_decimal_mem=latitude_decimal_mem;
      newPos.latitude_direction=latitude_direction;

      newPos.longitude_fractional=longitude_fractional;
      newPos.longitude_sexagesimal=longitude_sexagesimal;
      newPos.longitude_decimal=longitude_decimal;
      newPos.longitude_decimal_mem=longitude_decimal_mem;
      newPos.longitude_direction=longitude_direction;

      newPos.altitudemax=altitudemax;
      newPos.altitude=altitude;

      newPos.geoidseparation=geoidseparation;

      newPos.sattime=sattime;
      newPos.satdate=satdate;

      return newPos;
    }
Пример #2
0
        private void gps_Position(object sender, OpenNetGps.Position pos)
        {
            int latMultipler   = (pos.DirectionLatitude == CardinalDirection.South) ? -1 : 1;
            int longMultiplier = (pos.DirectionLongitude == CardinalDirection.West) ? -1 : 1;

            OnPosition(new GpsPositionEventArgs(new GpsPosition(
                                                    pos.Altitude == 0 ? null : new Decimal?(pos.Altitude),
                                                    pos.Longitude_Decimal == 0 ? null : new Decimal?(pos.Longitude_Decimal * longMultiplier),
                                                    pos.Latitude_Decimal == 0 ? null : new Decimal?(pos.Latitude_Decimal * latMultipler),
                                                    pos.SatTime)));
        }
Пример #3
0
        /// <summary>
        /// calculate distance between a position and another position (in meters)
        /// </summary>
        /// <param name="pos1">Position 1</param>
        /// <param name="pos2">Position 2</param>
        /// <param name="unit">Units of measure</param>
        /// <returns></returns>
        public decimal CalculateDistance(Position pos1, Position pos2, Units unit)
        {
            double lat1 = (double)pos1.Latitude_Decimal;
            double lat2 = (double)pos2.Latitude_Decimal;
            double lon1 = (double)pos1.Longitude_Decimal;
            double lon2 = (double)pos2.Longitude_Decimal;
            double distance;

            if ((lat1 == lat2) && (lon1 == lon2))
                return 0;

            double DEG2RAD = Math.PI/180;
            lat1 *= DEG2RAD;
            lat2 *= DEG2RAD;
            lon1 *= DEG2RAD;
            lon2 *= DEG2RAD;
            distance = (60.0 * ((Math.Acos((Math.Sin(lat1) * Math.Sin(lat2)) + (Math.Cos(lat1) * Math.Cos(lat2) * Math.Cos(lon2 - lon1)))) / DEG2RAD));

            switch (unit)
            {
                case Units.Kilometers:
                    return Misc.NmToMeters((decimal)distance)/1000;
                case Units.Knots:
                    return Misc.ToDecimal((decimal)distance)/1000;
                case Units.Miles:
                    return Misc.NmToMiles((decimal)distance)/1000;
                default:
                    return 0;
            }
        }
Пример #4
0
        /// <summary>
        /// calculate bearing between a position and another position (in degrees)
        /// </summary>
        /// <param name="pos1"></param>
        /// <param name="pos2"></param>
        /// <returns></returns>
        public decimal CalculateBearing(Position pos1,Position pos2)
        {
            double DEG2RAD = Math.PI/180;
            double lat1 = (double)pos1.Latitude_Decimal * DEG2RAD;
            double lat2 = (double)pos2.Latitude_Decimal * DEG2RAD;
            double lon1 = (double)pos1.Longitude_Decimal * DEG2RAD;
            double lon2 = (double)pos2.Longitude_Decimal * DEG2RAD;
            double bearing;

            if ((lat1 == lat2) && (lon1 == lon2))
                return 0;

            bearing = (Math.Atan2(Math.Sin(lon2 - lon1) * Math.Cos(lat2),
                Math.Cos(lat1) * Math.Sin(lat2) - Math.Sin(lat1) * Math.Cos(lat2) * Math.Cos(lon2 - lon1))) / DEG2RAD;
            // returns a value between -180 and 180.
            if (bearing < 0.0)
                bearing += 360.0;

            return (decimal)bearing;
        }
Пример #5
0
        private void reset_gps_vars()
        {
            strreceived="";
            sentencecount=0;

            pos = null;
            pos = new Position();
            mov = null;
            mov = new Movement();
            satellites = null;
            lasterror="";

            distancetowaypoint=0;
            bearingtowaypoint=0;
            coursecorrection=0;

            InitDistance = false;

            // Position dilution of precision
            pdop=50;

            // Horizontal dilution of precision
            hdop=50;

            // Vertical dilution of precision
            hdop=50;
        }
Пример #6
0
 protected virtual void OnPosition(Position pos)
 {
     if (Position!=null) Position(this,pos);
 }