Пример #1
0
        ///// <summary>
        /////     转换为度分秒
        ///// </summary>
        ///// <param name="sender"></param>
        ///// <param name="e"></param>
        //private void ConversionDuFenMiao()
        //{
        //    if (radLngLat.SelectedIndex == 0)
        //    {
        //        FormatLongitudeToCelsiusMinuteSecondHanzi(double.Parse(txtInput.Text.Trim()));
        //    }
        //    else
        //    {
        //        FormatLatitudeToCelsiusMinuteSecondHanzi(double.Parse(txtInput.Text.Trim()));
        //    }
        //}

        ///// <summary>
        /////     转换为°′″
        ///// </summary>
        ///// <param name="sender"></param>
        ///// <param name="e"></param>
        //private void SignConversionDuFenMiao()
        //{
        //    if (radLngLat.SelectedIndex == 0)
        //    {
        //        FormatLongitudeToCelsiusMinuteSecond(double.Parse(txtInput.Text.Trim()));
        //    }
        //    else
        //    {
        //        FormatLatitudeToCelsiusMinuteSecond(double.Parse(txtInput.Text.Trim()));
        //    }
        //}

        /// <summary>
        /// 转换经度为°′″
        /// </summary>
        /// <param name="longitude"></param>
        /// <returns></returns>
        private string FormatLongitudeToCelsiusMinuteSecond(double longitude)
        {
            double jd    = longitude;
            var    tipJD = string.Empty;

            if (jd >= 0) //东经E
            {
                tipJD = "E";
            }
            else
            {
                tipJD = "W";
                jd    = 0 - jd;
            }

            int    Celsius_JD, Minute_JD, Second_JD;
            string strCelsius_JD, strMinute_JD, strSecond_JD;

            Celsius_JD = (int)Math.Floor(jd);
            if (Celsius_JD < 10) //只有一位,补两个0
            {
                strCelsius_JD = "00" + Celsius_JD;
            }
            else if (Celsius_JD < 100) //只有两位,补一个0
            {
                strCelsius_JD = "0" + Celsius_JD;
            }
            else
            {
                strCelsius_JD = Celsius_JD.ToString();
            }
            strCelsius_JD += "°";

            Minute_JD = (int)Math.Floor((jd - Celsius_JD) * 60);
            if (Minute_JD < 10) //只有一位,补一个0
            {
                strMinute_JD = "0" + Minute_JD;
            }
            else
            {
                strMinute_JD = Minute_JD.ToString();
            }
            strMinute_JD += "′";
            //decimal sum = Convert.ToDecimal((jd - Celsius_JD) * 60);
            Second_JD = (int)Math.Floor((Convert.ToDecimal((jd - Celsius_JD) * 60) - Minute_JD) * 60);
            if (Second_JD < 10)
            {
                strSecond_JD = "0" + Second_JD;
            }
            else
            {
                strSecond_JD = Second_JD.ToString();
            }
            strSecond_JD += "″";
            var strDMSJD = string.Format("{0}{1}{2}{3}", strCelsius_JD, strMinute_JD, Second_JD, tipJD);

            return(strDMSJD);
        }
Пример #2
0
        ///// <summary>
        /////     转换为度分
        ///// </summary>
        ///// <param name="sender"></param>
        ///// <param name="e"></param>
        //private void ConversionDuFen()
        //{
        //    if (radLngLat.SelectedIndex == 0)
        //    {
        //        FormatLongitudeToCelsiusMinuteHanzi(double.Parse(txtInput.Text.Trim()));
        //    }
        //    else
        //    {
        //        FormatLatitudeToCelsiusMinuteHanzi(double.Parse(txtInput.Text.Trim()));
        //    }
        //}

        ///// <summary>
        /////     转换为°′
        ///// </summary>
        ///// <param name="sender"></param>
        ///// <param name="e"></param>
        //private void SignConversionDuFen()
        //{
        //    if (radLngLat.SelectedIndex == 0)
        //    {
        //        FormatLongitudeToCelsiusMinute(double.Parse(txtInput.Text.Trim()));
        //    }
        //    else
        //    {
        //        FormatLatitudeToCelsiusMinute(double.Parse(txtInput.Text.Trim()));
        //    }
        //}

        /// <summary>
        ///     转换经度为°′格式
        /// </summary>
        /// <param name="longitude"></param>
        /// <returns></returns>
        public string FormatLongitudeToCelsiusMinute(double longitude)
        {
            var jd    = longitude;
            var tipJD = string.Empty;

            if (jd >= 0) //东经E
            {
                tipJD = "E";
            }
            else
            {
                tipJD = "W";
                jd    = 0 - jd;
            }

            int    Celsius_JD, Minute_JD;
            string strCelsius_JD, strMinute_JD;

            Celsius_JD = (int)Math.Floor(jd);
            if (Celsius_JD < 10) //只有一位,补两个0
            {
                strCelsius_JD = "00" + Celsius_JD;
            }
            else if (Celsius_JD < 100) //只有两位,补一个0
            {
                strCelsius_JD = "0" + Celsius_JD;
            }
            else
            {
                strCelsius_JD = Celsius_JD.ToString();
            }
            strCelsius_JD += "°";

            Minute_JD = (int)Math.Floor((jd - Celsius_JD) * 60);
            if (Minute_JD < 10) //只有一位,补一个0
            {
                strMinute_JD = "0" + Minute_JD;
            }
            else
            {
                strMinute_JD = Minute_JD.ToString();
            }
            strMinute_JD += "′";


            var strDMSJD = string.Format("{0}{1}{2}", strCelsius_JD, strMinute_JD, tipJD);

            return(strDMSJD);
        }
Пример #3
0
        /// <summary>
        ///     转换经度为度格式
        /// </summary>
        /// <param name="longitude"></param>
        /// <returns></returns>
        public string FormatLongitudeToCelsiusHanzi(double longitude)
        {
            var jd    = longitude;
            var tipJD = string.Empty;

            if (jd >= 0) //东经E
            {
                tipJD = "E";
            }
            else
            {
                tipJD = "W";
                jd    = 0 - jd;
            }

            int    Celsius_JD, Minute_JD;
            string strCelsius_JD, strMinute_JD;
            var    strDMSJD = "";

            Celsius_JD = (int)Math.Floor(jd);
            if (Celsius_JD < 10) //只有一位,补两个0
            {
                strCelsius_JD = "00" + Celsius_JD;
            }
            else if (Celsius_JD < 100) //只有两位,补一个0
            {
                strCelsius_JD = "0" + Celsius_JD;
            }
            else
            {
                strCelsius_JD = Celsius_JD.ToString();
            }
            if ((jd - Celsius_JD) == 0)
            {
                strCelsius_JD += "度";
                strDMSJD       = string.Format("{0}{1}", strCelsius_JD, tipJD);
            }
            else
            {
                Minute_JD = (int)Math.Floor((jd - Celsius_JD) * 60);
                if (Minute_JD < 10) //只有一位,补一个0
                {
                    strMinute_JD = "0" + Minute_JD;
                    strDMSJD     = string.Format("{0}{1}{2}", strCelsius_JD + ".", strMinute_JD + "度", tipJD);
                }
                else
                {
                    if (Minute_JD >= 60)
                    {
                        Celsius_JD++;
                        if (Celsius_JD < 10) //只有一位,补两个0
                        {
                            strCelsius_JD = "00" + Celsius_JD;
                        }
                        else if (Celsius_JD < 100) //只有两位,补一个0
                        {
                            strCelsius_JD = "0" + Celsius_JD;
                        }
                        else
                        {
                            strCelsius_JD = Celsius_JD.ToString();
                        }

                        strDMSJD = string.Format("{0}{1}{2}", strCelsius_JD + ".", (Minute_JD - 60) + "度", tipJD);
                    }
                    else
                    {
                        strMinute_JD = Minute_JD.ToString();
                        strDMSJD     = string.Format("{0}{1}{2}", strCelsius_JD + ".", strMinute_JD + "度", tipJD);
                    }
                }
            }

            return(strDMSJD);
        }