geo-distance2 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 523c3c087965f4be5c678ae45c5a5b8f47d08732
4
+ data.tar.gz: 2cd2ad476d2a3fc4b23be27af6a4905341147b9c
5
+ SHA512:
6
+ metadata.gz: 3b6dd41efd4b5682730f9548624533b429effee4cf799b449b214f7d8cee5d8d5004c06c09c1b9497a57643f45c085fb367eed10434f1b3de4b9467a742e185b
7
+ data.tar.gz: 5435d9e8b786fd2dea3d575968089e0c98d8d7bd433d16a8923a34e284df29b91773ed3c04bb7771be9ebff4e82cadc9cb44d01cde7eeb0cd69587b74a902956
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'geo_point', '~> 0.2.5'
4
+ gem 'geo_units', '~> 0.2.4.1'
5
+
6
+ group :development do
7
+ gem "rspec", ">= 2.6.0"
8
+ gem "bundler", "~> 1.10.6"
9
+ gem "jeweler", "~> 1.6.2"
10
+ gem "simplecov", ">= 0"
11
+ end
@@ -0,0 +1,55 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.0.9)
5
+ diff-lcs (1.1.2)
6
+ docile (1.1.5)
7
+ geo_calc (0.7.6)
8
+ activesupport (>= 3.0.1)
9
+ geo_units (~> 0.2.1)
10
+ i18n
11
+ require_all (~> 1.2.0)
12
+ sugar-high (~> 0.4.6.3)
13
+ geo_point (0.2.5)
14
+ geo_calc (~> 0.7.5)
15
+ geo_units (~> 0.2.1)
16
+ geo_units (0.2.4.1)
17
+ sugar-high (~> 0.4.6.2)
18
+ git (1.2.5)
19
+ i18n (0.6.0)
20
+ jeweler (1.6.2)
21
+ bundler (~> 1.0)
22
+ git (>= 1.2.5)
23
+ rake
24
+ json (1.8.3)
25
+ rake (0.9.2)
26
+ require_all (1.2.0)
27
+ rspec (2.6.0)
28
+ rspec-core (~> 2.6.0)
29
+ rspec-expectations (~> 2.6.0)
30
+ rspec-mocks (~> 2.6.0)
31
+ rspec-core (2.6.4)
32
+ rspec-expectations (2.6.0)
33
+ diff-lcs (~> 1.1.2)
34
+ rspec-mocks (2.6.0)
35
+ simplecov (0.10.0)
36
+ docile (~> 1.1.0)
37
+ json (~> 1.8)
38
+ simplecov-html (~> 0.10.0)
39
+ simplecov-html (0.10.0)
40
+ sugar-high (0.4.6.4)
41
+
42
+ PLATFORMS
43
+ ruby
44
+ x64-mingw32
45
+
46
+ DEPENDENCIES
47
+ bundler (~> 1.10.6)
48
+ geo_point (~> 0.2.5)
49
+ geo_units (~> 0.2.4.1)
50
+ jeweler (~> 1.6.2)
51
+ rspec (>= 2.6.0)
52
+ simplecov
53
+
54
+ BUNDLED WITH
55
+ 1.10.6
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Kristian Mandrup
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,83 @@
1
+ h1. GeoDistance - geo distance calculations
2
+
3
+ Calculates the Geo distance between two locations using longitude and latitude.
4
+ This is done using "pure" Math formulas without resorting to Active Record or SQL DB functionality
5
+
6
+ This gem is meant to be a replacement for those geo distance utils out there that use built in SQL DB functionality for their calculations!
7
+
8
+ The formulas curently supported are
9
+
10
+ * _Haversine_
11
+ * _Spherical_
12
+ * _Vincenty_
13
+ * _Flat_
14
+
15
+ h2. Install & Usage
16
+
17
+ <pre>require 'geo-distance'
18
+
19
+ it "should work" do
20
+ lon1 = -104.88544
21
+ lat1 = 39.06546
22
+
23
+ lon2 = -104.80
24
+ lat2 = lat1
25
+
26
+ dist = GeoDistance.distance( lat1, lon1, lat2, lon2 ) # in radians
27
+
28
+ dist = GeoDistance::Haversine.geo_distance( lat1, lon1, lat2, lon2 ).to_meters
29
+
30
+ # Change to (lng, lat) mode
31
+ GeoPoint.coord_mode = :lng_lat
32
+
33
+ p1, p2 = [[lon1, lat1].geo_point, [lon2, lat2].geo_point]
34
+
35
+ dist = GeoDistance::Haversine.geo_distance( lon1, lat1, lon2, lat2)
36
+ dist = GeoDistance::Haversine.geo_distance( p1, p2).to_miles
37
+
38
+ puts "the distance from #{lat1}, #{lon1} to #{lat2}, #{lon2} is: #{dist.meters} meters"
39
+
40
+ dist.feet
41
+ dist.meters
42
+ dist.kms
43
+ dist.miles
44
+ end
45
+ </pre>
46
+
47
+ h2. Distance API
48
+
49
+ The call to distance returns an instance of GeoDistance
50
+
51
+ @dist = GeoDistance::Haversine.distance( lat1, lon1, lat2, lon2 )@
52
+
53
+ The #kms, #meters, #miles and #feet methods return an instance og GeoUnit
54
+
55
+ @dist.kms@
56
+
57
+ h3. Setting default algorithm
58
+
59
+ You can also set a default algorithm to use...
60
+ The following will use the _Haversine_ algorithm:
61
+
62
+ <pre>
63
+ GeoDistance.default_algorithm = :haversine
64
+ dist = GeoDistance.distance( lat1, lon1, lat2, lon2 )
65
+ </pre>
66
+
67
+ GeoDistance is used in the "geo_magic":https://github.com/kristianmandrup/geo_magic gem
68
+
69
+ h2. Contributing to geo-distance
70
+
71
+ * Check out the specs and add specs to spec any added features or changes!
72
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
73
+ * Fork the project
74
+ * Start a feature/bugfix branch
75
+ * Commit and push until you are happy with your contribution
76
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
77
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
78
+
79
+ h2. Copyright
80
+
81
+ Copyright (c) 2011 Kristian Mandrup. See LICENSE.txt for
82
+ further details.
83
+
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "geo-distance2"
16
+ gem.homepage = "http://github.com/olignyf/geo-distance2"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Calculates the geo distance between two locations using longitude and latitude, using Haversine, Speherical or Vincenty formula}
19
+ gem.description = %Q{Calculates the geo distance between two locations using longitude and latitude using Haversine, Speherical or Vincenty formula.
20
+ This is done using Math formulas without resorting to Active Record or SQL DB functionality}
21
+ gem.email = "kmandrup@gmail.com"
22
+ gem.authors = ["Kristian Mandrup"]
23
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
24
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
25
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
26
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rspec/core'
31
+ require 'rspec/core/rake_task'
32
+ RSpec::Core::RakeTask.new(:spec) do |spec|
33
+ spec.pattern = FileList['spec/**/*_spec.rb']
34
+ end
35
+
36
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
37
+ spec.pattern = 'spec/**/*_spec.rb'
38
+ spec.rcov = true
39
+ end
40
+
41
+ task :default => :spec
42
+
43
+ require 'rake/rdoctask'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "geo-distance #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.0.0
@@ -0,0 +1,87 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{geo-distance2}
8
+ s.version = "0.2.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{Francois Oligny-Lemieux}, %q{Kristian Mandrup}]
12
+ s.date = %q{2015-12-09}
13
+ s.description = %q{Calculates the geo distance between two locations using longitude and latitude using Haversine, Speherical or Vincenty formula.
14
+ This is done using Math formulas without resorting to Active Record or SQL DB functionality}
15
+ s.email = %q{frank.quebec@gmail.com}
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.textile"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".rspec",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.textile",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "geo-distance.gemspec",
30
+ "lib/geo-distance.rb",
31
+ "lib/geo-distance/class_methods.rb",
32
+ "lib/geo-distance/conversion.rb",
33
+ "lib/geo-distance/conversion/meters.rb",
34
+ "lib/geo-distance/conversion/radians.rb",
35
+ "lib/geo-distance/core_ext.rb",
36
+ "lib/geo-distance/distance.rb",
37
+ "lib/geo-distance/formula.rb",
38
+ "lib/geo-distance/formula/flat.rb",
39
+ "lib/geo-distance/formula/haversine.rb",
40
+ "lib/geo-distance/formula/n_vector.rb",
41
+ "lib/geo-distance/formula/spherical.rb",
42
+ "lib/geo-distance/formula/vincenty.rb",
43
+ "lib/geo-distance/scale.rb",
44
+ "spec/geo_distance/class_methods_spec.rb",
45
+ "spec/geo_distance/core_ext_spec.rb",
46
+ "spec/geo_distance/distance_spec.rb",
47
+ "spec/geo_distance/formula/flat_spec.rb",
48
+ "spec/geo_distance/formula/haversine_spec.rb",
49
+ "spec/geo_distance/formula/n_vector.rb",
50
+ "spec/geo_distance/formula/spherical_spec.rb",
51
+ "spec/geo_distance/formula/vincenty_spec.rb",
52
+ "spec/spec_helper.rb"
53
+ ]
54
+ s.homepage = %q{http://github.com/olignyf/geo-distance2}
55
+ s.licenses = [%q{MIT}]
56
+ s.require_paths = [%q{lib}]
57
+ s.rubygems_version = %q{1.8.5}
58
+ s.summary = %q{Calculates the geo distance between two locations using longitude and latitude, using Haversine, Speherical or Vincenty formula}
59
+
60
+ if s.respond_to? :specification_version then
61
+ s.specification_version = 3
62
+
63
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
64
+ s.add_runtime_dependency(%q<geo_point>, ["~> 0.2.5"])
65
+ s.add_runtime_dependency(%q<geo_units>, ["~> 0.2.4.1"])
66
+ s.add_development_dependency(%q<rspec>, [">= 2.6.0"])
67
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.10"])
68
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
69
+ s.add_development_dependency(%q<rcov>, [">= 0"])
70
+ else
71
+ s.add_dependency(%q<geo_point>, ["~> 0.2.5"])
72
+ s.add_dependency(%q<geo_units>, ["~> 0.2.4.1"])
73
+ s.add_dependency(%q<rspec>, [">= 2.6.0"])
74
+ s.add_dependency(%q<bundler>, ["~> 1.0.10"])
75
+ s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
76
+ s.add_dependency(%q<rcov>, [">= 0"])
77
+ end
78
+ else
79
+ s.add_dependency(%q<geo_point>, ["~> 0.2.5"])
80
+ s.add_dependency(%q<geo_units>, ["~> 0.2.4.1"])
81
+ s.add_dependency(%q<rspec>, [">= 2.6.0"])
82
+ s.add_dependency(%q<bundler>, ["~> 1.0.10"])
83
+ s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
84
+ s.add_dependency(%q<rcov>, [">= 0"])
85
+ end
86
+ end
87
+
@@ -0,0 +1,18 @@
1
+ require 'geo_point'
2
+
3
+ class GeoDistance
4
+ autoload :Conversion, 'geo-distance/conversion'
5
+ autoload :Scale, 'geo-distance/scale'
6
+ autoload :ClassMethods, 'geo-distance/class_methods'
7
+
8
+ autoload :Haversine, 'geo-distance/formula/haversine'
9
+ autoload :Spherical, 'geo-distance/formula/spherical'
10
+ autoload :Vincenty, 'geo-distance/formula/vincenty'
11
+ autoload :NVector, 'geo-distance/formula/n_vector'
12
+ autoload :Flat, 'geo-distance/formula/flat'
13
+ end
14
+
15
+ require 'geo-distance/distance'
16
+ require 'geo-distance/core_ext'
17
+ require 'geo-distance/formula'
18
+
@@ -0,0 +1,71 @@
1
+ class GeoDistance
2
+ # this is global because if computing lots of track point distances, it didn't make
3
+ # sense to new a Hash each time over potentially 100's of thousands of points
4
+
5
+ module ClassMethods
6
+ # radius of the great circle in miles
7
+ # radius in kilometers...some algorithms use 6367
8
+
9
+ def distance(*args)
10
+ klass = case default_algorithm
11
+ when :flat
12
+ GeoDistance::Flat
13
+ when :haversine
14
+ GeoDistance::Haversine
15
+ when :spherical
16
+ GeoDistance::Spherical
17
+ when :vincenty
18
+ GeoDistance::Vincenty
19
+ when :nvector
20
+ GeoDistance::NVector
21
+ else
22
+ raise ArgumentError, "Not a valid algorithm. Must be one of: #{algorithms}"
23
+ end
24
+ klass.distance *args
25
+ end
26
+
27
+ def default_units= name
28
+ raise ArgumentError, "Not a valid units. Must be one of: #{all_units}" if !all_units.include?(name.to_sym)
29
+ @default_units = GeoUnits.key(name)
30
+ end
31
+
32
+ def default_units
33
+ @default_units || :kms
34
+ end
35
+
36
+ def default_algorithm= name
37
+ raise ArgumentError, "Not a valid algorithm. Must be one of: #{algorithms}" if !algorithms.include?(name.to_sym)
38
+ @default_algorithm = name
39
+ end
40
+
41
+ def default_algorithm
42
+ @default_algorithm || :haversine
43
+ end
44
+
45
+ def earth_radius units
46
+ GeoUnits.earth_radius units
47
+ end
48
+
49
+ def radians_per_degree
50
+ 0.017453293 # PI/180
51
+ end
52
+
53
+ def radians_ratio unit
54
+ GeoDistance.radians_per_degree * earth_radius[unit]
55
+ end
56
+
57
+ def all_units
58
+ GeoUnits.all_units
59
+ end
60
+
61
+ def units
62
+ GeoUnits.units
63
+ end
64
+
65
+ def algorithms
66
+ [:flat, :haversine, :spherical, :vincenty, :nvector]
67
+ end
68
+ end
69
+
70
+ extend ClassMethods
71
+ end
@@ -0,0 +1,67 @@
1
+ class GeoDistance
2
+ module Conversion
3
+ autoload :Meters, 'geo-distance/conversion/meters'
4
+ autoload :Radians, 'geo-distance/conversion/radians'
5
+
6
+ def self.included(base)
7
+ base.send :include, Meters
8
+ base.send :include, Radians
9
+ end
10
+
11
+ # return new GeoDistance instance with distance converted to specific unit
12
+ ::GeoDistance.units.each do |unit|
13
+ class_eval %{
14
+ def to_#{unit}
15
+ cloned = self.dup
16
+ un = GeoUnits.key :#{unit}
17
+ cloned.distance = in_meters * GeoUnits.meters_map[un]
18
+ cloned.unit = un
19
+ cloned
20
+ end
21
+ }
22
+ end
23
+
24
+ # in_ and as_ return distance as a Float
25
+ # to_xxx! and similar, modify distance (self) directly
26
+ (::GeoDistance.units - [:meters]).each do |unit|
27
+ class_eval %{
28
+ def in_#{unit}
29
+ dist = (unit == :radians) ? in_radians : distance
30
+ conv_unit = GeoUnits.key :#{unit}
31
+ convert_to_meters(dist) * GeoUnits.meters_map[conv_unit]
32
+ end
33
+ alias_method :as_#{unit}, :in_#{unit}
34
+
35
+ def to_#{unit}!
36
+ conv_unit = GeoUnits.key :#{unit}
37
+ self.distance = in_meters * GeoUnits.meters_map[conv_unit]
38
+ self.unit = conv_unit
39
+ self
40
+ end
41
+ alias_method :in_#{unit}!, :to_#{unit}!
42
+ alias_method :as_#{unit}!, :to_#{unit}!
43
+ }
44
+ end
45
+
46
+ ::GeoDistance.all_units.each do |unit|
47
+ class_eval %{
48
+ def #{unit}
49
+ un = GeoUnits.key :#{unit}
50
+ send(:"as_\#{un}")
51
+ end
52
+ }
53
+ end
54
+
55
+ protected
56
+
57
+ # distance delta
58
+ GeoDistance.units.each do |unit|
59
+ class_eval %{
60
+ def delta_#{unit}
61
+ unit = GeoUnits.key(:#{unit})
62
+ GeoDistance.earth_radius[:#{unit}] * distance
63
+ end
64
+ }
65
+ end
66
+ end
67
+ end