fgmapping 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,216 @@
1
+ SPEED_AVG_TIME_SEC = 10 # time in sec over which the speed is being averaged
2
+
3
+ class Float
4
+ def rad
5
+ return self / 180.0 * Math::PI
6
+ end
7
+ end
8
+
9
+
10
+ class Node
11
+ attr_reader :xtile, :ytile, :lat, :lon, :elevation, :timestamp, :speed
12
+ attr_writer :lat, :lon, :elevation, :speed
13
+
14
+ @@zoom=15
15
+
16
+ def initialize(id, time, lon, lat, elevation=0, zoom=nil)
17
+ @id = id
18
+ if time.kind_of? String then
19
+ #2009-06-18T20:32:16Z
20
+ time =~ /(\d*)-(\d*)-(\d*)T(\d*):(\d*):(\d*)Z/
21
+ @timestamp = Time.local($1,$2,$3,$4,$5,$6)
22
+ else
23
+ @timestamp = time
24
+ end
25
+ @lon = lon
26
+ @lat = lat
27
+ @elevation = elevation
28
+
29
+ if !zoom.nil? then
30
+ @@zoom = zoom
31
+ end
32
+ @xtile = toxtile
33
+ @ytile = toytile
34
+ # puts "Tiles: #{@xtile},#{@ytile}"
35
+ @speed = 0
36
+ end
37
+
38
+ def zoom(zoomlevel)
39
+ @@zoom = zoomlevel
40
+ @xtile = toxtile
41
+ @ytile = toytile
42
+ end
43
+
44
+ def tofilename(cx=@xtile, cy=@ytile)
45
+ return $MAPSHOME + "/#{@@zoom}/#{cx.to_i}/#{cy.to_i}"
46
+ end
47
+
48
+ def getLatLonBox(size, offset_x, offset_y)
49
+ x = (size.width / 256 + 1) / 2
50
+ y = (size.height / 256 + 1) / 2
51
+ # add halve a tile at the borders to get to the border of each tile, not its center
52
+ return [[tolon(@xtile + offset_x - x - 0.5), tolon(@xtile + offset_x + x + 0.5)],
53
+ [tolat(@ytile + offset_y + y + 0.5), tolat(@ytile + offset_y - y - 0.5)]]
54
+ end
55
+
56
+ def getfilenames(size, offset_x, offset_y)
57
+ fn=[]
58
+ x = (size.width / 256 + 1) / 2
59
+ y = (size.height / 256 + 1) / 2
60
+ (-x..x).each {|ix|
61
+ cx = @xtile + ix + offset_x
62
+ cx = 2 ** @@zoom - 1 if cx < 0
63
+ cx = 0 if cx > 2 ** @@zoom - 1
64
+ (-y..y).each {|iy|
65
+ cy = @ytile + iy + offset_y
66
+ cy = 2 ** @@zoom - 1 if cy < 0
67
+ cy = 0 if cy > 2 ** @@zoom - 1
68
+ fn << tofilename(cx,cy)
69
+ }
70
+ }
71
+ return fn
72
+ end
73
+
74
+ def xtile=(setto)
75
+ @xtile = setto
76
+ @lon = tolon(setto)
77
+ end
78
+
79
+ def ytile=(setto)
80
+ @ytile = setto
81
+ @lat = tolat(setto)
82
+ end
83
+
84
+ def tolon(setto)
85
+ n = 2 ** @@zoom
86
+ return (setto / n * 360.0 - 180.0)
87
+ end
88
+
89
+ def tolat(setto)
90
+ n = 2 ** @@zoom
91
+ d = Math::PI - 2*Math::PI * setto / n
92
+ return (180.0 / Math::PI * Math.atan(0.5 * (Math::exp(d) - Math::exp(-d))))
93
+ end
94
+
95
+ def toxtile()
96
+ n = 2 ** @@zoom
97
+ return ((@lon + 180.0) / 360.0) * n
98
+ end
99
+
100
+ def toytile()
101
+ lat_rad = @lat/180.0 * Math::PI
102
+ n = 2 ** @@zoom
103
+ return (1.0 - (Math::log(Math::tan(lat_rad) + (1.0 / Math::cos(lat_rad))) / Math::PI)) / 2 * n
104
+ end
105
+
106
+ def toGPStime()
107
+ #2009-06-18T20:32:16Z
108
+ return @timestamp.strftime("%Y-%m-%dT%H:%M:%SZ")
109
+ end
110
+
111
+ def distanceto(lon, lat)
112
+ lon1 = lon.rad
113
+ lat1 = lat.rad
114
+ lon2 = @lon.rad
115
+ lat2 = @lat.rad
116
+ begin
117
+ return(Math.acos(Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1)) * 6371000)
118
+ rescue Errno::EDOM
119
+ return 0
120
+ end
121
+ end
122
+
123
+ def distanceto_str(lon, lat)
124
+ d = distanceto(lon, lat)
125
+ if d < 2.0 then
126
+ return ("%.1f" % d) + "m"
127
+ else
128
+ return ("%.1f" % (d/1000.0)) + "km"
129
+ end
130
+ end
131
+
132
+ end
133
+
134
+
135
+ class Way
136
+ attr_reader :nodes, :currentwp, :color, :path
137
+ attr_writer :currentwp, :path
138
+
139
+ def initialize(id, user, time, color)
140
+ @id = id
141
+ @user = user
142
+ @color = color
143
+ if time.kind_of? String then
144
+ #2009-06-18T20:32:16Z
145
+ time =~ /(\d*)-(\d*)-(\d*)T(\d*):(\d*):(\d*)Z/
146
+ @timestamp = Time.local($1,$2,$3,$4,$5,$6)
147
+ else
148
+ @timestamp = time
149
+ end
150
+ @nodes=[]
151
+ @currentwp=nil
152
+ end
153
+
154
+ def <<(node)
155
+ i=@nodes.index(nil)
156
+ if i.nil? then
157
+ @nodes << node
158
+ check_nodes = @nodes[-10, 10]
159
+ if check_nodes.nil? then
160
+ check_nodes = @nodes
161
+ end
162
+ avg_nodes = check_nodes.find_all{|n|
163
+ (node.timestamp - n.timestamp) <= SPEED_AVG_TIME_SEC
164
+ }
165
+ speeds=[]
166
+ t_diff = 0
167
+ avg_nodes.each_with_index{|n, i|
168
+ if i>0 then
169
+ t_diff = n.timestamp - avg_nodes[i-1].timestamp
170
+ if t_diff > 0 then
171
+ speeds << n.distanceto(avg_nodes[i-1].lon, avg_nodes[i-1].lat) / t_diff
172
+ end
173
+ end
174
+ }
175
+ if speeds.length > 0 then
176
+ avg_speed = speeds.inject(0){ |result, element| result + element } / speeds.length * 3.6
177
+ else
178
+ avg_speed = 0
179
+ end
180
+ node.speed = avg_speed
181
+ @nodes.length
182
+ else
183
+ @nodes[i]=node
184
+ i+1
185
+ end
186
+ end
187
+
188
+ def del(lon,lat)
189
+ diff=[]
190
+ @nodes.each{|n|
191
+ diff << [ Math::sqrt((n.lat - lat) ** 2 + (n.lon - lon) ** 2) , n.lat, n.lon] if !n.nil?
192
+ }
193
+ mindist=999.0
194
+ min=nil
195
+ diff.each{|i|
196
+ if i[0] < mindist then
197
+ mindist = i[0]
198
+ min=i
199
+ end
200
+ }
201
+ deleted=nil
202
+ @nodes.each_index {|i|
203
+ if (!@nodes[i].nil?) and (@nodes[i].lat == min[1]) and (@nodes[i].lon == min[2]) then
204
+ @nodes[i]=nil
205
+ deleted=i
206
+ end
207
+ }
208
+ return deleted+1
209
+ end
210
+
211
+ def toGPStime()
212
+ #2009-06-18T20:32:16Z
213
+ return @timestamp.strftime("%Y-%m-%dT%H:%M:%SZ")
214
+ end
215
+
216
+ end
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ ##################################################
3
+ # Flightgear Mapping
4
+ #
5
+ # Provide a real-time map of flight position in Flightgear. It is based on tiles from Openstreetmap,
6
+ # downloads them in the background, provides navigation aids and runways, allows setting of waypoints
7
+ # and tracks the flight.
8
+ #
9
+ # License
10
+ # GPL V2
11
+ #
12
+ # Author Michael Meltner (mmeltner@gmail.com)
13
+ ##################################################
14
+
15
+ Dir.chdir(File.dirname(__FILE__))
16
+ require "rubygems"
17
+ require "Qt4"
18
+ require "main-dlg-impl.rb"
19
+
20
+ a = Qt::Application.new(ARGV)
21
+ u = Qt::MainWindow.new
22
+
23
+ w = MainDlg.new(u, ARGV[0])
24
+ u.resize(w.size) # set Mainwindow to correct size
25
+ u.setCentralWidget(w) # make widget part of the mainwindow to allow resizing
26
+ u.show
27
+ w.movemap(w.node,true)
28
+
29
+ a.exec
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fgmapping
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 1
9
+ version: 1.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Michael Meltner
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-06-11 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Flightgear live mapping
22
+ email: mmeltner @nospamplease@ gmail.com
23
+ executables:
24
+ - flightgear-mapping
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - CHANGELOG
29
+ - LICENSE
30
+ - README
31
+ - bin/flightgear-mapping
32
+ - lib/LICENSE
33
+ - lib/README
34
+ - lib/bsearch.rb
35
+ - lib/hud-impl.rb
36
+ - lib/hud-widget.rb
37
+ - lib/init.rb
38
+ - lib/main-dlg-impl.rb
39
+ - lib/main-dlg.rb
40
+ - lib/navaid.rb
41
+ - lib/nodeinfo-impl.rb
42
+ - lib/nodeinfo-widget.rb
43
+ - lib/resources.rb
44
+ - lib/tile.rb
45
+ - lib/waypoint.rb
46
+ files:
47
+ - CHANGELOG
48
+ - LICENSE
49
+ - Manifest
50
+ - README
51
+ - Rakefile
52
+ - bin/flightgear-mapping
53
+ - fgmap.gemspec
54
+ - fgmapping.gemspec
55
+ - lib/LICENSE
56
+ - lib/README
57
+ - lib/bsearch.rb
58
+ - lib/hud-impl.rb
59
+ - lib/hud-widget.rb
60
+ - lib/init.rb
61
+ - lib/main-dlg-impl.rb
62
+ - lib/main-dlg.rb
63
+ - lib/navaid.rb
64
+ - lib/nodeinfo-impl.rb
65
+ - lib/nodeinfo-widget.rb
66
+ - lib/resources.rb
67
+ - lib/tile.rb
68
+ - lib/waypoint.rb
69
+ has_rdoc: true
70
+ homepage: http://rubyforge.org/projects/fgmap
71
+ licenses: []
72
+
73
+ post_install_message:
74
+ rdoc_options:
75
+ - --line-numbers
76
+ - --inline-source
77
+ - --title
78
+ - Fgmapping
79
+ - --main
80
+ - README.build_gem
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ segments:
95
+ - 1
96
+ - 2
97
+ version: "1.2"
98
+ requirements: []
99
+
100
+ rubyforge_project: fgmapping
101
+ rubygems_version: 1.3.6
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Flightgear live mapping
105
+ test_files: []
106
+