class GlobalMapTiles::GlobalGeodetic
Functions necessary for generation of global tiles in Plate Carre projection, EPSG:4326, “unprojected profile”.
Public Class Methods
new(tile_size = 256)
click to toggle source
# File lib/global_map_tiles/global_geodetic.rb, line 4 def initialize(tile_size = 256) @tile_size = tile_size end
Public Instance Methods
lon_lat_to_pixels(lon, lat, zoom)
click to toggle source
Converts lon/lat to pixel coordinates in given zoom of the EPSG:4326 pyramid
# File lib/global_map_tiles/global_geodetic.rb, line 9 def lon_lat_to_pixels(lon, lat, zoom) res = 180 / 256.0 / 2**zoom px = (180 + lat) / res py = (90 + lon) / res [px, py] end
pixels_to_tile(px, py)
click to toggle source
Returns coordinates of the tile covering region in pixel coordinates
# File lib/global_map_tiles/global_geodetic.rb, line 17 def pixels_to_tile(px, py) tx = ((px / @tile_size.to_f).ceil - 1).to_i ty = ((py / @tile_size.to_f).ceil - 1).to_i [tx, ty] end
resolution(zoom)
click to toggle source
Resolution (arc/pixel) for given zoom level (measured at Equator)“
# File lib/global_map_tiles/global_geodetic.rb, line 24 def resolution(zoom) (180 / 256.0) / 2**zoom end
tile_bounds(tx, ty, zoom)
click to toggle source
Returns bounds of the given tile
# File lib/global_map_tiles/global_geodetic.rb, line 29 def tile_bounds(tx, ty, zoom) res = 180 / 256.0 / 2**zoom [ tx * 256 * res - 180, ty * 256 * res - 90, (tx + 1) * 256 * res - 180, (ty + 1) * 256 * res - 90 ] end