Convert Geo to Degree
Posted: Sun Oct 16, 2011 5:36 pm
Since in 'coding questions' is a thread about distance calculation on earth:
http://www.purebasic.fr/english/viewtop ... 13&t=47853
Only for your convenience:
Bernd
http://www.purebasic.fr/english/viewtop ... 13&t=47853
Only for your convenience:
Code: Select all
Procedure.f ConvertGeoToDeg(Value$)
Protected Result.f = 0.0
Protected Direction$
Protected Direction = 1
Protected Pos
ReplaceString(Value$, ",", ".", #PB_String_InPlace)
If FindString(Value$, "°", 1) = 0
ProcedureReturn ValF(Value$)
EndIf
ReplaceString(Value$, "''", #DQUOTE$ + " ", #PB_String_InPlace)
Direction$ = Left(Value$, 1)
If Direction$ > "A"
Value$ = Mid(Value$, 2)
Else
Direction$ = Right(Value$, 1)
EndIf
If Direction$ = "S" Or Direction$ = "W"
Direction = -1
EndIf
Pos = FindString(Value$, "°", 1)
If Pos
Result = Val(Value$)
Value$ = Mid(Value$, Pos + 1)
Pos = FindString(Value$, "'", 1)
If Pos
Result + (Val(Value$) / 60)
Value$ = Mid(Value$, Pos + 1)
Pos = FindString(Value$, #DQUOTE$, 1)
If Pos
Result + (ValF(Value$) / 3600)
EndIf
EndIf
EndIf
ProcedureReturn Result * Direction
EndProcedure
Debug ConvertGeoToDeg("16°19'28.29''")
Debug ConvertGeoToDeg("16° 19' 28.29'' S")
Debug ConvertGeoToDeg("S 16° 19' 28.29''")
Debug ConvertGeoToDeg("16.234")
Debug ConvertGeoToDeg("16,234")