geospatial 1.11.1 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93f2203f7a1b83d37a2baa63f70ef67cddb542c734c7ce75a0a4d23be7484df3
4
- data.tar.gz: 5238f1ccbd55623cc06571926b7483c4b2b2ca10df0ce8c8acffc99c9008356e
3
+ metadata.gz: 46655140f5da1a76565f09afb88784d5b7649b1603e21f1c03bbd6f106949a44
4
+ data.tar.gz: eacbf6a8aabb6b2cacdbdc243a1879c1a58d31e9f9964c46635f54880d18b542
5
5
  SHA512:
6
- metadata.gz: c2a9c85d10e38208311bf0cd006ff368dcbb2e882446c0763547725f87c401d117626bca439c93058f9c9ce620ae91987dea246cc82758e4e5e27fee0d508c30
7
- data.tar.gz: 69e0a11e4af435879ebe579c0523dd2911c9cf380817068c07b18baea3d76fb2f49f4124d32eea4f98fe24bc602ab07a49812e6ddc21ce7f66cacc4890d08bce
6
+ metadata.gz: 77dc08c1bc0441bbb1df97395454892f4bcd610dd7706eca9b884bd228594b60335763e45d222bef819e58d22a579b154e88e2ee0fa6a90603e44990480c0bd4
7
+ data.tar.gz: 236392df8641f5c37a3022249e4253587352fcd5024180fc36b5f4171525a66218433b114805b7762836c134da7d1fd40ab8c52b2b560e86786eb84d2f10d365
@@ -21,31 +21,31 @@
21
21
  require_relative 'distance'
22
22
 
23
23
  module Geospatial
24
- # This location is specifically relating to a WGS84 coordinate on Earth.
25
- class Location
26
- # WGS 84 semi-major axis constant in meters
27
- WGS84_A = 6378137.0
28
- # WGS 84 semi-minor axis constant in meters
29
- WGS84_B = 6356752.3
30
-
31
- # Earth Radius
32
- R = (WGS84_A + WGS84_B) / 2.0
33
-
34
- # WGS 84 eccentricity
35
- WGS84_E = 8.1819190842622e-2
24
+ # WGS 84 semi-major axis constant in meters
25
+ WGS84_A = 6378137.0
26
+ # WGS 84 semi-minor axis constant in meters
27
+ WGS84_B = 6356752.3
28
+
29
+ # Earth Radius
30
+ R = (WGS84_A + WGS84_B) / 2.0
31
+
32
+ # WGS 84 eccentricity
33
+ WGS84_E = 8.1819190842622e-2
36
34
 
37
- # Radians to degrees multiplier
38
- R2D = (180.0 / Math::PI)
39
- D2R = (Math::PI / 180.0)
35
+ # Radians to degrees multiplier
36
+ R2D = (180.0 / Math::PI)
37
+ D2R = (Math::PI / 180.0)
40
38
 
41
- MIN_LONGITUDE = -180.0 * D2R
42
- MAX_LONGITUDE = 180.0 * D2R
43
- VALID_LONGITUDE = -180.0...180.0
39
+ MIN_LONGITUDE = -180.0 * D2R
40
+ MAX_LONGITUDE = 180.0 * D2R
41
+ VALID_LONGITUDE = -180.0...180.0
44
42
 
45
- MIN_LATITUDE = -90.0 * D2R
46
- MAX_LATITUDE = 90.0 * D2R
47
- VALID_LATITUDE = -90.0...90.0
48
-
43
+ MIN_LATITUDE = -90.0 * D2R
44
+ MAX_LATITUDE = 90.0 * D2R
45
+ VALID_LATITUDE = -90.0...90.0
46
+
47
+ # This location is specifically relating to a WGS84 coordinate on Earth.
48
+ class Location
49
49
  class << self
50
50
  def from_ecef(x, y, z)
51
51
  # Constants (WGS ellipsoid)
@@ -77,6 +77,24 @@ module Geospatial
77
77
  end
78
78
  end
79
79
 
80
+ # @param [Float] radius The radius of the sphere on which to compute the area.
81
+ def area(radius = 1.0)
82
+ if @points.size > 2
83
+ area = 0.0
84
+
85
+ self.edges.each do |p1, p2|
86
+ r1 = (p2[0] - p1[0]) * D2R
87
+ r2 = 2 + Math::sin(p1[1] * D2R) + Math::sin(p2[1] * D2R)
88
+
89
+ area += r1 * r2
90
+ end
91
+
92
+ return (area * radius * radius / 2.0).abs
93
+ else
94
+ return 0.0
95
+ end
96
+ end
97
+
80
98
  def simplify(minimum_distance = 1)
81
99
  simplified_points = @points.first(1)
82
100
 
@@ -103,7 +121,7 @@ module Geospatial
103
121
  count = 0
104
122
 
105
123
  edges.each do |pa, pb|
106
- if pa[1] <= p[1]
124
+ if pa[1] <= p[1]
107
125
  if pb[1] >= p[1] and Polygon.is_left(pa, pb, p) > 0
108
126
  count += 1
109
127
  end
@@ -121,7 +139,7 @@ module Geospatial
121
139
  def include_point?(point)
122
140
  return false unless bounding_box.include_point?(point)
123
141
 
124
- self.winding_number(point) == 1
142
+ self.winding_number(point).odd?
125
143
  end
126
144
 
127
145
  def intersect_with_box?(other)
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Geospatial
22
- VERSION = "1.11.1"
22
+ VERSION = "1.12.0"
23
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geospatial
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.1
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-25 00:00:00.000000000 Z
11
+ date: 2018-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  version: '0'
126
126
  requirements: []
127
127
  rubyforge_project:
128
- rubygems_version: 2.7.7
128
+ rubygems_version: 2.7.8
129
129
  signing_key:
130
130
  specification_version: 4
131
131
  summary: Provides abstractions for dealing with geographical locations efficiently