module GeoDistance::ClassMethods

this is global because if computing lots of track point distances, it didn’t make sense to new a Hash each time over potentially 100’s of thousands of points

Public Instance Methods

algorithms() click to toggle source
# File lib/geo-distance/class_methods.rb, line 65
def algorithms
  [:flat, :haversine, :spherical, :vincenty, :nvector]
end
all_units() click to toggle source
# File lib/geo-distance/class_methods.rb, line 57
def all_units
  GeoUnits.all_units
end
default_algorithm() click to toggle source
# File lib/geo-distance/class_methods.rb, line 41
def default_algorithm 
  @default_algorithm || :haversine
end
default_algorithm=(name) click to toggle source
# File lib/geo-distance/class_methods.rb, line 36
def default_algorithm= name
  raise ArgumentError, "Not a valid algorithm. Must be one of: #{algorithms}" if !algorithms.include?(name.to_sym)
  @default_algorithm = name 
end
default_units() click to toggle source
# File lib/geo-distance/class_methods.rb, line 32
def default_units
  @default_units || :kms
end
default_units=(name) click to toggle source
# File lib/geo-distance/class_methods.rb, line 27
def default_units= name
  raise ArgumentError, "Not a valid units. Must be one of: #{all_units}" if !all_units.include?(name.to_sym)
  @default_units = GeoUnits.key(name)
end
distance(*args) click to toggle source

radius of the great circle in miles radius in kilometers…some algorithms use 6367

# File lib/geo-distance/class_methods.rb, line 9
def distance(*args) 
  klass = case default_algorithm
  when :flat
    GeoDistance::Flat
  when :haversine
    GeoDistance::Haversine
  when :spherical
    GeoDistance::Spherical        
  when :vincenty
    GeoDistance::Vincenty
  when :nvector
    GeoDistance::NVector
  else
    raise ArgumentError, "Not a valid algorithm. Must be one of: #{algorithms}"
  end
  klass.distance *args
end
earth_radius(units) click to toggle source
# File lib/geo-distance/class_methods.rb, line 45
def earth_radius units
  GeoUnits.earth_radius units
end
radians_per_degree() click to toggle source
# File lib/geo-distance/class_methods.rb, line 49
def radians_per_degree
  0.017453293  #  PI/180
end
radians_ratio(unit) click to toggle source
# File lib/geo-distance/class_methods.rb, line 53
def radians_ratio unit
  GeoDistance.radians_per_degree * earth_radius[unit]          
end
units() click to toggle source
# File lib/geo-distance/class_methods.rb, line 61
def units 
  GeoUnits.units
end