//=======================================================================
        #region -= static methods =-

        /// <summary>
        /// must be in the format 239.02,E
        /// </summary>
        /// <param name="inputString"></param>
        /// <returns></returns>
        public static MagneticVariation Parse(string inputString)
        {
            //---- declare vars
            MagneticVariation magVar = new MagneticVariation();

            string[] halves = inputString.Split(',');

            if (halves.Length < 2)
            {
                throw new FormatException("Input string must be in the format of 33.02,E");
            }

            if (string.IsNullOrEmpty(halves[0]))
            {
                magVar.Degrees = 0.0M;
            }
            else
            {
                magVar.Degrees = decimal.Parse(halves[0]);
            }
            magVar.Direction = DirectionUtil.Parse(halves[1]);

            //---- return
            return(magVar);
        }
Exemple #2
0
        //=======================================================================

        #endregion
        //=======================================================================

        //=======================================================================
        #region -= static methods =-

        /// <summary>
        /// must be in the format 24952.32,N
        /// </summary>
        /// <param name="positionalDegree"></param>
        /// <returns></returns>
        public static PositionalDegree Parse(string inputString)
        {
            //---- declare vars
            PositionalDegree position = new PositionalDegree();

            //---- split it in half
            string[] halves = inputString.Trim().Split(',');
            //----
            if (halves.Length < 2)
            {
                throw new FormatException("Input string must be in the format 23490.32,N");
            }

            //---- parse the direction
            position.Direction = DirectionUtil.Parse(halves[1]);

            //---- parse the degrees, minutes seconds
            decimal degrees;

            bool isparse = true;

            try
            {
                degrees = decimal.Parse(halves[0]);
            }
            catch (ArgumentException)
            {
                isparse = false;
                degrees = new decimal();
            }

            if (isparse)
            {
                position.Degrees = degrees;
            }
            else
            {
                throw new FormatException("Degrees must be in the format 20934.23");
            }

            //----
            return(position);
        }
Exemple #3
0
        //public PositionalDegree(int degrees, int minutes, int seconds)
        //    : base()
        //{
        //    this._degrees = degrees;
        //    this._minutes = minutes;
        //    this._seconds = seconds;
        //}

        #endregion
        //=======================================================================

        //=======================================================================
        #region -= public methods =-

        //=======================================================================
        /// <summary>
        /// Returns in the format of "23908.908,N"
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return(this._degrees.ToString() + "," + DirectionUtil.ToString(this._direction));
        }