geospatial 1.7.0 → 1.8.0
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/.travis.yml +2 -7
- data/lib/geospatial/dimensions.rb +4 -0
- data/lib/geospatial/histogram.rb +18 -11
- data/lib/geospatial/location.rb +19 -3
- data/lib/geospatial/tiles.rb +68 -0
- data/lib/geospatial/version.rb +1 -1
- data/spec/geospatial/tiles_spec.rb +31 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 110738e0a022fbd6b133c9d9e28b12e0bcb695c7ab7649cf17d654e634172489
|
4
|
+
data.tar.gz: 9b95095906672c0e8e7cc1db514ef60ef3382bf26c64a6b3197d767a38582715
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 347668d651ee545201053b43be845dd9812e54cf1921125decd7aa6875423a9fb3bd8493c0187c8d77d2e85e9e720f9f8b503176bf7e584d277b99cb973c870c
|
7
|
+
data.tar.gz: 19228fff1b436087f3ce92a64b753b2a2338040d40f13c919b2d2a2d0d4f69f7428aca95ffb48ade10615c77439bc78714affa9141ee03e8d77796764139fd92
|
data/.travis.yml
CHANGED
@@ -1,18 +1,13 @@
|
|
1
1
|
language: ruby
|
2
|
-
sudo: false
|
3
|
-
dist: trusty
|
4
2
|
cache: bundler
|
5
3
|
rvm:
|
6
|
-
- 2.0
|
7
|
-
- 2.1
|
8
|
-
- 2.2
|
9
4
|
- 2.3
|
10
5
|
- 2.4
|
6
|
+
- 2.5
|
7
|
+
- 2.6
|
11
8
|
- jruby-head
|
12
9
|
- ruby-head
|
13
|
-
- rbx-3
|
14
10
|
matrix:
|
15
11
|
allow_failures:
|
16
12
|
- rvm: ruby-head
|
17
13
|
- rvm: jruby-head
|
18
|
-
- rvm: rbx-3
|
@@ -23,6 +23,10 @@ require 'matrix'
|
|
23
23
|
module Geospatial
|
24
24
|
# An integral dimension which maps a continuous space into an integral space. The scale is the maximum integral unit.
|
25
25
|
class Dimension
|
26
|
+
def self.map(min, max, steps)
|
27
|
+
self.new(min, max-min, steps)
|
28
|
+
end
|
29
|
+
|
26
30
|
def initialize(origin, size, scale = 1.0)
|
27
31
|
@origin = origin
|
28
32
|
@size = size
|
data/lib/geospatial/histogram.rb
CHANGED
@@ -23,8 +23,16 @@ module Geospatial
|
|
23
23
|
attr :offset
|
24
24
|
attr :scale
|
25
25
|
|
26
|
+
def map(value)
|
27
|
+
((value - @min) / @scale)
|
28
|
+
end
|
29
|
+
|
30
|
+
def unmap(index)
|
31
|
+
@min + ((index + 0.5) * @scale)
|
32
|
+
end
|
33
|
+
|
26
34
|
def add(value, amount = 1)
|
27
|
-
index = (
|
35
|
+
index = map(value).floor
|
28
36
|
|
29
37
|
if @bins[index]
|
30
38
|
@bins[index] += amount
|
@@ -35,23 +43,23 @@ module Geospatial
|
|
35
43
|
return self
|
36
44
|
end
|
37
45
|
|
38
|
-
def peaks
|
39
|
-
@bins.each_with_index
|
40
|
-
end
|
41
|
-
|
42
|
-
def offset(index)
|
43
|
-
@min + (index * @scale)
|
44
|
-
end
|
45
|
-
|
46
46
|
def inspect
|
47
47
|
buffer = String.new("\#<#{self.class}")
|
48
48
|
|
49
49
|
@bins.each_with_index do |bin, index|
|
50
|
-
buffer << "\n#{
|
50
|
+
buffer << "\n#{unmap(index).to_s.rjust(8)}: #{bin}"
|
51
51
|
end
|
52
52
|
|
53
53
|
buffer << "\n>"
|
54
54
|
end
|
55
|
+
|
56
|
+
def each
|
57
|
+
return to_enum unless block_given?
|
58
|
+
|
59
|
+
@bins.each_with_index do |value, index|
|
60
|
+
yield unmap(index), value
|
61
|
+
end
|
62
|
+
end
|
55
63
|
end
|
56
64
|
|
57
65
|
class RadialHistogram < Histogram
|
@@ -65,5 +73,4 @@ module Geospatial
|
|
65
73
|
super(point.bearing_from(@center), value)
|
66
74
|
end
|
67
75
|
end
|
68
|
-
|
69
76
|
end
|
data/lib/geospatial/location.rb
CHANGED
@@ -28,7 +28,8 @@ module Geospatial
|
|
28
28
|
# WGS 84 semi-minor axis constant in meters
|
29
29
|
WGS84_B = 6356752.3
|
30
30
|
|
31
|
-
|
31
|
+
# Earth Radius
|
32
|
+
R = (WGS84_A + WGS84_B) / 2.0
|
32
33
|
|
33
34
|
# WGS 84 eccentricity
|
34
35
|
WGS84_E = 8.1819190842622e-2
|
@@ -82,6 +83,10 @@ module Geospatial
|
|
82
83
|
[@longitude, @latitude]
|
83
84
|
end
|
84
85
|
|
86
|
+
def to_ary
|
87
|
+
to_a
|
88
|
+
end
|
89
|
+
|
85
90
|
def to_s
|
86
91
|
"#{self.class}[#{self.longitude.to_f}, #{self.latitude.to_f}]"
|
87
92
|
end
|
@@ -92,7 +97,7 @@ module Geospatial
|
|
92
97
|
attr :latitude # -90 -> 90 (equivalent to y)
|
93
98
|
|
94
99
|
# http://janmatuschek.de/LatitudeLongitudeBoundingCoordinates
|
95
|
-
def bounding_box(distance, radius =
|
100
|
+
def bounding_box(distance, radius = R)
|
96
101
|
raise ArgumentError.new("Invalid distance or radius") if distance < 0 or radius < 0
|
97
102
|
|
98
103
|
# angular distance in radians on a great circle
|
@@ -153,7 +158,7 @@ module Geospatial
|
|
153
158
|
|
154
159
|
a = Math::sin(dlat/2) ** 2 + Math::cos(rlat1) * Math::cos(rlat2) * Math::sin(dlon/2) ** 2
|
155
160
|
c = 2 * Math::atan2(Math::sqrt(a), Math::sqrt(1-a))
|
156
|
-
d =
|
161
|
+
d = R * c
|
157
162
|
|
158
163
|
return d
|
159
164
|
end
|
@@ -170,6 +175,17 @@ module Geospatial
|
|
170
175
|
) * R2D
|
171
176
|
end
|
172
177
|
|
178
|
+
def location_by(bearing, distance)
|
179
|
+
lon1 = self.longitude * D2R
|
180
|
+
lat1 = self.latitude * D2R
|
181
|
+
|
182
|
+
lat2 = Math::asin(Math::sin(lat1)*Math::cos(distance/R) + Math::cos(lat1)*Math::sin(distance/R)*Math::cos(bearing * D2R))
|
183
|
+
|
184
|
+
lon2 = lon1 + Math::atan2(Math::sin(bearing * D2R)*Math::sin(distance/R)*Math::cos(lat1), Math::cos(distance/R)-Math::sin(lat1)*Math::sin(lat2))
|
185
|
+
|
186
|
+
return self.class.new(lon2 * R2D, lat2 * R2D)
|
187
|
+
end
|
188
|
+
|
173
189
|
def - other
|
174
190
|
Distance.new(self.distance_from(other))
|
175
191
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require_relative 'box'
|
22
|
+
|
23
|
+
module Geospatial
|
24
|
+
class Tiles
|
25
|
+
# Radians to degrees multiplier
|
26
|
+
R2D = (180.0 / Math::PI)
|
27
|
+
D2R = (Math::PI / 180.0)
|
28
|
+
|
29
|
+
def initialize(box, zoom = 5)
|
30
|
+
@box = box
|
31
|
+
@zoom = zoom
|
32
|
+
end
|
33
|
+
|
34
|
+
attr :box
|
35
|
+
attr :zoom
|
36
|
+
|
37
|
+
def map(longitude, latitude, zoom = @zoom)
|
38
|
+
n = 2 ** zoom
|
39
|
+
|
40
|
+
x = n * ((longitude + 180.0) / 360.0)
|
41
|
+
y = n * (1.0 - (Math::log(Math::tan(latitude * D2R) + (1.0 / Math::cos(latitude * D2R))) / Math::PI)) / 2.0
|
42
|
+
|
43
|
+
return x, y
|
44
|
+
end
|
45
|
+
|
46
|
+
def unmap(x, y, zoom = @zoom)
|
47
|
+
n = 2 ** zoom
|
48
|
+
longitude = x / n * 360.0 - 180.0
|
49
|
+
latitude = Math::arctan(Math::sinh(Math::PI * (1.0 - 2.0 * y / n))) * R2D
|
50
|
+
|
51
|
+
return longitude, latitude
|
52
|
+
end
|
53
|
+
|
54
|
+
def each(zoom = @zoom)
|
55
|
+
return to_enum(:each, zoom) unless block_given?
|
56
|
+
|
57
|
+
min = map(*@box.min, zoom)
|
58
|
+
max = map(*@box.max, zoom)
|
59
|
+
|
60
|
+
(min[0].floor...max[0].ceil).each do |x|
|
61
|
+
# The y axis is reversed... (i.e. the origin is in the top left)
|
62
|
+
(max[1].floor...min[1].ceil).each do |y|
|
63
|
+
yield zoom, x, y
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/geospatial/version.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'geospatial/tiles'
|
22
|
+
|
23
|
+
RSpec.describe Geospatial::Tiles do
|
24
|
+
let(:box) {Geospatial::Box.from_bounds(Vector[172.0,-44.0], Vector[173.5,-43.0])}
|
25
|
+
|
26
|
+
subject {described_class.new(box)}
|
27
|
+
|
28
|
+
it "should enumerate tiles" do
|
29
|
+
expect(subject.each.to_a).to be == [[5, 31, 20]]
|
30
|
+
end
|
31
|
+
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.
|
4
|
+
version: 1.8.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-
|
11
|
+
date: 2018-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- lib/geospatial/map.rb
|
84
84
|
- lib/geospatial/map/index.rb
|
85
85
|
- lib/geospatial/polygon.rb
|
86
|
+
- lib/geospatial/tiles.rb
|
86
87
|
- lib/geospatial/version.rb
|
87
88
|
- spec/geospatial/box_spec.rb
|
88
89
|
- spec/geospatial/circle_spec.rb
|
@@ -97,6 +98,7 @@ files:
|
|
97
98
|
- spec/geospatial/map_spec.rb
|
98
99
|
- spec/geospatial/polygon_spec.rb
|
99
100
|
- spec/geospatial/sorted.rb
|
101
|
+
- spec/geospatial/tiles_spec.rb
|
100
102
|
- spec/geospatial/visualization.rb
|
101
103
|
- spec/geospatial/world.png
|
102
104
|
- spec/spec_helper.rb
|
@@ -138,6 +140,7 @@ test_files:
|
|
138
140
|
- spec/geospatial/map_spec.rb
|
139
141
|
- spec/geospatial/polygon_spec.rb
|
140
142
|
- spec/geospatial/sorted.rb
|
143
|
+
- spec/geospatial/tiles_spec.rb
|
141
144
|
- spec/geospatial/visualization.rb
|
142
145
|
- spec/geospatial/world.png
|
143
146
|
- spec/spec_helper.rb
|