度分秒与度相互转换的原理
角度之间一律采用六十进制。度是大单位,秒是小单位,从大化小就乘以60,从小到大就除以60。
1°=60′=3600″
1′=(1/60)°
1″=(1/60)’=(1/3600)°
105°47′24″=105°+47*(1/60)°+24*(1/3600)°=105.79°
105.79°=105°+0.79*60′=105°+47.4′=105°+47′+0.4*60″=105°47′24″
/// <summary>/// 度分秒转度/// </summary>/// <param name="DMS">°′″</param>/// <returns></returns>static public double DMSToDDD(string DMS){ const double num = 60; double D = 0; double M = 0; double S = 0; GetDMS(DMS, out D, out M, out S); double DDD = 0; DDD += Convert.ToDouble(D); DDD += (M / num); DDD += (S / (num * num)); return DDD;}/// <summary>/// 度转度分秒/// </summary>/// <param name="DDD"></param>/// <returns></returns>static public string DDDToDMS(double DDD){ const double num = 60; int D = (int)DDD; double tmp = (DDD - D) * num; int M = (int)tmp; double S = (tmp - M) * num; string DMS = "" + D + "°" + M + "′" + S + "″"; return DMS;}/// <summary>/// 度分秒分离取值/// </summary>/// <param name="DMS">度分秒</param>/// <param name="D">度</param>/// <param name="M">分</param>/// <param name="S">秒</param>static public void GetDMS(string DMS, out double D, out double M, out double S){ D = 0; M = 0; S = 0; int d = DMS.IndexOf('°'); if (d < 0) { D = 0; } else { string degree = DMS.Substring(0, d); D = Convert.ToDouble(degree); } int m = DMS.IndexOf('′'); if (m < 0) { M = 0; } else { string minute = DMS.Substring(d + 1, m - d - 1); M = Convert.ToDouble(minute); } int s = DMS.IndexOf('″'); if (s < 0) { S = 0; } else { if (m == -1) { if (d == -1) { string second = DMS.Substring(m + 1, s - m - 1); S = Convert.ToDouble(second); } else { string second = DMS.Substring(d + 1, s - d - 1); S = Convert.ToDouble(second); } } else { string second = DMS.Substring(m + 1, s - m - 1); S = Convert.ToDouble(second); } }}