Пример #1
0
        private DmsCoordinateFormatHelper FormatDefault(DmsCoordinateFormatHelper dmsCoordinateFormatHelper)
        {
            if (dmsCoordinateFormatHelper.DegreesRequested)
            {
                FormatElement(DmsElement.Degrees, Degrees, ref dmsCoordinateFormatHelper);
                if (NegationOfDegreesRequired(dmsCoordinateFormatHelper))
                {
                    dmsCoordinateFormatHelper.FormattedString = "-" + dmsCoordinateFormatHelper.FormattedString;
                }
            }

            if (dmsCoordinateFormatHelper.MinutesRequested)
            {
                FormatElement(DmsElement.Minutes, Minutes, ref dmsCoordinateFormatHelper);
            }

            if (dmsCoordinateFormatHelper.SecondsRequested)
            {
                FormatElement(DmsElement.Seconds, Seconds, ref dmsCoordinateFormatHelper);
            }

            if (dmsCoordinateFormatHelper.HemisphereRequested)
            {
                FormatHemisphere(ref dmsCoordinateFormatHelper);
            }

            return(dmsCoordinateFormatHelper);
        }
Пример #2
0
        private static void UpdateFormatString(DmsCoordinateFormatHelper helper, char charToReplace, double value)
        {
            var degreesElementHelpers = helper.Format.FindConsecutiveChars(charToReplace);

            foreach (var degreesElementHelper in degreesElementHelpers)
            {
                helper.FormattedString = helper.FormattedString
                                         .Replace(degreesElementHelper.StringReplacement,
                                                  value.ToString(degreesElementHelper.FormatSpecifier, helper.FormatProvider));
            }
        }
Пример #3
0
        private void FormatDegreesOnly(ref DmsCoordinateFormatHelper dmsCoordinateFormatHelper)
        {
            const char charToReplaceInFormatString = 'D';
            var        factor = NegationOfDegreesRequired(dmsCoordinateFormatHelper) ? -1 : 1;
            var        valueInDecimalDegreesToFormat = (Degrees + Minutes / 60.0 + Seconds / 3600.0) * factor;

            UpdateFormatString(dmsCoordinateFormatHelper, charToReplaceInFormatString, valueInDecimalDegreesToFormat);

            if (dmsCoordinateFormatHelper.HemisphereRequested)
            {
                FormatHemisphere(ref dmsCoordinateFormatHelper);
            }
        }
Пример #4
0
        private void FormatDegreesMinutes(ref DmsCoordinateFormatHelper helper)
        {
            FormatElement(DmsElement.Degrees, Degrees, ref helper);
            if (NegationOfDegreesRequired(helper))
            {
                helper.FormattedString = "-" + helper.FormattedString;
            }

            const char charToReplace = 'M';
            var        minutesValue  = Minutes + Seconds / 60.0;

            UpdateFormatString(helper, charToReplace, minutesValue);

            if (helper.HemisphereRequested)
            {
                FormatHemisphere(ref helper);
            }
        }
Пример #5
0
        private string FormatString(string format, IFormatProvider formatProvider)
        {
            var formatHelper = new DmsCoordinateFormatHelper(format, formatProvider, format.ToUpper());

            if (DegreesOnlyRequested(formatHelper))
            {
                FormatDegreesOnly(ref formatHelper);
            }
            else if (DegreesAndMinutesOnlyRequested(formatHelper))
            {
                FormatDegreesMinutes(ref formatHelper);
            }
            else
            {
                formatHelper = FormatDefault(formatHelper);
            }

            return(formatHelper.FormattedString);
        }
Пример #6
0
 private static bool DegreesOnlyRequested(DmsCoordinateFormatHelper dmsCoordinateFormatHelper)
 {
     return(dmsCoordinateFormatHelper.DegreesRequested && !dmsCoordinateFormatHelper.MinutesRequested && !dmsCoordinateFormatHelper.SecondsRequested);
 }
Пример #7
0
        private void FormatHemisphere(ref DmsCoordinateFormatHelper helper)
        {
            var replacement = Hemisphere.ToString().Substring(0, 1);

            helper.FormattedString = helper.FormattedString.Replace("H", replacement);
        }
Пример #8
0
        private static void FormatElement(DmsElement element, double elementSource, ref DmsCoordinateFormatHelper helper)
        {
            var charToReplace = char.Parse(element.ToString().Substring(0, 1));

            UpdateFormatString(helper, charToReplace, elementSource);
        }
Пример #9
0
 private bool NegationOfDegreesRequired(DmsCoordinateFormatHelper helper)
 {
     return(helper != null && (!helper.HemisphereRequested && (Hemisphere == Hemisphere.South || Hemisphere == Hemisphere.West)));
 }