Exemplo n.º 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);
        }
Exemplo n.º 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));
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 6
0
 private static bool DegreesOnlyRequested(DmsCoordinateFormatHelper dmsCoordinateFormatHelper)
 {
     return(dmsCoordinateFormatHelper.DegreesRequested && !dmsCoordinateFormatHelper.MinutesRequested && !dmsCoordinateFormatHelper.SecondsRequested);
 }
Exemplo n.º 7
0
        private void FormatHemisphere(ref DmsCoordinateFormatHelper helper)
        {
            var replacement = Hemisphere.ToString().Substring(0, 1);

            helper.FormattedString = helper.FormattedString.Replace("H", replacement);
        }
Exemplo n.º 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);
        }
Exemplo n.º 9
0
 private bool NegationOfDegreesRequired(DmsCoordinateFormatHelper helper)
 {
     return(helper != null && (!helper.HemisphereRequested && (Hemisphere == Hemisphere.South || Hemisphere == Hemisphere.West)));
 }