Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
primitive closest and within radius works for collection of points
- Loading branch information
1 parent
6a26412
commit 3874cd6
Showing
14 changed files
with
189 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'geo-distance' | ||
require 'geo_magic/remote' | ||
require 'geo_magic/calculate' | ||
require 'geo_magic/distance' | ||
require 'geo_magic/meta' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
module GeoDistance | ||
class Haversine < DistanceFormula | ||
def self.point_distance( point_a, point_b, units = :meters ) | ||
def self.point_distance point_a, point_b | ||
points = GeoMagic::Util.extract_points point_a, point_b | ||
distance *points, units | ||
distance *points | ||
end | ||
end | ||
end | ||
|
||
module GeoDistance | ||
class Spherical < DistanceFormula | ||
def self.point_distance( point_a, point_b, units = :meters ) | ||
def self.point_distance point_a, point_b | ||
points = GeoMagic::Util.extract_points point_a, point_b | ||
distance *points, units | ||
distance *points | ||
end | ||
end | ||
end | ||
|
||
module GeoDistance | ||
class Vincenty < DistanceFormula | ||
def self.point_distance( point_a, point_b, units = :meters ) | ||
def self.point_distance point_a, point_b | ||
points = GeoMagic::Util.extract_points point_a, point_b | ||
distance *points, units | ||
distance *points | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require 'geo_magic/radius' | ||
|
||
module GeoMagic | ||
class MapPoint | ||
attr_accessor :latitude, :longitude, :dist | ||
|
||
def initialize latitude, longitude | ||
@latitude = latitude | ||
@longitude = longitude | ||
end | ||
|
||
def within(distance) | ||
GeoMagic::Radius.new self, distance | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module GeoMagic | ||
class Radius | ||
attr_accessor :center, :distance | ||
|
||
RAD_PER_DEG = 0.017453293 | ||
|
||
# radius of the great circle in miles | ||
# radius in kilometers...some algorithms use 6367 | ||
def rad | ||
{:km => 6371, :miles => 3956, :feet => 20895592, :meters => 6371000} | ||
end | ||
|
||
def initialize center, distance | ||
@center = center | ||
@distance = distance | ||
end | ||
|
||
def create_points number | ||
conversion = (RAD_PER_DEG * rad[distance.unit]) | ||
|
||
max_radius_rad = distance.distance / conversion | ||
|
||
range = (max_radius_rad * normalize).to_i | ||
|
||
number.times.inject([]) do |res, n| | ||
dlong = (get_randowm_radiant(range) / normalize) * conversion | ||
dlat = (get_randowm_radiant(range) / normalize) * conversion | ||
|
||
point = GeoMagic::Point.new @center.latitude + dlat, @center.longitude + dlong | ||
res << point | ||
res | ||
end | ||
end | ||
|
||
def get_randowm_radiant range | ||
rand(range) - (range / 2) | ||
end | ||
|
||
def normalize | ||
1000000.0 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'spec_helper' | ||
require 'geo_magic' | ||
require 'geo_magic/remote' | ||
|
||
describe "GeoMagic closest" do | ||
before do | ||
@long1 = -104.88544 | ||
@lat1 = 39.06546 | ||
|
||
@center_point = GeoMagic::Point.new @long1, @lat1 | ||
@radius = @center_point.within(10.km) | ||
@points = @radius.create_points 10 | ||
end | ||
|
||
|
||
it "should select the closest 3 points" do | ||
# puts "radius: #{@radius.inspect}" | ||
# puts "points: #{@points.inspect}" | ||
closest = @points.as_locations.get_closest 3, :from => @center_point | ||
puts "3 closest points: #{closest.inspect}" | ||
end | ||
|
||
it "should select all points within 4 km" do | ||
# puts "radius: #{@radius.inspect}" | ||
# puts "points: #{@points.inspect}" | ||
closest = @points.as_locations.get_within 4.km, :from => @center_point | ||
puts "points within 4 km: #{closest.inspect}" | ||
end | ||
|
||
end |