Class: Node
- Inherits:
-
Object
- Object
- Node
- Defined in:
- lib/fgmapping/tile.rb
Constant Summary collapse
- @@zoom =
15
Instance Attribute Summary collapse
-
#elevation ⇒ Object
Returns the value of attribute elevation.
-
#lat ⇒ Object
Returns the value of attribute lat.
-
#lon ⇒ Object
Returns the value of attribute lon.
-
#speed ⇒ Object
Returns the value of attribute speed.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#xtile ⇒ Object
Returns the value of attribute xtile.
-
#ytile ⇒ Object
Returns the value of attribute ytile.
Instance Method Summary collapse
- #distanceto(lon, lat) ⇒ Object
- #distanceto_str(lon, lat) ⇒ Object
- #getfilenames(size, offset_x, offset_y) ⇒ Object
- #getLatLonBox(size, offset_x, offset_y) ⇒ Object
-
#initialize(id, time, lon, lat, elevation = 0, zoom = nil) ⇒ Node
constructor
A new instance of Node.
- #tofilename(cx = @xtile, cy = @ytile) ⇒ Object
- #toGPStime ⇒ Object
- #tolat(setto) ⇒ Object
- #tolon(setto) ⇒ Object
- #toxtile ⇒ Object
- #toytile ⇒ Object
- #zoom(zoomlevel) ⇒ Object
Constructor Details
#initialize(id, time, lon, lat, elevation = 0, zoom = nil) ⇒ Node
Returns a new instance of Node.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fgmapping/tile.rb', line 16 def initialize(id, time, lon, lat, elevation=0, zoom=nil) @id = id if time.kind_of? String then #2009-06-18T20:32:16Z time =~ /(\d*)-(\d*)-(\d*)T(\d*):(\d*):(\d*)Z(\d*)/ @timestamp = Time.local($1,$2,$3,$4,$5,$6,$7) else @timestamp = time end @lon = lon @lat = lat @elevation = elevation if !zoom.nil? then @@zoom = zoom end @xtile = toxtile @ytile = toytile # puts "Tiles: #{@xtile},#{@ytile}" @speed = 0 end |
Instance Attribute Details
#elevation ⇒ Object
Returns the value of attribute elevation.
11 12 13 |
# File 'lib/fgmapping/tile.rb', line 11 def elevation @elevation end |
#lat ⇒ Object
Returns the value of attribute lat.
11 12 13 |
# File 'lib/fgmapping/tile.rb', line 11 def lat @lat end |
#lon ⇒ Object
Returns the value of attribute lon.
11 12 13 |
# File 'lib/fgmapping/tile.rb', line 11 def lon @lon end |
#speed ⇒ Object
Returns the value of attribute speed.
11 12 13 |
# File 'lib/fgmapping/tile.rb', line 11 def speed @speed end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
11 12 13 |
# File 'lib/fgmapping/tile.rb', line 11 def @timestamp end |
#xtile ⇒ Object
Returns the value of attribute xtile.
11 12 13 |
# File 'lib/fgmapping/tile.rb', line 11 def xtile @xtile end |
#ytile ⇒ Object
Returns the value of attribute ytile.
11 12 13 |
# File 'lib/fgmapping/tile.rb', line 11 def ytile @ytile end |
Instance Method Details
#distanceto(lon, lat) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/fgmapping/tile.rb', line 111 def distanceto(lon, lat) lon1 = lon.rad lat1 = lat.rad lon2 = @lon.rad lat2 = @lat.rad begin return(Math.acos(Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1)) * 6371000) rescue Errno::EDOM return 0 end end |
#distanceto_str(lon, lat) ⇒ Object
123 124 125 126 127 128 129 130 |
# File 'lib/fgmapping/tile.rb', line 123 def distanceto_str(lon, lat) d = distanceto(lon, lat) if d < 2000 then return ("%.1f" % d) + "m" else return ("%.1f" % (d/1000.0)) + "km" end end |
#getfilenames(size, offset_x, offset_y) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/fgmapping/tile.rb', line 56 def getfilenames(size, offset_x, offset_y) fn=[] x = (size.width / 256 + 1) / 2 y = (size.height / 256 + 1) / 2 (-x..x).each {|ix| cx = @xtile + ix + offset_x cx = 2 ** @@zoom - 1 if cx < 0 cx = 0 if cx > 2 ** @@zoom - 1 (-y..y).each {|iy| cy = @ytile + iy + offset_y cy = 2 ** @@zoom - 1 if cy < 0 cy = 0 if cy > 2 ** @@zoom - 1 fn << tofilename(cx,cy) } } return fn end |
#getLatLonBox(size, offset_x, offset_y) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/fgmapping/tile.rb', line 48 def getLatLonBox(size, offset_x, offset_y) x = (size.width / 256 + 1) / 2 y = (size.height / 256 + 1) / 2 # add halve a tile at the borders to get to the border of each tile, not its center return [[tolon(@xtile + offset_x - x - 0.5), tolon(@xtile + offset_x + x + 0.5)], [tolat(@ytile + offset_y + y + 0.5), tolat(@ytile + offset_y - y - 0.5)]] end |
#tofilename(cx = @xtile, cy = @ytile) ⇒ Object
44 45 46 |
# File 'lib/fgmapping/tile.rb', line 44 def tofilename(cx=@xtile, cy=@ytile) return $MAPSHOME + "/#{@@zoom}/#{cx.to_i}/#{cy.to_i}" end |
#toGPStime ⇒ Object
106 107 108 109 |
# File 'lib/fgmapping/tile.rb', line 106 def toGPStime() #2009-06-18T20:32:16Z return @timestamp.strftime("%Y-%m-%dT%H:%M:%SZ") end |
#tolat(setto) ⇒ Object
89 90 91 92 93 |
# File 'lib/fgmapping/tile.rb', line 89 def tolat(setto) n = 2 ** @@zoom d = Math::PI - 2*Math::PI * setto / n return (180.0 / Math::PI * Math.atan(0.5 * (Math::exp(d) - Math::exp(-d)))) end |
#tolon(setto) ⇒ Object
84 85 86 87 |
# File 'lib/fgmapping/tile.rb', line 84 def tolon(setto) n = 2 ** @@zoom return (setto / n * 360.0 - 180.0) end |
#toxtile ⇒ Object
95 96 97 98 |
# File 'lib/fgmapping/tile.rb', line 95 def toxtile() n = 2 ** @@zoom return ((@lon + 180.0) / 360.0) * n end |
#toytile ⇒ Object
100 101 102 103 104 |
# File 'lib/fgmapping/tile.rb', line 100 def toytile() lat_rad = @lat/180.0 * Math::PI n = 2 ** @@zoom return (1.0 - (Math::log(Math::tan(lat_rad) + (1.0 / Math::cos(lat_rad))) / Math::PI)) / 2 * n end |
#zoom(zoomlevel) ⇒ Object
38 39 40 41 42 |
# File 'lib/fgmapping/tile.rb', line 38 def zoom(zoomlevel) @@zoom = zoomlevel @xtile = toxtile @ytile = toytile end |