gps_tools 0.1.0 → 0.1.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.
- checksums.yaml +4 -4
- data/lib/gps_tools.rb +28 -5
- data/lib/gps_tools/distance.rb +6 -2
- data/lib/gps_tools/geometry.rb +24 -6
- metadata +3 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab1aed7260c6af3b0c702d324ac9f5f2b1def10dca3c0b1f9e8365e575360a8b
|
4
|
+
data.tar.gz: 3b0fd3d99b8a363afddcf289f6b2b1bd8f3a8396271c176060c37d043400f879
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11813f0d7162599d79b9a304a26844560f5becd4959ad4ffc4ff5f443102636f7ade3eaa0cac716220858707582e44a6ec0d3ea60ac53edaaf0fe728d82d089b
|
7
|
+
data.tar.gz: ec6395e448fd121fa1ada673c678a814663feacc2f215c140f950fb7df37f53b67310698913064e7945c90a1eab2366750c66ae8c50df19b3f6ccd7e0ee88f77
|
data/lib/gps_tools.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
|
-
require 'gps_tools/distance'
|
2
|
-
require 'gps_tools/geometry'
|
3
|
-
|
4
1
|
class GPSTools
|
5
2
|
##
|
6
3
|
# Returns the distance in miles (unit = "mile"), kilometers (unit = "km"), or nautical miles (unit = "nm")
|
7
4
|
# between two gps coordinates, coord1 and coord2
|
8
5
|
def self.distance(coord1, coord2, unit = "mile")
|
9
6
|
distance_tool = Distance.new(unit)
|
10
|
-
|
7
|
+
distance = distance_tool.get_distance(coord1[0], coord1[1], coord2[0], coord2[1])
|
8
|
+
return distance
|
11
9
|
end
|
12
10
|
|
13
11
|
##
|
@@ -17,4 +15,29 @@ class GPSTools
|
|
17
15
|
geometry = Geometry.new()
|
18
16
|
return geometry.in_polygon?(polygon, coord)
|
19
17
|
end
|
20
|
-
|
18
|
+
|
19
|
+
##
|
20
|
+
# Returns a new array containing all coordinates within the given polygon
|
21
|
+
def self.filter_by_polygon(polygon, coords)
|
22
|
+
geometry = Geometry.new()
|
23
|
+
return geometry.filter_by_polygon(polygon, coords)
|
24
|
+
end
|
25
|
+
|
26
|
+
##
|
27
|
+
# Returns a boolean that identifies if a given gps coordinate, coord, is within
|
28
|
+
# a given radius of a center point, center
|
29
|
+
def self.in_radius?(radius, center, coord)
|
30
|
+
geometry = Geometry.new()
|
31
|
+
return geometry.in_radius?(radius, center, coord)
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# Returns a new array containing all coordinates within the given radius
|
36
|
+
def self.filter_by_radius(radius, center, coords)
|
37
|
+
geometry = Geometery.new()
|
38
|
+
return geometry.filter_by_radius(radius, center, coords)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
require 'gps_tools/distance'
|
43
|
+
require 'gps_tools/geometry'
|
data/lib/gps_tools/distance.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
class Distance
|
1
|
+
class GPSTools::Distance
|
2
2
|
def initialize(unit = "mile")
|
3
3
|
@unit = unit
|
4
4
|
case @unit
|
@@ -11,6 +11,9 @@ class Distance
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
##
|
15
|
+
# Returns the distance in miles (unit = "mile"), kilometers (unit = "km"), or nautical miles (unit = "nm")
|
16
|
+
# between two gps coordinates, coord1 and coord2
|
14
17
|
def get_distance(coord1, coord2)
|
15
18
|
lat1 = coord1[0]
|
16
19
|
long1 = coord1[1]
|
@@ -23,7 +26,8 @@ class Distance
|
|
23
26
|
a = Math.sin(degrees_to_radians(lat_diff)/2) * Math.sin(degrees_to_radians(lat_diff)/2) + Math.sin(degrees_to_radians(long_diff)/2) * Math.sin(degrees_to_radians(long_diff)/2) * Math.cos(degrees_to_radians(lat1)) * Math.cos(degrees_to_radians(lat2))
|
24
27
|
c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a))
|
25
28
|
|
26
|
-
|
29
|
+
distance = @earth_radius * c
|
30
|
+
return distance
|
27
31
|
end
|
28
32
|
|
29
33
|
private
|
data/lib/gps_tools/geometry.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
|
-
class Geometry
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
end
|
6
|
-
|
1
|
+
class GPSTools::Geometry
|
2
|
+
##
|
3
|
+
# Returns a boolean that identifies if a given gps coordinate, coord, is within
|
4
|
+
# a given polygon (array of [lat, lng])
|
7
5
|
def in_polygon?(polygon, coord)
|
8
6
|
n = polygon.length
|
9
7
|
|
@@ -41,6 +39,26 @@ class Geometry
|
|
41
39
|
intersections % 2 == 1
|
42
40
|
end
|
43
41
|
|
42
|
+
##
|
43
|
+
# Returns a new array containing all coordinates within the given polygon
|
44
|
+
def filter_by_polygon(polygon, coords)
|
45
|
+
coords.select { |coord| in_polygon?(polygon, coord) }
|
46
|
+
end
|
47
|
+
|
48
|
+
##
|
49
|
+
# Returns a boolean that identifies if a given gps coordinate, coord, is within
|
50
|
+
# a given radius of a center point, center
|
51
|
+
def in_radius?(radius, center, coord)
|
52
|
+
distance = GPSTools::Distance.new.get_distance(center, coord)
|
53
|
+
distance <= radius
|
54
|
+
end
|
55
|
+
|
56
|
+
##
|
57
|
+
# Returns a new array containing all coordinates within the given radius
|
58
|
+
def filter_by_radius(radius, center, coords)
|
59
|
+
coords.select{ |coord| in_radius?(radius, center, coord) }
|
60
|
+
end
|
61
|
+
|
44
62
|
private
|
45
63
|
def max(a, b)
|
46
64
|
a > b ? a : b
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gps_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Van Fleet
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-08-
|
11
|
+
date: 2021-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -39,14 +39,7 @@ licenses:
|
|
39
39
|
- MIT
|
40
40
|
metadata: {}
|
41
41
|
post_install_message:
|
42
|
-
rdoc_options:
|
43
|
-
- "-m"
|
44
|
-
- README.rdoc
|
45
|
-
- "-x"
|
46
|
-
- lib/(?!gps_tools.rb).*
|
47
|
-
- lib/gps_tools.rb
|
48
|
-
- LICENSE
|
49
|
-
- README.rdoc
|
42
|
+
rdoc_options: []
|
50
43
|
require_paths:
|
51
44
|
- lib
|
52
45
|
required_ruby_version: !ruby/object:Gem::Requirement
|