1
2
3
4 """ Tool for finding node ids by clicking on a GUI map
5 - load a map into gui (libchamplain based)
6 - on click, next available way node is shown and information written to stderr
7 - map is not centered/zoomed, user has to move to map
8 """
9
10 import champlain
11 import clutter
12 import math
13 import gobject
14
15 import select
16 import sys
17 sys.path.append("..")
18
19 from mosp.geo.utm import utm_to_latlong, latlong_to_utm
20 from mosp.geo import osm, utils
21
22 __author__ = "F. Ludwig"
23 __copyright__ = "(c) 2010-2011, DCSec, Leibniz Universitaet Hannover, Germany"
24 __license__ = "GPLv3"
25 __status__ = "unmaintained"
26
27
28 MARKER_SIZE = 10
29 DEFAULT_MARKER_COLOR = [0.1,0.1,0.9,1.0]
30 POSITION = [52.381790828929, 9.719464266585755]
31 SCREEN_SIZE = [800, 600]
32
33
35 """The AnimatedMarker will extend the champlain.Marker class"""
52
53
54
55
57 """Map GUI visualization.
58 @author: F. Ludwig"""
59
61 """Update GUI and stderr output."""
62 s = select.select([sys.stdin], [], [], 0.0)
63 while s[0]:
64 t, id, x, y = [int(i) for i in sys.stdin.readline().split(' ')]
65 coords = utm_to_latlong(x, y, self.zone)
66 self.markers[id].set_position(coords[1], coords[0])
67 print id, t, x, y
68 print coords
69 s = select.select([sys.stdin], [], [], 0.0)
70
71 gobject.timeout_add(200, self.update)
72
73
75 """Resize actor."""
76 self.actor.set_size(int(stage.get_width()), int(stage.get_height()))
77 print "\n\n\n\n\n\n", stage.get_allocation_box(), "\n\n\n\n\n\n\n\n\n"
78
79
81 """Node finder main loads map and inits the GUI."""
82 self.data = osm.OSMModel('../data/hannover2.osm')
83 self.data.initialize(self.data)
84 global markers
85 gobject.threads_init()
86 clutter.init()
87 stage = clutter.Stage(default=True)
88 self.actor = champlain.View()
89 layer = champlain.Layer()
90 self.marker = AnimatedMarker()
91 layer.add(self.marker)
92
93 stage.set_user_resizable(True)
94 stage.connect("allocation-changed", self.resize_actor)
95 stage.connect("button-press-event", self.button_pressed)
96
97 stage.set_size(*SCREEN_SIZE)
98 self.actor.set_size(*SCREEN_SIZE)
99 stage.add(self.actor)
100
101 layer.show()
102 self.actor.add_layer(layer)
103
104
105 self.actor.set_property("zoom-level", 16)
106 self.actor.set_property("scroll-mode", champlain.SCROLL_MODE_KINETIC)
107 self.actor.center_on(*POSITION)
108
109 stage.show()
110
111 clutter.main()
112
121 nearest = self.data.way_nodes[0]
122 nearest_dist = utils.distance(Node, nearest)
123 for node in self.data.way_nodes:
124 if utils.distance(Node, node) < nearest_dist:
125 nearest = node
126 nearest_dist = utils.distance(Node, node)
127
128 print
129 print "==========KLICK=========="
130 print nearest, nearest_dist
131 print coords
132 self.marker.set_position(nearest.lat, nearest.lon)
133
134
136 """Starts a libchamplain-based Finder (map GUI) and its main methods."""
137 f = Finder()
138 f.main()
139
140
141 if __name__ == '__main__':
142 main()
143