class Node

Attributes

elevation[RW]
lat[RW]
lon[RW]
speed[RW]
timestamp[R]
xtile[R]
ytile[R]

Public Class Methods

new(id, time, lon, lat, elevation=0, zoom=nil) click to toggle source
# 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

Public Instance Methods

distanceto(lon, lat) click to toggle source
# 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) click to toggle source
# 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
getLatLonBox(size, offset_x, offset_y) click to toggle source
# 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
getfilenames(size, offset_x, offset_y) click to toggle source
# 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
toGPStime() click to toggle source
# File lib/fgmapping/tile.rb, line 106
def toGPStime()
        #2009-06-18T20:32:16Z
        return @timestamp.strftime("%Y-%m-%dT%H:%M:%SZ")
end
tofilename(cx=@xtile, cy=@ytile) click to toggle source
# File lib/fgmapping/tile.rb, line 44
def tofilename(cx=@xtile, cy=@ytile)
        return $MAPSHOME + "/#{@@zoom}/#{cx.to_i}/#{cy.to_i}"
end
tolat(setto) click to toggle source
# 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) click to toggle source
# File lib/fgmapping/tile.rb, line 84
def tolon(setto) 
        n = 2 ** @@zoom
        return (setto / n * 360.0 - 180.0)
end
toxtile() click to toggle source
# File lib/fgmapping/tile.rb, line 95
def toxtile()
        n = 2 ** @@zoom
        return ((@lon + 180.0) / 360.0) * n
end
toytile() click to toggle source
# 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
xtile=(setto) click to toggle source
# File lib/fgmapping/tile.rb, line 74
def xtile=(setto) 
        @xtile = setto
        @lon = tolon(setto)
end
ytile=(setto) click to toggle source
# File lib/fgmapping/tile.rb, line 79
def ytile=(setto)
        @ytile = setto
        @lat = tolat(setto)
end
zoom(zoomlevel) click to toggle source
# File lib/fgmapping/tile.rb, line 38
def zoom(zoomlevel)
        @@zoom = zoomlevel
        @xtile = toxtile
        @ytile = toytile
end