Display of IGN tiles

This commit is contained in:
Pascal Brisset
2006-03-10 13:23:36 +00:00
parent 0934d7cda3
commit 1679bc1b2c
8 changed files with 198 additions and 13 deletions
+13 -9
View File
@@ -448,20 +448,22 @@ let active_gm_auto = fun x ->
gm_auto := x
let button_press = fun (geomap:MapCanvas.widget) ev ->
if GdkEvent.Button.button ev = 3 then
if GdkEvent.Button.button ev = 3 then begin
let xc = GdkEvent.Button.x ev
and yc = GdkEvent.Button.y ev in
let (xw,yw) = geomap#window_to_world xc yc in
let wgs84 = geomap#of_world (xw,yw) in
let (xw',yw') = geomap#world_of wgs84 in
ignore(Thread.create (fun geo ->
try ignore (MapGoogle.display_tile geomap geo) with
Gm.Not_available -> ())
wgs84);
false
else
false
let display = fun geo ->
if Gdk.Convert.test_modifier `SHIFT (GdkEvent.Button.state ev) then
MapIGN.display_tile geomap geo
else
try ignore (MapGoogle.display_tile geomap geo) with
Gm.Not_available -> () in
ignore(Thread.create display wgs84)
end;
false
let fill_gm_tiles = fun geomap -> ignore (Thread.create MapGoogle.fill_window geomap)
@@ -480,6 +482,8 @@ let _ =
[ "-b", Arg.String (fun x -> ivy_bus := x), "Bus\tDefault is 127.255.255.25:2010";
"-ref", Arg.Set_string geo_ref, "Geographic ref (default '')";
"-mercator", Arg.Unit (fun () -> projection:=MapCanvas.Mercator),"Switch to (Google Maps) Mercator projection";
"-lambertIIe", Arg.Unit (fun () -> projection:=MapCanvas.LambertIIe),"Switch to LambertIIe projection";
"-ign", Arg.Set_string IGN.data_path, "IGN tiles path";
"-m", Arg.String (fun x -> map_file := x), "Map description file"] in
Arg.parse (options)
(fun x -> Printf.fprintf stderr "Warning: Don't do anythig with %s\n" x)
+2 -2
View File
@@ -26,11 +26,11 @@ OCAMLC=ocamlc $(INCLUDES)
OCAMLOPT=ocamlopt $(INCLUDES)
SRC = debug.ml env.ml serial.ml ocaml_tools.ml extXml.ml xml2h.ml latlong.ml srtm.ml http.ml gm.ml wavecard.ml geometry_2d.ml geometry_3d.ml cserial.o convert.o ubx.ml pprz.ml
SRC = debug.ml env.ml serial.ml ocaml_tools.ml extXml.ml xml2h.ml latlong.ml srtm.ml http.ml gm.ml iGN.ml wavecard.ml geometry_2d.ml geometry_3d.ml cserial.o convert.o ubx.ml pprz.ml
CMO = $(SRC:.ml=.cmo)
CMX = $(SRC:.ml=.cmx)
XSRC = platform.ml gtkgl_Hack.ml ml_gtkgl_hack.o gtk_image.ml gtk_tools_icons.ml gtk_tools.ml gtk_draw.ml gtk_tools_GL.ml gtk_3d.ml mapCanvas.ml mapWaypoints.ml mapTrack.ml mapGoogle.ml ml_gtk_drag.o xmlEdit.ml
XSRC = platform.ml gtkgl_Hack.ml ml_gtkgl_hack.o gtk_image.ml gtk_tools_icons.ml gtk_tools.ml gtk_draw.ml gtk_tools_GL.ml gtk_3d.ml mapCanvas.ml mapWaypoints.ml mapTrack.ml mapGoogle.ml mapIGN.ml ml_gtk_drag.o xmlEdit.ml
XCMO = $(XSRC:.ml=.cmo)
XCMX = $(XSRC:.ml=.cmx)
+69
View File
@@ -0,0 +1,69 @@
(*
* $Id$
*
* Handling IGN tiles
*
* Copyright (C) 2004-2006 ENAC, Pascal Brisset, Antoine Drouin
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*)
let (//) = Filename.concat
module LL = Latlong
type tile_t = {
key : int * int; (* LambertIIe meters / size_m *)
sw_corner : Latlong.geographic;
ne_corner : Latlong.geographic
};;
let size_px = 250
let size_m = (size_px * 25) / 10
let tile_size = size_px , size_px
let data_path = ref "/path_to_ign_files"
let tile_of_geo = fun wgs84 ->
let lbt = LL.lambertIIe_of wgs84 in
let kx = lbt.LL.lbt_x / size_m
and ky = lbt.LL.lbt_y / size_m in
let x0 = kx * size_m and y0 = ky * size_m in
let x1 = x0 + size_m and y1 = y0 + size_m in
let sw_corner= LL.of_lambertIIe {LL.lbt_x=x0; lbt_y=y0}
and ne_corner = LL.of_lambertIIe {LL.lbt_x=x1; lbt_y=y1} in
{ key = (kx, ky);
sw_corner = sw_corner;
ne_corner = ne_corner }
let get_tile = fun tile ->
let (kx, ky) = tile.key in
let dalle_x = (kx * size_m) / 10000
and dalle_y = 267 - ((ky*size_m) / 10000) in
let file = !data_path // Printf.sprintf "F%03d_%03d.png" dalle_x dalle_y in
let tmp_file = Filename.temp_file "ign" ".png" in
let ix = (kx mod (10000 / size_m)) * size_px
and iy = 4000 - size_px - ((ky mod (10000 / size_m)) * size_px) in
let sub_tile = Printf.sprintf "convert -crop %dx%d+%d+%d %s %s" size_px size_px ix iy file tmp_file in
let x = Sys.command sub_tile in
if x <> 0 then failwith sub_tile;
tmp_file
+41
View File
@@ -0,0 +1,41 @@
(*
* $Id$
*
* Handling IGN tiles
*
* Copyright (C) 2004-2006 ENAC, Pascal Brisset, Antoine Drouin
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*)
val tile_size : int * int (** Pixels *)
type tile_t = {
key : int * int; (* LambertIIe meters / size *)
sw_corner : Latlong.geographic;
ne_corner : Latlong.geographic
};;
val data_path : string ref
(** Where to find the original tiles *)
val tile_of_geo : Latlong.geographic -> tile_t
val get_tile : tile_t -> string
(** Returns the filename of the given tile *)
+1 -1
View File
@@ -352,7 +352,7 @@ let lambertIIe_of = fun wgs84 ->
let lbt_add = fun {lbt_x=x; lbt_y=y} (dx, dy) ->
{lbt_x = x + truncate dx; lbt_y = y + truncate dy }
let lbt_sub = fun {lbt_x=x1; lbt_y=y1} {lbt_x=x2; lbt_y=y2} ->
(float (x2-x1), float (y2-y1))
(float (x1-x2), float (y1-y2))
let space = Str.regexp "[ \t]+"
let fos = float_of_string
+2 -1
View File
@@ -81,7 +81,8 @@ let display_the_tile = fun geomap tile jpg_file ->
and east_long = west_long +. tile.Gm.width in
let ne = { LL.posn_lat = north_lat; posn_long = east_long } in
let map = geomap#display_pixbuf ((0,256), tile.Gm.sw_corner) ((256,0),ne) (GdkPixbuf.from_file jpg_file) in
let (tx, ty) = Gm.tile_size in
let map = geomap#display_pixbuf ((0,tx), tile.Gm.sw_corner) ((ty,0),ne) (GdkPixbuf.from_file jpg_file) in
map#raise 1;
add_tile tile.Gm.key
+43
View File
@@ -0,0 +1,43 @@
(*
* $Id$
*
* Displaying IGN Maps on a MapCanvas object
*
* Copyright (C) 2004-2006 ENAC, Pascal Brisset, Antoine Drouin
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*)
module LL = Latlong
let displayed_tiles = Hashtbl.create 41
let mem_tile = fun t -> Hashtbl.mem displayed_tiles t.IGN.key
let add_tile = fun t -> Hashtbl.add displayed_tiles t.IGN.key ()
(** Displaying the tile around the given point *)
let display_tile = fun (geomap:MapCanvas.widget) wgs84 ->
let tile = IGN.tile_of_geo wgs84 in
if not (mem_tile tile) then
let jpg_file = IGN.get_tile tile in
let (sx,sy) = IGN.tile_size in
let map = geomap#display_pixbuf ((0,sx), tile.IGN.sw_corner) ((sy,0),tile.IGN.ne_corner) (GdkPixbuf.from_file jpg_file) in
map#raise 1;
add_tile tile
+27
View File
@@ -0,0 +1,27 @@
(*
* $Id$
*
* Displaying IGN Maps on a MapCanvas object
*
* Copyright (C) 2004-2006 ENAC, Pascal Brisset, Antoine Drouin
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*)
val display_tile : MapCanvas.widget -> Latlong.geographic -> unit