mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-02-05 18:51:00 +08:00
[ocaml] fix SRTM download path (#2659)
SRTM data are no more available for direct download, using ESA data instead. The new SRTM data are SRTM3 GL1 (1 arcsec instead of 3 previously), so the code is now adapted to support both formats, the most accurate available will be used first. The only way to force the update of new files is to remove the previous ones from data/srtm folder. close #2642
This commit is contained in:
committed by
GitHub
parent
48c6128628
commit
80b2c91a39
Binary file not shown.
@@ -794,8 +794,8 @@ class widget = fun ?(height=800) ?(srtm=false) ?width ?projection ?georef () ->
|
||||
match GToolbox.question_box "SRTM" ["Download"; "Cancel"] msg with
|
||||
| 1 ->
|
||||
begin try
|
||||
let tile_zip = x^".hgt.zip" in
|
||||
let url = Srtm.srtm_url // (Srtm.area_of_tile x) // tile_zip in
|
||||
let tile_zip = x^".SRTMGL1.hgt.zip" in
|
||||
let url = Srtm.srtm_url // tile_zip in
|
||||
let dest = Env.paparazzi_home // "data" // "srtm" // tile_zip in
|
||||
let tmp_dest = Env.paparazzi_home // "var" // tile_zip in
|
||||
ignore(Http.file_of_url ~dest:tmp_dest url);
|
||||
|
||||
@@ -30,12 +30,14 @@ let (//) = Filename.concat
|
||||
type error = string
|
||||
exception Tile_not_found of string
|
||||
|
||||
let srtm_url = "http://dds.cr.usgs.gov/srtm/version2_1/SRTM3"
|
||||
let srtm_url = "http://step.esa.int/auxdata/dem/SRTMGL1"
|
||||
|
||||
let error = fun string ->
|
||||
Printf.sprintf "download %s/???/%s.hgt.zip in data/srtm/" srtm_url string
|
||||
Printf.sprintf "download %s/%s.SRTMGL1.hgt.zip in data/srtm/" srtm_url string
|
||||
|
||||
let tile_size = 1201
|
||||
let tile_coef = 1200. (* size for GL3, multiply by 3 for GL1 *)
|
||||
let tile_size_gl3 = 1201
|
||||
let tile_size_gl1 = 3601
|
||||
|
||||
(* Previously opened tiles *)
|
||||
let htiles = Hashtbl.create 13
|
||||
@@ -54,19 +56,31 @@ let find = fun tile ->
|
||||
let (bottom, left) = tile in
|
||||
let tile_name =
|
||||
Printf.sprintf "%c%.0f%c%03.0f" (if bottom >= 0. then 'N' else 'S') (abs_float bottom) (if left >= 0. then 'E' else 'W') (abs_float left) in
|
||||
try
|
||||
let f = open_compressed (tile_name ^".hgt") in
|
||||
let n = tile_size*tile_size*2 in
|
||||
let buf = Bytes.create n in
|
||||
really_input f buf 0 n;
|
||||
Hashtbl.add htiles tile buf;
|
||||
buf
|
||||
with Not_found ->
|
||||
raise (Tile_not_found tile_name)
|
||||
let f, n, factor =
|
||||
try
|
||||
let f = open_compressed (tile_name ^".SRTMGL1.hgt") in
|
||||
let n = tile_size_gl1*tile_size_gl1*2 in
|
||||
f, n, 3.
|
||||
with Not_found -> begin
|
||||
try
|
||||
let f = open_compressed (tile_name ^".hgt") in
|
||||
let n = tile_size_gl3*tile_size_gl3*2 in
|
||||
f, n, 1.
|
||||
with Not_found ->
|
||||
raise (Tile_not_found tile_name)
|
||||
end
|
||||
in
|
||||
let buf = Bytes.create n in
|
||||
really_input f buf 0 n;
|
||||
Hashtbl.add htiles tile (buf, factor);
|
||||
buf, factor
|
||||
|
||||
|
||||
let get = fun tile y x ->
|
||||
let tile = find tile in
|
||||
let tile, factor = find tile in
|
||||
let x = truncate (x*.factor*.tile_coef+.0.5)
|
||||
and y = truncate (y*.factor*.tile_coef+.0.5)
|
||||
and tile_size = truncate (factor*.tile_coef+.1.) in
|
||||
let pos = (2*((tile_size-y)*tile_size+x)) in
|
||||
(((Char.code (Bytes.get tile pos) land 127) lsl 8) lor Char.code (Bytes.get tile (pos+1))) - ((Char.code (Bytes.get tile pos) lsr 7) * 256 * 128)
|
||||
|
||||
@@ -75,7 +89,7 @@ let of_wgs84 = fun geo ->
|
||||
and long = (Rad>>Deg)geo.posn_long in
|
||||
let bottom = floor lat and left = floor long in
|
||||
let tile = (bottom, left) in
|
||||
get tile (truncate ((lat-.bottom)*.1200.+.0.5)) (truncate ((long-.left)*.1200.+.0.5))
|
||||
get tile (lat-.bottom) (long-.left)
|
||||
|
||||
let of_utm = fun utm ->
|
||||
of_wgs84 (Latlong.of_utm WGS84 utm)
|
||||
@@ -83,21 +97,6 @@ let of_utm = fun utm ->
|
||||
let available = fun geo ->
|
||||
try ignore(of_wgs84 geo); true with _ -> false
|
||||
|
||||
let area_of_tile = fun tile ->
|
||||
let area = open_compressed "srtm.data.bz2" in
|
||||
let rec _area_of_tile = fun () ->
|
||||
try
|
||||
let ib = Scanf.Scanning.from_channel area in
|
||||
Scanf.bscanf ib "%s %s\n" (fun t a ->
|
||||
if t = tile then a
|
||||
else _area_of_tile ())
|
||||
with
|
||||
| End_of_file -> raise (Tile_not_found tile)
|
||||
| _ -> _area_of_tile ()
|
||||
in
|
||||
_area_of_tile ()
|
||||
|
||||
|
||||
(* field size in bytes *)
|
||||
let field_size = 2
|
||||
(* srtm file line size in bytes *)
|
||||
|
||||
@@ -42,7 +42,5 @@ val of_utm : Latlong.utm -> int
|
||||
val of_wgs84 : Latlong.geographic -> int
|
||||
(** [of_wgs84 wgs84_pos] Returns the altitude of the given geographic position *)
|
||||
|
||||
val area_of_tile : string -> string
|
||||
|
||||
val horizon_slope : Latlong.geographic -> int -> float -> float -> float -> float
|
||||
(** [horizon_slope geo alt route half_aperture horizon] *)
|
||||
|
||||
Reference in New Issue
Block a user