diff --git a/sw/lib/ocaml/latlong.ml b/sw/lib/ocaml/latlong.ml index fd2d834933..24480e6dc3 100644 --- a/sw/lib/ocaml/latlong.ml +++ b/sw/lib/ocaml/latlong.ml @@ -456,6 +456,19 @@ let of_string = fun s -> let string_of = fun geo -> Printf.sprintf "WGS84 %s" (string_degrees_of_geographic geo) +let deg_of_string = fun s -> + match Str.split space s with + [lat_d; lat_m; lat_s] -> + decimal (ios lat_d) (ios lat_m) (fos lat_s) + | [lat_d; lat_m; lat_s; hemi] -> + let sign = + match hemi with + "N" | "E" -> 1. | "S" | "W" -> -1. + | _ -> failwith (Printf.sprintf "N or S expected for hemispere in dms, found '%s'" hemi) in + sign *. decimal (ios lat_d) (ios lat_m) (fos lat_s) + | [deg] -> float_of_string deg + | _ -> invalid_arg (Printf.sprintf "Latlong.of_string: %s" s) + let mercator_lat = fun l -> log (tan (pi/.4. +. 0.5*. l)) let inv_mercator_lat = fun l -> 2. *. atan (exp l) -. pi/.2. diff --git a/sw/lib/ocaml/latlong.mli b/sw/lib/ocaml/latlong.mli index 044a6b888e..99add23629 100644 --- a/sw/lib/ocaml/latlong.mli +++ b/sw/lib/ocaml/latlong.mli @@ -137,6 +137,8 @@ val of_string : string -> geographic (** [of_string pos] Parses [pos] as "WGS84 45.678 1.2345", "UTM 500123 4500300 31" or "LBT2e 544945 1755355" *) val string_of : geographic -> string (** Returns a "WGS84" annotated string *) +val deg_of_string : string -> float +(** Parse a deg min sec or a decimal angle *) val mercator_lat : float -> float (** wgs84 -> [-pi; pi] *)