Degrees Minutes Seconds to Decimal Degrees

This Page is locked
Modified: 2007/06/05 15:46 by ViaVE Visitor
Useful little function for converting from dms (where seconds is 4 digits) string to decimal degrees for VE

        private double degreesMinutesSecondsToDecimal(string degminsec)
        {
            //Divide the number of seconds by 60, 28.79 ÷ 60 = 0.5166. 
            //Add the result to the number of minutes, 31 + .47983. 
            //Divide the result by 60, 31.47983 ÷ 60 = 0.52466383. 
            //Now add that to the number degrees, 48 + .52466383. 
            //The result is 48.52466383° 

double seconds = Double.Parse(degminsec.Substring(degminsec.Length - 4, 4)); double minutes = Double.Parse(degminsec.Substring(degminsec.Length - 6, 2)); double degrees = Double.Parse(degminsec.Substring(0, degminsec.Length - 6));

if (degrees > 0) { return (((seconds / 6000) + minutes) / 60) + degrees; } else { return degrees - (((seconds / 6000) + minutes) / 60); } }

Private Function degreesMinutesSecondsToDecimal(ByVal degminsec As String) As Double ' Divide the number of seconds by 60, 28.79 ÷ 60 = 0.5166. ' Add the result to the number of minutes, 31 + .47983. ' Divide the result by 60, 31.47983 ÷ 60 = 0.52466383. ' Now add that to the number degrees, 48 + .52466383. ' The result is 48.52466383° Dim seconds As Double = Double.Parse(degminsec.Substring(degminsec.Length - 4, 4)) Dim minutes As Double = Double.Parse(degminsec.Substring(degminsec.Length - 6, 2)) Dim degrees As Double = Double.Parse(degminsec.Substring(0, degminsec.Length - 6)) If degrees > 0 Then Return (((seconds / 6000) + minutes) / 60) + degrees Else Return degrees - (((seconds / 6000) + minutes) / 60) End If End Function