ocean-names 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +11 -11
- data/README.md +8 -8
- data/bin/console +1 -1
- data/lib/ocean_names.rb +50 -0
- data/lib/ocean_names/polygon.rb +35 -0
- data/lib/ocean_names/version.rb +5 -0
- data/ocean-names.gemspec +3 -3
- metadata +7 -7
- data/lib/ocean/names.rb +0 -52
- data/lib/ocean/names/polygon.rb +0 -37
- data/lib/ocean/names/version.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b3fcd9b45bddee3727772b3515016ac765c5b42ac266b48a5a44dc15e105445
|
4
|
+
data.tar.gz: acbfd16ef0d5af323ce7b6ebdfc5ff2ef7df1b644d4e9f4eb1748fe81dbc76e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fef1186bdcace4947750b157b3f01daea48b9bc5cb8dc9df31020024fc198285b682c1a0fc5c8381a5828a11ced97b1aefbd7cff192437c7c98ae90661fea64
|
7
|
+
data.tar.gz: e5e295d9c1bced6151771ee1042c253dffa7aeda26d6fde2e746cd5c7b9b3f81c8674897d343c436bfb17222b0778d6a9a947eca0f3c6a6d60cf7c6880282cf1
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ocean-names (0.
|
4
|
+
ocean-names (1.0.1)
|
5
5
|
oj (~> 3.3)
|
6
6
|
|
7
7
|
GEM
|
@@ -10,26 +10,26 @@ GEM
|
|
10
10
|
coderay (1.1.2)
|
11
11
|
diff-lcs (1.3)
|
12
12
|
docile (1.3.2)
|
13
|
-
json (2.
|
13
|
+
json (2.3.0)
|
14
14
|
method_source (0.9.2)
|
15
|
-
oj (3.
|
15
|
+
oj (3.10.6)
|
16
16
|
pry (0.12.2)
|
17
17
|
coderay (~> 1.1.0)
|
18
18
|
method_source (~> 0.9.0)
|
19
|
-
rake (
|
19
|
+
rake (13.0.1)
|
20
20
|
rspec (3.9.0)
|
21
21
|
rspec-core (~> 3.9.0)
|
22
22
|
rspec-expectations (~> 3.9.0)
|
23
23
|
rspec-mocks (~> 3.9.0)
|
24
|
-
rspec-core (3.9.
|
25
|
-
rspec-support (~> 3.9.
|
26
|
-
rspec-expectations (3.9.
|
24
|
+
rspec-core (3.9.1)
|
25
|
+
rspec-support (~> 3.9.1)
|
26
|
+
rspec-expectations (3.9.1)
|
27
27
|
diff-lcs (>= 1.2.0, < 2.0)
|
28
28
|
rspec-support (~> 3.9.0)
|
29
|
-
rspec-mocks (3.9.
|
29
|
+
rspec-mocks (3.9.1)
|
30
30
|
diff-lcs (>= 1.2.0, < 2.0)
|
31
31
|
rspec-support (~> 3.9.0)
|
32
|
-
rspec-support (3.9.
|
32
|
+
rspec-support (3.9.2)
|
33
33
|
rspec_junit_formatter (0.4.1)
|
34
34
|
rspec-core (>= 2, < 4, != 2.12.0)
|
35
35
|
simplecov (0.17.1)
|
@@ -45,10 +45,10 @@ DEPENDENCIES
|
|
45
45
|
bundler (~> 2.0)
|
46
46
|
ocean-names!
|
47
47
|
pry (~> 0.12.2)
|
48
|
-
rake (~>
|
48
|
+
rake (~> 13.0)
|
49
49
|
rspec (~> 3.0)
|
50
50
|
rspec_junit_formatter (~> 0.4.1)
|
51
51
|
simplecov (~> 0.17.1)
|
52
52
|
|
53
53
|
BUNDLED WITH
|
54
|
-
2.
|
54
|
+
2.1.4
|
data/README.md
CHANGED
@@ -26,19 +26,19 @@ Or install it yourself as:
|
|
26
26
|
## Usage
|
27
27
|
|
28
28
|
```ruby
|
29
|
-
2.6.5 :001 > require "
|
29
|
+
2.6.5 :001 > require "ocean_names"
|
30
30
|
=> true
|
31
|
-
2.6.5 :002 >
|
31
|
+
2.6.5 :002 > OceanNames.reverse_geocode(lng: 0, lat: 0)
|
32
32
|
=> {"name"=>"South Atlantic Ocean", "lng"=>-18.80876715914, "lat"=>-33.73239551445, "min_lng"=>-69.60083675371, "min_lat"=>-60, "max_lng"=>20.00904913827, "max_lat"=>0.07510554798, "area"=>40501812}
|
33
|
-
2.6.5 :003 >
|
33
|
+
2.6.5 :003 > OceanNames.reverse_geocode(lng: -18, lat: -33)
|
34
34
|
=> {"name"=>"South Atlantic Ocean", "lng"=>-18.80876715914, "lat"=>-33.73239551445, "min_lng"=>-69.60083675371, "min_lat"=>-60, "max_lng"=>20.00904913827, "max_lat"=>0.07510554798, "area"=>40501812}
|
35
|
-
2.6.5 :004 >
|
35
|
+
2.6.5 :004 > OceanNames.reverse_geocode(lng: 79, lat: -32)
|
36
36
|
=> {"name"=>"Indian Ocean", "lng"=>79.20858601429, "lat"=>-32.72458381046, "min_lng"=>20.00261595272, "min_lat"=>-60, "max_lng"=>146.8982192222, "max_lat"=>10.44499945636, "area"=>58230954}
|
37
|
-
2.6.5 :005 >
|
37
|
+
2.6.5 :005 > OceanNames.reverse_geocode(lng: 135, lat: -40)
|
38
38
|
=> {"name"=>"Great Australian Bight", "lng"=>132.7165581317, "lat"=>-36.72591576597, "min_lng"=>117.6141982382, "min_lat"=>-43.56601647135, "max_lng"=>146.23115575344, "max_lat"=>-31.46366941901, "area"=>1326209}
|
39
|
-
2.6.5 :006 >
|
39
|
+
2.6.5 :006 > OceanNames.reverse_geocode(lng: 135, lat: 40)
|
40
40
|
=> {"name"=>"Japan Sea", "lng"=>135.13274500727, "lat"=>40.5084302428, "min_lng"=>125.8013889, "min_lat"=>32.57501368363, "max_lng"=>142.2638347153, "max_lat"=>51.74733316939, "area"=>1066307}
|
41
|
-
2.6.5 :007 >
|
41
|
+
2.6.5 :007 > OceanNames.reverse_geocode(lng: 125, lat: 29)
|
42
42
|
=> {"name"=>"Eastern China Sea", "lng"=>125.21708986497, "lat"=>29.13089135213, "min_lng"=>118.47804582106, "min_lat"=>24.05760752069, "max_lng"=>131.1322036827, "max_lat"=>33.37195920955, "area"=>761356}
|
43
43
|
```
|
44
44
|
|
@@ -58,4 +58,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
58
58
|
|
59
59
|
## Code of Conduct
|
60
60
|
|
61
|
-
Everyone interacting in the
|
61
|
+
Everyone interacting in the OceanNames project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/ocean-names/blob/master/CODE_OF_CONDUCT.md).
|
data/bin/console
CHANGED
data/lib/ocean_names.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "ocean_names/version"
|
4
|
+
require "ocean_names/polygon"
|
5
|
+
require "oj"
|
6
|
+
|
7
|
+
module OceanNames
|
8
|
+
class Error < StandardError; end
|
9
|
+
|
10
|
+
# drill down to main geometry points array
|
11
|
+
GET_POINTS = ->(arg) {
|
12
|
+
return arg unless arg.first.first.is_a?(Array)
|
13
|
+
|
14
|
+
GET_POINTS.(arg.first)
|
15
|
+
}
|
16
|
+
|
17
|
+
# check bounds to avoid
|
18
|
+
WITHIN_BOUNDS = ->(record, x, y) {
|
19
|
+
record["min_lng"] <= x &&
|
20
|
+
record["max_lng"] >= x &&
|
21
|
+
record["min_lat"] <= y &&
|
22
|
+
record["max_lat"] >= y
|
23
|
+
}
|
24
|
+
|
25
|
+
def self.reverse_geocode(lat:, lng:)
|
26
|
+
rec = data.find do |record|
|
27
|
+
# avoid check of obviously false geometries
|
28
|
+
next unless WITHIN_BOUNDS.(record, lng, lat)
|
29
|
+
|
30
|
+
record["geometry"].any? do |geometry|
|
31
|
+
# get points from nested arrays
|
32
|
+
points = GET_POINTS.(geometry)
|
33
|
+
polygon = OceanNames::Polygon.new(points)
|
34
|
+
polygon.contains?(lat: lat, lng: lng)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
rec&.reject do |key|
|
39
|
+
key == "geometry"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.file
|
44
|
+
File.expand_path("../data/water.json", File.dirname(__FILE__))
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.data
|
48
|
+
@data ||= Oj.load(File.read(file))
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OceanNames
|
4
|
+
class Polygon
|
5
|
+
def initialize(points)
|
6
|
+
@points = points
|
7
|
+
@points << points[0] if points[0] != points[-1]
|
8
|
+
end
|
9
|
+
|
10
|
+
def contains?(lat:, lng:)
|
11
|
+
last_point = @points[-1]
|
12
|
+
|
13
|
+
odd_node = false
|
14
|
+
|
15
|
+
x = lng
|
16
|
+
y = lat
|
17
|
+
|
18
|
+
@points.each do |p|
|
19
|
+
# p = [lng, lat]
|
20
|
+
x1 = p.first
|
21
|
+
y1 = p.last
|
22
|
+
x2 = last_point.first
|
23
|
+
y2 = last_point.last
|
24
|
+
|
25
|
+
if x1 < x && x2 >= x || x2 < x && x1 >= x
|
26
|
+
odd_node = !odd_node if y1 + (x - x1) / (x2 - x1) * (y2 - y1) < y
|
27
|
+
end
|
28
|
+
|
29
|
+
last_point = p
|
30
|
+
end
|
31
|
+
|
32
|
+
odd_node
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/ocean-names.gemspec
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
lib = File.expand_path("lib", __dir__)
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require "
|
3
|
+
require "ocean_names/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "ocean-names"
|
7
|
-
spec.version =
|
7
|
+
spec.version = OceanNames::VERSION
|
8
8
|
spec.authors = ["rafael"]
|
9
9
|
spec.email = ["skcc321@gmail.com"]
|
10
10
|
|
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_dependency "oj", "~> 3.3"
|
32
32
|
|
33
33
|
spec.add_development_dependency "bundler", "~> 2.0"
|
34
|
-
spec.add_development_dependency "rake", "~>
|
34
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
35
35
|
spec.add_development_dependency "rspec", "~> 3.0"
|
36
36
|
spec.add_development_dependency "rspec_junit_formatter", "~> 0.4.1"
|
37
37
|
spec.add_development_dependency "simplecov", "~> 0.17.1"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ocean-names
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rafael
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '13.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '13.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,9 +128,9 @@ files:
|
|
128
128
|
- bin/console
|
129
129
|
- bin/setup
|
130
130
|
- data/water.json
|
131
|
-
- lib/
|
132
|
-
- lib/
|
133
|
-
- lib/
|
131
|
+
- lib/ocean_names.rb
|
132
|
+
- lib/ocean_names/polygon.rb
|
133
|
+
- lib/ocean_names/version.rb
|
134
134
|
- ocean-names.gemspec
|
135
135
|
homepage: https://github.com/skcc321/ocean-names
|
136
136
|
licenses:
|
data/lib/ocean/names.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "ocean/names/version"
|
4
|
-
require "ocean/names/polygon"
|
5
|
-
require "oj"
|
6
|
-
|
7
|
-
module Ocean
|
8
|
-
module Names
|
9
|
-
class Error < StandardError; end
|
10
|
-
|
11
|
-
# drill down to main geometry points array
|
12
|
-
GET_POINTS = ->(arg) {
|
13
|
-
return arg unless arg.first.first.is_a?(Array)
|
14
|
-
|
15
|
-
GET_POINTS.(arg.first)
|
16
|
-
}
|
17
|
-
|
18
|
-
# check bounds to avoid
|
19
|
-
WITHIN_BOUNDS = ->(record, x, y) {
|
20
|
-
record["min_lng"] <= x &&
|
21
|
-
record["max_lng"] >= x &&
|
22
|
-
record["min_lat"] <= y &&
|
23
|
-
record["max_lat"] >= y
|
24
|
-
}
|
25
|
-
|
26
|
-
def self.reverse_geocode(lat:, lng:)
|
27
|
-
rec = data.find do |record|
|
28
|
-
# avoid check of obviously false geometries
|
29
|
-
next unless WITHIN_BOUNDS.(record, lng, lat)
|
30
|
-
|
31
|
-
record["geometry"].any? do |geometry|
|
32
|
-
# get points from nested arrays
|
33
|
-
points = GET_POINTS.(geometry)
|
34
|
-
polygon = Ocean::Names::Polygon.new(points)
|
35
|
-
polygon.contains?(lat: lat, lng: lng)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
rec&.reject do |key|
|
40
|
-
key == "geometry"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.file
|
45
|
-
File.expand_path("../../data/water.json", File.dirname(__FILE__))
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.data
|
49
|
-
@data ||= Oj.load(File.read(file))
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
data/lib/ocean/names/polygon.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Ocean
|
4
|
-
module Names
|
5
|
-
class Polygon
|
6
|
-
def initialize(points)
|
7
|
-
@points = points
|
8
|
-
@points << points[0] if points[0] != points[-1]
|
9
|
-
end
|
10
|
-
|
11
|
-
def contains?(lat:, lng:)
|
12
|
-
last_point = @points[-1]
|
13
|
-
|
14
|
-
odd_node = false
|
15
|
-
|
16
|
-
x = lng
|
17
|
-
y = lat
|
18
|
-
|
19
|
-
@points.each do |p|
|
20
|
-
# p = [lng, lat]
|
21
|
-
x1 = p.first
|
22
|
-
y1 = p.last
|
23
|
-
x2 = last_point.first
|
24
|
-
y2 = last_point.last
|
25
|
-
|
26
|
-
if x1 < x && x2 >= x || x2 < x && x1 >= x
|
27
|
-
odd_node = !odd_node if y1 + (x - x1) / (x2 - x1) * (y2 - y1) < y
|
28
|
-
end
|
29
|
-
|
30
|
-
last_point = p
|
31
|
-
end
|
32
|
-
|
33
|
-
odd_node
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|