/// <summary> /// Converts the specified string representation of a Degree-Minute-Second to its DegreeMinuteSecond /// equivalent and returns a value that indicates whether the conversion succeeded. /// </summary> /// <param name="value"></param> /// <param name="result"></param> /// <returns></returns> public static bool TryParse(string value, out DegreeMinuteSecond result) { if (string.IsNullOrWhiteSpace(value)) { throw new ArgumentNullException(nameof(value), "The argument cannot be null or empty."); } double doubleValue; if (double.TryParse(value, out doubleValue) && double.IsInfinity(doubleValue) == false) { result = new DegreeMinuteSecond(doubleValue); return(true); } string[] parts = TryParseSplitStringIntoDegreeMinuteSecond(value); var d = Convert.ToDouble(parts[0]); var m = parts.Length >= 2 ? Convert.ToDouble(parts[1]) : 0D; var s = parts.Length >= 3 ? Convert.ToDouble(parts[2]) : 0D; var degrees = TryParseCalculateNumericDegrees(d, m, s); result = new DegreeMinuteSecond(TryParseConvertToNegativeIfSouthOrWest(value, degrees)); return(true); }
/// <summary> /// Get the string representation of this object after converting the Latitude and Longitude to Degrees-Minutes-Seconds. /// </summary> /// <returns></returns> public string ToDegreeMinuteSecond() { string latitude = new DegreeMinuteSecond(this.Latitude).ToLatitude(); string longitude = new DegreeMinuteSecond(this.Longitude).ToLongitude(); return(string.Format("{0}, {1}", latitude, longitude)); }
private static double ConvertToDegrees(string value) { DegreeMinuteSecond dms; if (DegreeMinuteSecond.TryParse(value, out dms)) { return(dms.Degrees); } else { throw new InvalidCastException(string.Format("Could not convert '{0}' to a DegreeMinuteSecond.", value)); } }