예제 #1
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;

            if (decimal.TryParse(halves[0], out degrees))
            {
                int d = (int)(degrees / 100);
                var f = (degrees - d * 100);
                position.Degrees = (d + f / 60.0m);
            }
            //else { throw new FormatException("Degrees must be in the format 20934.23"); }

            //----
            return(position);
        }
예제 #2
0
 public static bool TryParse(string inputString, out PositionalDegree positionalDegree)
 {
     try
     {
         positionalDegree = Parse(inputString);
         return(true);
     }
     catch (Exception e)
     {
         positionalDegree = null;
         return(false);
     }
 }
예제 #3
0
        //=======================================================================

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

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

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

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

            if (halves.Length < 2)
            {
                throw new FormatException();
            }

            position.Latitude = PositionalDegree.Parse(halves[0]);

            position.Longitude = PositionalDegree.Parse(halves[1]);

            //----
            return(position);
        }