'************************************************************************************
'
'This procedure converts a latitude/longitude string to a double
'
'Input parameters are:
'
' Lat_long_string = latitude/longitude string, in any of following formats:
' [+-]DDD.DDDDD
' [+-]DDD:MM.MMMMM
' [+-]DDD:MM:SS.SSSSS
'
'Returns:
'
' Numeric equivalent, as a Double
'
'Notes on this procedure:
'
' o None
'
'************************************************************************************
Private Sub Util_convert_lat_long(Lat_long_string As String) As Double
Private wrk_sign, wrk_DD, wrk_MM, wrk_SS As Double
Private wrk_ptr As Int
Lat_long_string = Lat_long_string.Trim
'Sign stuff has to be done this way to handle cases such as -0:MM.MMMMM,
'-:MM.MMMMM etc
'Assume +ve
wrk_sign = 1
'If -ve...
If Lat_long_string.SubString2(0,1) = "-" Then
'Set sign to -ve
wrk_sign = -1
'Lop off [-]
Lat_long_string = Lat_long_string.SubString(1)
End If
'Find location of first :
wrk_ptr = Lat_long_string.IndexOf(":")
'If have [+]DDD:MM.MMMMM or DDD:MM:SS.SSSSS...
If wrk_ptr > -1 Then
'Extract absolute DDD
Try
wrk_DD = Lat_long_string.SubString2(0, wrk_ptr)
Catch
wrk_DD = 0
End Try
'Lop off [+]DDD:
Lat_long_string = Lat_long_string.SubString(wrk_ptr + 1)
'Find location of second :
wrk_ptr = Lat_long_string.IndexOf(":")
'If have MM:SS.SSSSS...
If wrk_ptr > -1 Then
'Extract absolute MM
Try
wrk_MM = Lat_long_string.SubString2(0, wrk_ptr)
Catch
wrk_MM = 0
End Try
'Extract absolute SS.SSSSS
Try
wrk_SS = Lat_long_string.SubString(wrk_ptr + 1)
Catch
wrk_SS = 0
End Try
'Otherwise, must have MM.MMMMM...
Else
'Extract absolute MM.MMMMM
Try
wrk_MM = Lat_long_string
Catch
wrk_MM = 0
End Try
End If
'Otherwise, must have [+]DDD.DDDDD...
Else
'Extract [+]DDD.DDDDD
Try
wrk_DD = Lat_long_string
Catch
wrk_DD = 0
End Try
End If
Return wrk_sign * (wrk_DD + wrk_MM/60 + wrk_SS/3600)
End Sub