geospatial 0.0.1 → 1.0.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/.gitignore +1 -0
- data/.travis.yml +11 -2
- data/Gemfile +12 -1
- data/README.md +37 -8
- data/Rakefile +11 -0
- data/australia.png +0 -0
- data/geospatial.gemspec +1 -1
- data/lib/geospatial/box.rb +126 -0
- data/lib/geospatial/circle.rb +109 -0
- data/lib/geospatial/dimensions.rb +130 -0
- data/lib/geospatial/filter.rb +82 -0
- data/lib/geospatial/hilbert/curve.rb +79 -0
- data/lib/geospatial/hilbert/traverse.rb +65 -0
- data/lib/geospatial/hilbert.rb +111 -90
- data/lib/geospatial/index.rb +80 -0
- data/lib/geospatial/interleave.rb +69 -0
- data/lib/geospatial/location.rb +53 -32
- data/lib/geospatial/map/index.rb +57 -0
- data/lib/geospatial/map.rb +153 -0
- data/lib/geospatial/polygon.rb +115 -0
- data/lib/geospatial/version.rb +21 -1
- data/lib/geospatial.rb +22 -3
- data/spec/geospatial/box_spec.rb +42 -0
- data/spec/geospatial/circle_spec.rb +76 -0
- data/spec/geospatial/dimensions_spec.rb +35 -0
- data/spec/geospatial/hilbert_curve_spec.rb +59 -0
- data/spec/geospatial/hilbert_traverse_spec.rb +63 -0
- data/spec/geospatial/index_spec.rb +113 -0
- data/spec/{geoquery → geospatial}/location_spec.rb +4 -4
- data/spec/geospatial/map_index_spec.rb +41 -0
- data/spec/geospatial/map_spec.rb +71 -0
- data/spec/geospatial/polygon_spec.rb +96 -0
- data/spec/geospatial/sorted.rb +6 -0
- data/spec/geospatial/visualization.rb +46 -0
- data/spec/geospatial/world.png +0 -0
- metadata +43 -9
- data/spec/geoquery/hilbert_spec.rb +0 -72
@@ -0,0 +1,113 @@
|
|
1
|
+
# Copyright, 2015, 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/index'
|
22
|
+
require_relative 'sorted'
|
23
|
+
|
24
|
+
RSpec.shared_context "hilbert index" do
|
25
|
+
it "computes the correct hash" do
|
26
|
+
coordinates.each do |coordinate, encoded|
|
27
|
+
index = Geospatial::OrdinalIndex.new(coordinate, bits)
|
28
|
+
|
29
|
+
# puts "c: #{coordinate} i: #{index.inspect} h: #{index.to_hilbert.inspect} #{index.to_hilbert.to_i} == #{encoded}"
|
30
|
+
|
31
|
+
expect(index.to_hilbert.to_i).to be == encoded
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "computes the correct unhash" do
|
36
|
+
coordinates.each do |coordinate, encoded|
|
37
|
+
index = Geospatial::HilbertIndex.from_integral(encoded, coordinate.size, bits)
|
38
|
+
|
39
|
+
expect(index.to_ordinal.axes).to be == coordinate
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
RSpec.describe "order=0 n=2" do
|
45
|
+
let(:coordinates) {
|
46
|
+
{
|
47
|
+
#y, x
|
48
|
+
[0, 0] => 0b00,
|
49
|
+
[0, 1] => 0b01,
|
50
|
+
[1, 1] => 0b10,
|
51
|
+
[1, 0] => 0b11
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
let(:bits) {1}
|
56
|
+
|
57
|
+
it_behaves_like "hilbert index"
|
58
|
+
end
|
59
|
+
|
60
|
+
RSpec.describe "order=0 n=3" do
|
61
|
+
let(:coordinates) {
|
62
|
+
{
|
63
|
+
# The sequence on the left walks through the hilbert curve in 3-space, while on the right is stepping incrementally through the curve.
|
64
|
+
[0, 0, 0] => 0b000,
|
65
|
+
[0, 0, 1] => 0b001,
|
66
|
+
[0, 1, 1] => 0b010,
|
67
|
+
[0, 1, 0] => 0b011,
|
68
|
+
[1, 1, 0] => 0b100,
|
69
|
+
[1, 1, 1] => 0b101,
|
70
|
+
[1, 0, 1] => 0b110,
|
71
|
+
[1, 0, 0] => 0b111,
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
let(:bits) {1}
|
76
|
+
|
77
|
+
it_behaves_like "hilbert index"
|
78
|
+
end
|
79
|
+
|
80
|
+
RSpec.describe "order=1 n=2" do
|
81
|
+
# Curves of odd order, move on the most significant axis first (so that their top level motion is equivalent)
|
82
|
+
let(:coordinates) {
|
83
|
+
{
|
84
|
+
# Lower left quadrant
|
85
|
+
[0, 0] => 0b0000,
|
86
|
+
[1, 0] => 0b0001,
|
87
|
+
[1, 1] => 0b0010,
|
88
|
+
[0, 1] => 0b0011,
|
89
|
+
|
90
|
+
# Lower right quadrant
|
91
|
+
[0, 2] => 0b0100,
|
92
|
+
[0, 3] => 0b0101,
|
93
|
+
[1, 3] => 0b0110,
|
94
|
+
[1, 2] => 0b0111,
|
95
|
+
|
96
|
+
# Upper right quadrant
|
97
|
+
[2, 2] => 0b1000,
|
98
|
+
[2, 3] => 0b1001,
|
99
|
+
[3, 3] => 0b1010,
|
100
|
+
[3, 2] => 0b1011,
|
101
|
+
|
102
|
+
# Upper left quadrant
|
103
|
+
[3, 1] => 0b1100,
|
104
|
+
[2, 1] => 0b1101,
|
105
|
+
[2, 0] => 0b1110,
|
106
|
+
[3, 0] => 0b1111,
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
let(:bits) {2}
|
111
|
+
|
112
|
+
it_behaves_like "hilbert index"
|
113
|
+
end
|
@@ -22,11 +22,11 @@ require 'geospatial/location'
|
|
22
22
|
|
23
23
|
module Geospatial::LocationSpec
|
24
24
|
describe Geospatial::Location do
|
25
|
+
let(:lake_tekapo) {Geospatial::Location.new(170.53, -43.89)}
|
26
|
+
let(:lake_alex) {Geospatial::Location.new(170.45, -43.94)}
|
27
|
+
|
25
28
|
it "compute the correct distance between two points" do
|
26
|
-
|
27
|
-
lake_alex = Geospatial::Location.new(-43.95, 170.45)
|
28
|
-
|
29
|
-
expect(lake_alex.distance_from(lake_tekapo)).to be_within(10).of(9_130)
|
29
|
+
expect(lake_alex.distance_from(lake_tekapo)).to be_within(100).of(8_500)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Copyright, 2015, 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/map/index'
|
22
|
+
|
23
|
+
RSpec.describe Geospatial::Map::Index do
|
24
|
+
let(:map) {Geospatial::Map.for_earth(30)}
|
25
|
+
let(:subject) {map.index}
|
26
|
+
|
27
|
+
let(:lake_alex) {Geospatial::Location.new(170.45, -43.94)}
|
28
|
+
let(:point) {map.point_for_coordinates(lake_alex.to_a)}
|
29
|
+
|
30
|
+
it "should dump to hash" do
|
31
|
+
expect(subject.dump(point)).to be == point.hash
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should load hash" do
|
35
|
+
truncated_point = subject.load(point.hash)
|
36
|
+
distance = Geospatial::Location.new(*truncated_point.coordinates).distance_from(lake_alex)
|
37
|
+
|
38
|
+
# The distance between the truncated point and the original point should be < 10 meters.
|
39
|
+
expect(distance).to be < 10
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# Copyright, 2015, 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/hilbert'
|
22
|
+
require 'geospatial/map'
|
23
|
+
|
24
|
+
require_relative 'visualization'
|
25
|
+
|
26
|
+
RSpec.describe Geospatial::Map.for_earth do
|
27
|
+
let(:lake_tekapo) {Geospatial::Location.new(170.53, -43.89)}
|
28
|
+
let(:lake_alex) {Geospatial::Location.new(170.45, -43.94)}
|
29
|
+
let(:sydney) {Geospatial::Location.new(151.21, -33.85)}
|
30
|
+
|
31
|
+
let(:new_zealand) {Geospatial::Box.from_bounds(Vector[166.0, -48.0], Vector[180.0, -34.0])}
|
32
|
+
let(:australia) {Geospatial::Box.from_bounds(Vector[112.0, -45.0], Vector[155.0, -10.0])}
|
33
|
+
|
34
|
+
it "can generate visualisation" do
|
35
|
+
Geospatial::Visualization.for_map(subject) do |pdf, origin|
|
36
|
+
size = australia.size
|
37
|
+
top_left = (origin + australia.min) + Vector[0, size[1]]
|
38
|
+
pdf.rectangle(top_left.to_a, *size.to_a)
|
39
|
+
|
40
|
+
pdf.fill
|
41
|
+
|
42
|
+
subject.traverse(australia, depth: subject.order - 10) do |child, prefix, order|
|
43
|
+
size = child.size
|
44
|
+
top_left = (origin + child.min) + Vector[0, size[1]]
|
45
|
+
pdf.rectangle(top_left.to_a, *size.to_a)
|
46
|
+
end
|
47
|
+
|
48
|
+
pdf.fill_and_stroke
|
49
|
+
end.render_file "map.pdf"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should add points" do
|
53
|
+
subject << lake_tekapo
|
54
|
+
subject << lake_alex
|
55
|
+
|
56
|
+
subject.sort!
|
57
|
+
|
58
|
+
expect(subject.count).to be == 2
|
59
|
+
expect(subject.points[0].hash).to be <= subject.points[1].hash
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should find points in New Zealand" do
|
63
|
+
subject << lake_tekapo << lake_alex << sydney
|
64
|
+
|
65
|
+
subject.sort!
|
66
|
+
|
67
|
+
points = subject.query(new_zealand, depth: 10)
|
68
|
+
expect(points).to include(lake_tekapo, lake_alex)
|
69
|
+
expect(points).to_not include(sydney)
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# Copyright, 2016, 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/polygon'
|
22
|
+
|
23
|
+
require_relative 'visualization'
|
24
|
+
|
25
|
+
RSpec.shared_context "kaikoura region" do
|
26
|
+
let(:region) do
|
27
|
+
Geospatial::Polygon[
|
28
|
+
Vector[173.7218528654108, -42.32817252073923],
|
29
|
+
Vector[173.6307775307161, -42.32729039137249],
|
30
|
+
Vector[173.5400659958715, -42.39758413896335],
|
31
|
+
Vector[173.5446498680837, -42.43847509799515],
|
32
|
+
Vector[173.6833471779081, -42.44870319335309],
|
33
|
+
Vector[173.7608096128163, -42.42144813099029],
|
34
|
+
Vector[173.7218528654108, -42.32817252073923],
|
35
|
+
]
|
36
|
+
end
|
37
|
+
|
38
|
+
let(:filter) {subject.filter_for(region)}
|
39
|
+
let(:kaikoura) {Geospatial::Location.new(173.6814, -42.4008)}
|
40
|
+
end
|
41
|
+
|
42
|
+
RSpec.describe Geospatial::Polygon.new([Vector[0.0, 0.0], Vector[1.0, 0.0], Vector[0.0, 1.0]]) do
|
43
|
+
it "should intersect point on edge" do
|
44
|
+
is_expected.to be_include_point(Vector[0.0, 0.0])
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should not intersect point outside" do
|
48
|
+
is_expected.to_not be_include_point(Vector[1.0, 0.5])
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should intersect point inside" do
|
52
|
+
is_expected.to be_include_point(Vector[0.2, 0.2])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
RSpec.describe Geospatial::Map.for_earth(22) do
|
57
|
+
include_context "kaikoura region"
|
58
|
+
|
59
|
+
it "should contain some prefixes" do
|
60
|
+
expect(filter.ranges).to_not be_empty
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should contain kaikoura" do
|
64
|
+
point = subject.point_for_object(kaikoura)
|
65
|
+
expect(filter).to include(point)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
RSpec.describe Geospatial::Polygon do
|
70
|
+
include_context "kaikoura region"
|
71
|
+
|
72
|
+
it "can generate visualisation" do
|
73
|
+
map = Geospatial::Map.for_earth
|
74
|
+
|
75
|
+
map << kaikoura
|
76
|
+
|
77
|
+
Geospatial::Visualization.for_map(map) do |pdf, origin|
|
78
|
+
region.edges do |pa, pb|
|
79
|
+
pdf.line (origin + pa).to_a, (origin + pb).to_a
|
80
|
+
end
|
81
|
+
|
82
|
+
#count = 0
|
83
|
+
map.traverse(region, depth: map.order - 15) do |child, prefix, order|
|
84
|
+
#count += 1
|
85
|
+
size = child.size
|
86
|
+
top_left = (origin + child.min) + Vector[0, size[1]]
|
87
|
+
pdf.rectangle(top_left.to_a, *size.to_a)
|
88
|
+
# puts "#{top_left.to_a} #{size.to_a}"
|
89
|
+
end
|
90
|
+
|
91
|
+
#puts "count=#{count}"
|
92
|
+
|
93
|
+
pdf.fill_and_stroke
|
94
|
+
end.render_file "polygon.pdf"
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
require 'geospatial/map'
|
3
|
+
require 'prawn'
|
4
|
+
|
5
|
+
module Geospatial
|
6
|
+
module Visualization
|
7
|
+
def self.for_map(map)
|
8
|
+
margin = 10
|
9
|
+
scale = 16.0
|
10
|
+
size = map.bounds.size.to_a
|
11
|
+
half_size = size.map{|i| i.to_f / 2}
|
12
|
+
origin = [size[0] / 2, size[1] / 2]
|
13
|
+
|
14
|
+
pdf = Prawn::Document.new(
|
15
|
+
page_size: [(size[0] + 40) * scale, (size[1] + 40) * scale],
|
16
|
+
margin: 20,
|
17
|
+
)
|
18
|
+
|
19
|
+
pdf.line_width 0.001
|
20
|
+
pdf.scale(scale)
|
21
|
+
|
22
|
+
world_path = File.expand_path("world.png", __dir__)
|
23
|
+
pdf.image world_path, :at => [0, 180], width: 360, height: 180
|
24
|
+
|
25
|
+
pdf.stroke_axis(step_length: 45)
|
26
|
+
|
27
|
+
pdf.transparent(0.3, 0.9) do
|
28
|
+
pdf.stroke_color "000000"
|
29
|
+
pdf.fill_color "00abcc"
|
30
|
+
|
31
|
+
yield pdf, Vector[*origin]
|
32
|
+
|
33
|
+
pdf.fill_color "00ff00"
|
34
|
+
|
35
|
+
map.points.each do |point|
|
36
|
+
center = [origin[0] + point[0], origin[1] + point[1]]
|
37
|
+
pdf.circle center, 0.1
|
38
|
+
end
|
39
|
+
|
40
|
+
pdf.fill
|
41
|
+
end
|
42
|
+
|
43
|
+
return pdf
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
Binary file
|
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: 0.0
|
4
|
+
version: 1.0.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:
|
11
|
+
date: 2016-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.
|
19
|
+
version: '3.4'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 3.
|
26
|
+
version: '3.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,13 +66,36 @@ files:
|
|
66
66
|
- Gemfile
|
67
67
|
- README.md
|
68
68
|
- Rakefile
|
69
|
+
- australia.png
|
69
70
|
- geospatial.gemspec
|
70
71
|
- lib/geospatial.rb
|
72
|
+
- lib/geospatial/box.rb
|
73
|
+
- lib/geospatial/circle.rb
|
74
|
+
- lib/geospatial/dimensions.rb
|
75
|
+
- lib/geospatial/filter.rb
|
71
76
|
- lib/geospatial/hilbert.rb
|
77
|
+
- lib/geospatial/hilbert/curve.rb
|
78
|
+
- lib/geospatial/hilbert/traverse.rb
|
79
|
+
- lib/geospatial/index.rb
|
80
|
+
- lib/geospatial/interleave.rb
|
72
81
|
- lib/geospatial/location.rb
|
82
|
+
- lib/geospatial/map.rb
|
83
|
+
- lib/geospatial/map/index.rb
|
84
|
+
- lib/geospatial/polygon.rb
|
73
85
|
- lib/geospatial/version.rb
|
74
|
-
- spec/
|
75
|
-
- spec/
|
86
|
+
- spec/geospatial/box_spec.rb
|
87
|
+
- spec/geospatial/circle_spec.rb
|
88
|
+
- spec/geospatial/dimensions_spec.rb
|
89
|
+
- spec/geospatial/hilbert_curve_spec.rb
|
90
|
+
- spec/geospatial/hilbert_traverse_spec.rb
|
91
|
+
- spec/geospatial/index_spec.rb
|
92
|
+
- spec/geospatial/location_spec.rb
|
93
|
+
- spec/geospatial/map_index_spec.rb
|
94
|
+
- spec/geospatial/map_spec.rb
|
95
|
+
- spec/geospatial/polygon_spec.rb
|
96
|
+
- spec/geospatial/sorted.rb
|
97
|
+
- spec/geospatial/visualization.rb
|
98
|
+
- spec/geospatial/world.png
|
76
99
|
homepage: https://github.com/ioquatix/geospatial
|
77
100
|
licenses:
|
78
101
|
- MIT
|
@@ -93,10 +116,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
116
|
version: '0'
|
94
117
|
requirements: []
|
95
118
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.
|
119
|
+
rubygems_version: 2.5.2
|
97
120
|
signing_key:
|
98
121
|
specification_version: 4
|
99
122
|
summary: Provides abstractions for dealing with geographical locations efficiently
|
100
123
|
test_files:
|
101
|
-
- spec/
|
102
|
-
- spec/
|
124
|
+
- spec/geospatial/box_spec.rb
|
125
|
+
- spec/geospatial/circle_spec.rb
|
126
|
+
- spec/geospatial/dimensions_spec.rb
|
127
|
+
- spec/geospatial/hilbert_curve_spec.rb
|
128
|
+
- spec/geospatial/hilbert_traverse_spec.rb
|
129
|
+
- spec/geospatial/index_spec.rb
|
130
|
+
- spec/geospatial/location_spec.rb
|
131
|
+
- spec/geospatial/map_index_spec.rb
|
132
|
+
- spec/geospatial/map_spec.rb
|
133
|
+
- spec/geospatial/polygon_spec.rb
|
134
|
+
- spec/geospatial/sorted.rb
|
135
|
+
- spec/geospatial/visualization.rb
|
136
|
+
- spec/geospatial/world.png
|
@@ -1,72 +0,0 @@
|
|
1
|
-
# Copyright, 2015, 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/hilbert'
|
22
|
-
|
23
|
-
module Geospatial::HilbertSpec
|
24
|
-
describe Geospatial::Hilbert do
|
25
|
-
it "base case should be identity" do
|
26
|
-
# The base case for our coordinate system:
|
27
|
-
expect(Geospatial::Hilbert.rotate(0, 0)).to be == 0
|
28
|
-
expect(Geospatial::Hilbert.rotate(0, 1)).to be == 1
|
29
|
-
expect(Geospatial::Hilbert.rotate(0, 2)).to be == 2
|
30
|
-
expect(Geospatial::Hilbert.rotate(0, 3)).to be == 3
|
31
|
-
end
|
32
|
-
|
33
|
-
it "rotation is self-inverting" do
|
34
|
-
4.times do |rotation|
|
35
|
-
4.times do |quadrant|
|
36
|
-
# rotate(rotation, rotate(rotation, quadrant)) == quadrant
|
37
|
-
rotated = Geospatial::Hilbert.rotate(rotation, quadrant)
|
38
|
-
expect(Geospatial::Hilbert.rotate(rotation, rotated)).to be == quadrant
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
it "compute the correct hash of order=0" do
|
44
|
-
expect(Geospatial::Hilbert.hash(0, 0, 0)).to be == 0
|
45
|
-
expect(Geospatial::Hilbert.hash(1, 0, 0)).to be == 1
|
46
|
-
expect(Geospatial::Hilbert.hash(1, 1, 0)).to be == 2
|
47
|
-
expect(Geospatial::Hilbert.hash(0, 1, 0)).to be == 3
|
48
|
-
end
|
49
|
-
|
50
|
-
it "compute the correct hash of order=1" do
|
51
|
-
expect(Geospatial::Hilbert.hash(0, 0, 1)).to be == 0
|
52
|
-
expect(Geospatial::Hilbert.hash(1, 0, 1)).to be == 1
|
53
|
-
expect(Geospatial::Hilbert.hash(1, 1, 1)).to be == 2
|
54
|
-
expect(Geospatial::Hilbert.hash(0, 1, 1)).to be == 3
|
55
|
-
|
56
|
-
expect(Geospatial::Hilbert.hash(0, 2, 1)).to be == 4
|
57
|
-
expect(Geospatial::Hilbert.hash(0, 3, 1)).to be == 5
|
58
|
-
expect(Geospatial::Hilbert.hash(1, 3, 1)).to be == 6
|
59
|
-
expect(Geospatial::Hilbert.hash(1, 2, 1)).to be == 7
|
60
|
-
|
61
|
-
expect(Geospatial::Hilbert.hash(2, 2, 1)).to be == 8
|
62
|
-
expect(Geospatial::Hilbert.hash(2, 3, 1)).to be == 9
|
63
|
-
expect(Geospatial::Hilbert.hash(3, 3, 1)).to be == 10
|
64
|
-
expect(Geospatial::Hilbert.hash(3, 2, 1)).to be == 11
|
65
|
-
|
66
|
-
expect(Geospatial::Hilbert.hash(3, 1, 1)).to be == 12
|
67
|
-
expect(Geospatial::Hilbert.hash(2, 1, 1)).to be == 13
|
68
|
-
expect(Geospatial::Hilbert.hash(2, 0, 1)).to be == 14
|
69
|
-
expect(Geospatial::Hilbert.hash(3, 0, 1)).to be == 15
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|