geozone 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/geozone.rb +51 -0
- metadata +90 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 77cabebaaf4ad3227df18bdabe0240173eaa2463ba0c30d6f6560c166659f93f
|
4
|
+
data.tar.gz: 3427fecfd5f939ddfad2d0a03defc9b9af144247b479e521b45f0ee4865aa390
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 881da62959db1129ef01213b538372806c6be83af19bdfcc842c71dbba1b83e08ec14c9d7f6a953869fdb0bdd2f8c5b149d7de8a85a1b26c143a4768028bff97
|
7
|
+
data.tar.gz: 67a8655eb1e8a897c45499ba18a414e82e73fd0038307dc2985bb2d78b9f249b72e3af398432bd4b526dd184863d6466e8979fe8a046fedba8a24f49dfa99f80
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
Binary file
|
data/lib/geozone.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# file: geozone.rb
|
4
|
+
|
5
|
+
|
6
|
+
require 'dynarex'
|
7
|
+
|
8
|
+
|
9
|
+
class GeoZone
|
10
|
+
|
11
|
+
def initialize(locations: nil, journey: nil)
|
12
|
+
|
13
|
+
@dx = Dynarex.new locations if locations
|
14
|
+
@journey = journey
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def zone(location)
|
19
|
+
|
20
|
+
a = @dx.all.map do |x|
|
21
|
+
[x.label, distance(location, x.coords.split(/, */).map(&:to_f)).round]
|
22
|
+
end
|
23
|
+
|
24
|
+
label, distance = a.min_by(&:last)
|
25
|
+
{zone: label.to_sym, distance: distance}
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def distance(loc1, loc2)
|
32
|
+
|
33
|
+
rad = Math::PI/180
|
34
|
+
rkm = 6371 # Earth radius in kilometers
|
35
|
+
rm = rkm * 1000 # Radius in meters
|
36
|
+
|
37
|
+
dlat_rad = (loc2[0]-loc1[0]) * rad # Delta, converted to rad
|
38
|
+
dlon_rad = (loc2[1]-loc1[1]) * rad
|
39
|
+
|
40
|
+
lat1_rad, lon1_rad = loc1.map {|i| i * rad }
|
41
|
+
lat2_rad, lon2_rad = loc2.map {|i| i * rad }
|
42
|
+
|
43
|
+
a = Math.sin(dlat_rad/2)**2 + Math.cos(lat1_rad) * Math.cos(lat2_rad) \
|
44
|
+
* Math.sin(dlon_rad/2)**2
|
45
|
+
c = 2 * Math::atan2(Math::sqrt(a), Math::sqrt(1-a))
|
46
|
+
|
47
|
+
rm * c # Distance in meters
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: geozone
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Robertson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTkwMzE4MTQyODM4WhcN
|
15
|
+
MjAwMzE3MTQyODM4WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
|
16
|
+
cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQC85EJG
|
17
|
+
lDZIb1v438XSR5Be11+c4vWVsubBSpW+dNGWep/TVNibNQ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aL+i1hFi4kKJUTbfHKPCetqjmPZZDiW9jUvKSL7ksB3OY0ez/QNz2GZDN2FaXL
|
33
|
+
eCBKqgWgVpaqLA7POhC9eVOIL8sYRVYVOpYbGST/drRMxqe7lMRwLgkX/dAaHf0g
|
34
|
+
PWXSMooTJkiYd7cXryhAPh5vWfhuNkOeb4EIo+2wJy4Taogy3W5yD98j/Fcw7pgx
|
35
|
+
THUUi9/zPMGqrS2mHVePlefqaVbzFXtrHEp0V27bVQ9v8CtxIXg6Rv0OT19Dk4ta
|
36
|
+
tI62YhMUIlkRN9jPKJg4n2pG
|
37
|
+
-----END CERTIFICATE-----
|
38
|
+
date: 2019-03-18 00:00:00.000000000 Z
|
39
|
+
dependencies:
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: dynarex
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.8'
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 1.8.18
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '1.8'
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 1.8.18
|
60
|
+
description:
|
61
|
+
email: james@jamesrobertson.eu
|
62
|
+
executables: []
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files: []
|
65
|
+
files:
|
66
|
+
- lib/geozone.rb
|
67
|
+
homepage: https://github.com/jrobertson/geozone
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubygems_version: 3.0.1
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: Finds the nearest zone location by comparing GPS distances with known locations.
|
90
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|