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); }
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)); } }
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); } }
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); } }
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); }
private static bool DegreesOnlyRequested(DmsCoordinateFormatHelper dmsCoordinateFormatHelper) { return(dmsCoordinateFormatHelper.DegreesRequested && !dmsCoordinateFormatHelper.MinutesRequested && !dmsCoordinateFormatHelper.SecondsRequested); }
private void FormatHemisphere(ref DmsCoordinateFormatHelper helper) { var replacement = Hemisphere.ToString().Substring(0, 1); helper.FormattedString = helper.FormattedString.Replace("H", replacement); }
private static void FormatElement(DmsElement element, double elementSource, ref DmsCoordinateFormatHelper helper) { var charToReplace = char.Parse(element.ToString().Substring(0, 1)); UpdateFormatString(helper, charToReplace, elementSource); }
private bool NegationOfDegreesRequired(DmsCoordinateFormatHelper helper) { return(helper != null && (!helper.HemisphereRequested && (Hemisphere == Hemisphere.South || Hemisphere == Hemisphere.West))); }