wikipedia wrote:
There are three basic forms of a coordinate.
1. Coordinate containing degrees (integer), minutes (integer), and seconds (integer, or real number) (DMS).
2. Coordinate containing degrees (integer) and minutes (real number) (MinDec).
3. Coordinate containing only degrees (real number) (DegDec).
These functions convert the coordinates between these basic forms.
Valid Formats are:
Code:
DMS) 87° 43' 41.00'' N 87° 43' 41.00'' W
MinDec) 87° 43.68' N 87° 43.68' W
DegDec) 87.7280555556 -87.7280555556
More information on
wikipediaCode:
Convert_DMS2DegDec(DMSLat, DMSLon, ByRef DegDecLat, ByRef DegDecLon){
RegExMatch(DMSLat, "([snSN]?)(\d+)\D+(\d+)\D+([\d.]*)[^snSN]+([snSN]?)", Lat)
RegExMatch(DMSLon, "([weoWEO]?)(\d+)\D+(\d+)\D+([\d.]*)[^weoWEO]+([weoWEO]?)", Lon)
Save_FormatFloat := A_FormatFloat
SetFormat Float, 0.6
DegDecLat := (Lat2 + (Lat3 * 60 + Lat4) / 3600) * ((InStr(Lat1,"S") OR InStr(Lat5,"S")) ? -1 : 1)
DegDecLon := (Lon2 + (Lon3 * 60 + Lon4) / 3600) * ((InStr(Lon1,"W") OR InStr(Lon5,"W")) ? -1 : 1)
SetFormat Float, %Save_FormatFloat%
}
Convert_DMS2MinDec(DMSLat, DMSLon, ByRef MinDecLat, ByRef MinDecLon){
RegExMatch(DMSLat, "[snSN]?\d+\D+((\d+)\D+([\d.]*)'*)[^snSN]+[snSN]?", Lat)
RegExMatch(DMSLon, "[weoWEO]?\d+\D+((\d+)\D+([\d.]*)'*)[^weoWEO]+[weoWEO]?", Lon)
Save_FormatFloat := A_FormatFloat
SetFormat Float, 0.2
MinLat := Lat2 + Lat3 / 60
MinLon := Lon2 + Lon3 / 60
MinDecLat := RegExReplace(DMSLat, "([snSN]?\d+\D+)\d+\D+[\d.]*'*([^snSN]+[snSN]?)", "$1" MinLat "'$2")
MinDecLon := RegExReplace(DMSLon, "([weoWEO]?\d+\D+)\d+\D+[\d.]*'*([^weoWEO]+[weoWEO]?)", "$1" MinLon "'$2")
SetFormat Float, %Save_FormatFloat%
}
Convert_DegDec2DMS(DegLat, DegLon, ByRef DMS1, ByRef DMS2){
Dir1 := (DegLat > 0 ? "N" : (DegLat < 0 ? "S" : ""))
Dir2 := (DegLon > 0 ? "E" : (DegLon < 0 ? "W" : ""))
Save_FormatFloat := A_FormatFloat
Loop,2{
SetFormat Float, 0.99
DegDec := Abs(A_Index = 1 ? DegLat : DegLon)
Deg := Floor(DegDec)
Fract := (DegDec - Deg) * 60
Min := Floor(Fract)
SetFormat Float, 0.2
Sec := (Fract - Min) * 60
DMS%A_Index% := Deg "° " Min "' " Sec "'' " Dir%A_Index%
}
SetFormat Float, %Save_FormatFloat%
}
Convert_DegDec2MinDec(DegLat, DegLon, ByRef MinDec1, ByRef MinDec2){
Dir1 := (DegLat > 0 ? "N" : (DegLat < 0 ? "S" : ""))
Dir2 := (DegLon > 0 ? "E" : (DegLon < 0 ? "W" : ""))
Save_FormatFloat := A_FormatFloat
Loop,2{
SetFormat Float, 0.99
DegDec := Abs(A_Index = 1 ? DegLat : DegLon)
Deg := Floor(DegDec)
SetFormat Float, 0.2
Min := (DegDec - Deg) * 60
MinDec%A_Index% := Deg "° " Min "' " Dir%A_Index%
}
SetFormat Float, %Save_FormatFloat%
}
Convert_MinDec2DMS(MinDecLat, MinDecLon, ByRef DMSLat, ByRef DMSLon){
RegExMatch(MinDecLat, "[snSN]?\d+\D+([\d.]*)[^snSN]+[snSN]?", Lat)
RegExMatch(MinDecLon, "[weoWEO]?\d+\D+([\d.]*)[^weoWEO]+[weoWEO]?", Lon)
MinLat := Floor(Lat1)
MinLon := Floor(Lon1)
Save_FormatFloat := A_FormatFloat
SetFormat Float, 0.2
SecLat := (Lat1 - MinLat) * 60
SecLon := (Lon1 - MinLon) * 60
DMSLat := RegExReplace(MinDecLat, "([snSN]?\d+\D+)[\d.]*([^snSN]+[snSN]?)", "$1" MinLat "' " SecLat "'$2")
DMSLon := RegExReplace(MinDecLon, "([weoWEO]?\d+\D+)[\d.]*([^weoWEO]+[weoWEO]?)", "$1" MinLat "' " SecLon "'$2")
SetFormat Float, %Save_FormatFloat%
}
Convert_MinDec2DegDec(MinDecLat, MinDecLon, ByRef DegDecLat, ByRef DegDeclon){
RegExMatch(MinDecLat, "([snSN]?)(\d+)\D+([\d.]*)[^snSN]+([snSN]?)", Lat)
RegExMatch(MinDecLon, "([weoWEO]?)(\d+)\D+([\d.]*)[^weoWEO]+([weoWEO]?)", Lon)
Save_FormatFloat := A_FormatFloat
SetFormat Float, 0.6
DegDecLat := (Lat2 + Lat3 / 60) * ((InStr(Lat1,"S") OR InStr(Lat4,"S")) ? -1 : 1)
DegDecLon := (Lon2 + Lon3 / 60) * ((InStr(Lon1,"W") OR InStr(Lon4,"W")) ? -1 : 1)
SetFormat Float, %Save_FormatFloat%
}