ocean-names 0.3.4 → 0.4.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bae097bab35a19f1d7a9f8df2924387d6948fee8965cc308a1fffab8baedd53e
4
- data.tar.gz: 9d798670d00d48cd2b93473385e1957ba166bf5ec28a385621517b62429a003a
3
+ metadata.gz: ef91ec19173f79820a3c26b30d51a9b29964cc1b03fe91aa8de0db18e23eb2c8
4
+ data.tar.gz: 4d0ed8778da8f19ee8a28db34ae0640146a19a649dfd59d01c5aad9cdfb18ca4
5
5
  SHA512:
6
- metadata.gz: 3def51ff10c058007636d8d199460acf860dad61ef125728779346c4dea715837322b981151024bbb2a6b92a65c703c1fd04bc06c041c06399aa8335585167d9
7
- data.tar.gz: 1161be402544502a0d4c74f7b3e180d5b6b5794b46c0cf1168a5eb266ca51b613ce9a8bea6d157dbe8b3921aabed1fd5608fac4cfe833eeb773be94cac2421bb
6
+ metadata.gz: 8c13e6bc08996d3fc1953e9830433c1dd811d35d8a73c2f2dea13493ace414ab5b6332ca1e677d54c7502126db99f02a4a5a3625f833270dc621cae2fbfc8d25
7
+ data.tar.gz: e0072013b5f4af66332f09894ff75b8b06b60d1241ab7b4450a9792f2702bd78637a9803b82740f17e2a744735857ca208a63c7a015df45093435bbaf3f2732c
data/Gemfile.lock CHANGED
@@ -1,8 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ocean-names (0.2.4)
5
- geokit (~> 1.13)
4
+ ocean-names (0.3.4)
6
5
  oj (~> 3.3)
7
6
 
8
7
  GEM
@@ -11,7 +10,6 @@ GEM
11
10
  coderay (1.1.2)
12
11
  diff-lcs (1.3)
13
12
  docile (1.3.2)
14
- geokit (1.13.1)
15
13
  json (2.2.0)
16
14
  method_source (0.9.2)
17
15
  oj (3.9.2)
@@ -0,0 +1,37 @@
1
+ module Ocean
2
+ module Names
3
+ class Polygon
4
+ attr_accessor :points
5
+
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 = [lat, lng]
21
+ y1 = p.first
22
+ x1 = p.last
23
+ y2 = last_point.first
24
+ x2 = last_point.last
25
+
26
+ if y1 < y && y2 >= y || y2 < y && y1 >= y
27
+ odd_node = !odd_node if x1 + (y - y1) / (y2 - y1) * (x2 - x1) < x
28
+ end
29
+
30
+ last_point = p
31
+ end
32
+
33
+ odd_node
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,5 +1,5 @@
1
1
  module Ocean
2
2
  module Names
3
- VERSION = "0.3.4"
3
+ VERSION = "0.4.4"
4
4
  end
5
5
  end
data/lib/ocean/names.rb CHANGED
@@ -1,17 +1,19 @@
1
1
  require "ocean/names/version"
2
+ require "ocean/names/polygon"
2
3
  require "oj"
3
- require "geokit"
4
4
 
5
5
  module Ocean
6
6
  module Names
7
7
  class Error < StandardError; end
8
8
 
9
+ # drill down to main geometry points array
9
10
  GET_POINTS = ->(arg) {
10
11
  return arg unless arg.first.first.is_a?(Array)
11
12
 
12
13
  GET_POINTS.(arg.first)
13
14
  }
14
15
 
16
+ # check bounds to avoid
15
17
  WITHIN_BOUNDS = ->(record, x, y) {
16
18
  record["min_x"] <= x &&
17
19
  record["max_x"] >= x &&
@@ -20,18 +22,14 @@ module Ocean
20
22
  }
21
23
 
22
24
  def self.reverse_geocode(lat:, lng:)
23
- point = Geokit::LatLng.new(lat, lng)
24
-
25
25
  rec = data.find do |record|
26
26
  # avoid check of obviously false geometries
27
27
  next unless WITHIN_BOUNDS.(record, lat, lng)
28
28
 
29
29
  # get points from nested arrays
30
- source = GET_POINTS.(record["geometry"])
31
-
32
- points = source.map { |x| Geokit::LatLng.new(*x) }
33
- polygon = Geokit::Polygon.new(points)
34
- polygon.contains?(point)
30
+ points = GET_POINTS.(record["geometry"])
31
+ polygon = Ocean::Names::Polygon.new(points)
32
+ polygon.contains?(lat: lat, lng: lng)
35
33
  end
36
34
 
37
35
  rec&.reject do |key|
data/ocean-names.gemspec CHANGED
@@ -29,7 +29,6 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = ["lib"]
30
30
 
31
31
  spec.add_dependency "oj", "~> 3.3"
32
- spec.add_dependency "geokit", "~> 1.13"
33
32
 
34
33
  spec.add_development_dependency "bundler", "~> 2.0"
35
34
  spec.add_development_dependency "rake", "~> 10.0"
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: 0.3.4
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - rafael
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-25 00:00:00.000000000 Z
11
+ date: 2019-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.3'
27
- - !ruby/object:Gem::Dependency
28
- name: geokit
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.13'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.13'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: bundler
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -143,6 +129,7 @@ files:
143
129
  - bin/setup
144
130
  - data/water.json
145
131
  - lib/ocean/names.rb
132
+ - lib/ocean/names/polygon.rb
146
133
  - lib/ocean/names/version.rb
147
134
  - ocean-names.gemspec
148
135
  homepage: https://github.com/skcc321/ocean-names