geospatial 1.2.0 → 1.3.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
  SHA1:
3
- metadata.gz: f680a683a9711ab54aa842e366d8bcf331201221
4
- data.tar.gz: c9a05d601b5e06486bdcf5a387ebcdeb3c771ec9
3
+ metadata.gz: '08c617f2553f89f8517d92ddb199e6fea96e9944'
4
+ data.tar.gz: 8035d32514e61d2a6803181ca6fd8e1edaaa7df4
5
5
  SHA512:
6
- metadata.gz: ffb91f9ce99d727800906b8781b378753b508c16b54bac52f4fd6bcd0b51fd1a1467728d82b20ca18c2905e2c36fba31b10975512dde2dc60dd8f24f2350a904
7
- data.tar.gz: fb3e122187a2d047485253e90db1e19acd6b0d2667f331fd17326034c98f2483c01b6fe6c5e9929f9e0839d67c89c483b38095a5570d6fcf3ded6485b39945bc
6
+ metadata.gz: b6bd5d3e78d85dba02e4fcb4e184c1c9f9a70ee4499955a7b14098cf2110126dc8dec7bb83adbcbd3a5c53746b3df4c254faee864e9a59d3505218b65fafdca0
7
+ data.tar.gz: ccd3725544626d4a89f9de9b7e4c6a5907572fb4be42cb4b3015e0cb6cc6f43fdd8c17b5aa4b8a496f015e5030434cf5d5e518305a55b6d360c093e99bc84d1e
data/README.md CHANGED
@@ -14,6 +14,8 @@ We had a need to query a database of places efficiently using SQLite. We did som
14
14
 
15
15
  After researching geospatial hashing algorithms, I found [this blog post](http://blog.notdot.net/2009/11/Damn-Cool-Algorithms-Spatial-indexing-with-Quadtrees-and-Hilbert-Curves) and decided to implement a geospatial hash using the Hilbert curve. This library exposes a fast indexing and querying mechanism based on Hilbert curves, for points on a map, which can be integrated into a database or other systems as required.
16
16
 
17
+ For another solution to this problem, Google uses [S2 Geometry](http://blog.christianperone.com/2015/08/googles-s2-geometry-on-the-sphere-cells-and-hilbert-curve/) which is a more specific implementation designed for geospatial indexes only.
18
+
17
19
  ## Installation
18
20
 
19
21
  Add this line to your application's Gemfile:
@@ -28,9 +28,11 @@ module Geospatial
28
28
 
29
29
  def initialize(points)
30
30
  @points = points
31
- @box = nil
31
+ @bounding_box = nil
32
32
  end
33
33
 
34
+ attr :points
35
+
34
36
  def to_s
35
37
  "#{self.class}#{@points.inspect}"
36
38
  end
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Geospatial
22
- VERSION = "1.2.0"
22
+ VERSION = "1.3.0"
23
23
  end
@@ -40,6 +40,10 @@ RSpec.shared_context "kaikoura region" do
40
40
  end
41
41
 
42
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 have 3 points" do
44
+ expect(subject.points.count).to be == 3
45
+ end
46
+
43
47
  it "should intersect point on edge" do
44
48
  is_expected.to be_include_point(Vector[0.0, 0.0])
45
49
  end
@@ -100,3 +104,43 @@ RSpec.describe Geospatial::Polygon do
100
104
  end.render_file "polygon.pdf"
101
105
  end
102
106
  end
107
+
108
+ RSpec.shared_context "visualize polygon" do
109
+ it "can generate visualisation" do
110
+ map = Geospatial::Map.for_earth(30)
111
+
112
+ coordinates = region_string.split(/\s+/).collect{|coordinate| Vector.elements(coordinate.split(',').collect(&:to_f).first(2))}
113
+ region = Geospatial::Polygon.new(coordinates)
114
+
115
+ Geospatial::Visualization.for_map(map) do |pdf, origin|
116
+ region.edges do |pa, pb|
117
+ pdf.line (origin + pa).to_a, (origin + pb).to_a
118
+ end
119
+
120
+ count = 0
121
+ map.traverse(region, depth: 12) do |child, prefix, order|
122
+ count += 1
123
+ size = child.size
124
+ top_left = (origin + child.min) + Vector[0, size[1]]
125
+ pdf.rectangle(top_left.to_a, *size.to_a)
126
+ # puts "#{top_left.to_a} #{size.to_a}"
127
+ end
128
+
129
+ # puts "count=#{count}"
130
+
131
+ pdf.fill_and_stroke
132
+ end.render_file "#{self.class.description}.pdf"
133
+ end
134
+ end
135
+
136
+ RSpec.describe "Christchurch Polygon" do
137
+ let(:region_string) {"172.5704862712994,-43.48596596137077,0 172.5201239708415,-43.53774028333099,0 172.5497172175809,-43.58329117215316,0 172.604929908906,-43.58160925926914,0 172.6545025267675,-43.56367542997712,0 172.6985236068587,-43.55310361706354,0 172.7121776930187,-43.52196479307798,0 172.696171928184,-43.48585061855334,0 172.6332017124032,-43.45926891264853,0 172.5704862712994,-43.48596596137077,0"}
138
+
139
+ include_context "visualize polygon"
140
+ end
141
+
142
+ RSpec.describe "Whanganui Polygon" do
143
+ let(:region_string) {"175.0556233581592,-39.89861688271326,0 175.0212702693783,-39.91563023046992,0 174.9982107080192,-39.94106068540562,0 175.0189791159102,-39.95883189352543,0 175.0380433179273,-39.9568297441058,0 175.0580033463029,-39.94526078572716,0 175.0686808831414,-39.92828589884596,0 175.0760889571864,-39.90493548576401,0 175.0556233581592,-39.89861688271326,0"}
144
+
145
+ include_context "visualize polygon"
146
+ 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.2.0
4
+ version: 1.3.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: 2017-01-12 00:00:00.000000000 Z
11
+ date: 2017-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  version: '0'
120
120
  requirements: []
121
121
  rubyforge_project:
122
- rubygems_version: 2.5.2
122
+ rubygems_version: 2.6.10
123
123
  signing_key:
124
124
  specification_version: 4
125
125
  summary: Provides abstractions for dealing with geographical locations efficiently