Skip to content

Instantly share code, notes, and snippets.

@duncanbeevers
duncanbeevers / MapProjection_WinkelTripel.rb
Created September 28, 2009 16:44
Wikel Tripel Map Projection in Ruby
# Usage
# projection = MapProjection::WinkelTripel.new(w, h)
# projections.project( latitude, longitude)
# => [ x, y ] # cartesian coordinates
# Where x and y will be between 0, 0 (upper-left) and w, h (lower-right)
# suitable for compositing images on a bitmap
module Math
DEG2RAD = PI / 180
@humanzz
humanzz / Mercator.rb
Created October 29, 2008 13:07
Ruby implementation for GMercatorProjection
# This is a port of the javascript code found in the following link
#http://groups.google.com/group/Google-Maps-API/browse_thread/thread/a45947d72c27cc73
class Mercator
#offset is defined at zoom level 21 which means that this Mercator is valid for 21 zoom levels
OFFSET = 268435456
RADIUS = OFFSET / Math::PI
def self.lng_to_x(lng, zoom)
(OFFSET + RADIUS * lng * Math::PI / 180).to_i >> (21 - zoom)