Example #1
0
        /**
         * Parses a DMM string representation
         * @param s
         * @return
         */
        public static DMMComponents Parse(String s, GeoAngleFormatOptions options)
        {
            int    sign           = 1;
            int    wholeDegrees   = 0;
            double decimalMinutes = 0;

            if (options == GeoAngleFormatOptions.Compact)
            {
                // ... Split value and hemisphere letter

                String[] tokens = s.Split(DELIMS);
                if (tokens.Length != 2)
                {
                    throw new DMMFormatException(s);
                }

                sign = getHemisphereSign(tokens[1].Trim()[0]);

                double number = Double.Parse(tokens[0].Trim());
                wholeDegrees   = (int)Math.Floor(number / 100);
                decimalMinutes = number - wholeDegrees * 100;
            }
            else
            {
                // ... Split value and hemisphere letter
                List <String> tokens = new List <String>(s.Split(DELIMS, StringSplitOptions.RemoveEmptyEntries));
                if (tokens.Count != 2)
                {
                    throw new DMMFormatException(s);
                }
                wholeDegrees   = Int32.Parse(tokens[0]);
                sign           = wholeDegrees < 0 ? -1 : 1;
                wholeDegrees  *= sign; // Abs
                decimalMinutes = Double.Parse(tokens[1]);
            }

            DMMComponents rc = new DMMComponents();

            rc.set_sign(sign);
            rc.set_wholeDegrees(wholeDegrees);
            rc.set_decimalMinutes(decimalMinutes);
            return(rc);
        }