class GeoMonitor::LatLngPoint

Attributes

lat[RW]
lng[RW]

Public Class Methods

from_number(xtile, ytile, zoom) click to toggle source

Get the lat/lng for a specific tile at a zoom level From wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Pseudo-code

# File lib/geo_monitor/lat_lng_point.rb, line 24
def self.from_number(xtile, ytile, zoom)
  n = 2.0**zoom
  lng = xtile / n * 360.0 - 180.0
  lat_rad = Math.atan(Math.sinh(Math::PI * (1 - 2 * ytile / n)))
  lat = 180.0 * (lat_rad / Math::PI)
  new(lat: lat, lng: lng)
end
new(lat: 0, lng: 0) click to toggle source
# File lib/geo_monitor/lat_lng_point.rb, line 4
def initialize(lat: 0, lng: 0)
  @lat = lat.to_f
  @lng = lng.to_f
end

Public Instance Methods

to_3857() click to toggle source

This needs better documentation, but projecting from EPSG:4326 to EPSG:3857

# File lib/geo_monitor/lat_lng_point.rb, line 12
def to_3857
  d = Math::PI / 180
  max = 1 - 1E-15
  sin = [[Math.sin(lat * d), max].min, -max].max
  self.class.new(
    lng: ::GeoMonitor::Constants::R * lng * d,
    lat: ::GeoMonitor::Constants::R * Math.log((1 + sin) / (1 - sin)) / 2
  )
end