rclusters 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -10
- data/lib/rclusters.rb +1 -1
- data/lib/rclusters/screen_distance.rb +19 -0
- data/lib/rclusters/version.rb +1 -1
- data/rclusters.gemspec +1 -0
- metadata +16 -2
- data/lib/rclusters/pixel_distance.rb +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fa133b5d8a4fdd1dbbdad1260f858c7804fa8dd
|
4
|
+
data.tar.gz: d31afcd9af0e01bc4c103b9b4de654ebe97c22e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c515d4561ce56e4eff6874751b11ae2a47a813840bade276f8506aed8f8f7df3e5c5c5c33793b732297c934c296729748a9b655b222c9fbaccc445df61863ff0
|
7
|
+
data.tar.gz: db559fef721f115822e0d618ce445791432a991ff1f533562b4fb77539e09d23245b4e9f5675d4e3c56a1125e265260901a916346bf1a99149c69daa2d8f609c
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
#
|
1
|
+
# RClusters
|
2
2
|
|
3
|
-
RClusters is a Ruby gem that creates clusters from a points hash using either pixel or surface distance calculations.
|
3
|
+
RClusters is a Ruby gem that creates clusters from a geographic points hash using either pixel or surface distance calculations.
|
4
4
|
The input is a hash and the output is another hash. Right now, **a max_distance value has to be provided**.
|
5
5
|
|
6
|
-
|
6
|
+
Based on [this post](http://www.appelsiini.net/2008/introduction-to-marker-clustering-with-google-maps).
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
@@ -29,9 +29,10 @@ require 'rclusters'
|
|
29
29
|
|
30
30
|
opts = {}
|
31
31
|
|
32
|
-
rcluster = RClusters::
|
32
|
+
rcluster = RClusters::ScreenDistance.new(opts)
|
33
33
|
|
34
|
-
data = [{:lat=>-23.607581, :lon=>-46.630046,...},
|
34
|
+
data = [{:lat=>-23.607581, :lon=>-46.630046,...},
|
35
|
+
{:lat=>-23.511634, :lon=>-46.71541,...},...]
|
35
36
|
|
36
37
|
clusters = rcluster.calculate(data,2000) # 2000px as max_distance
|
37
38
|
```
|
@@ -44,7 +45,8 @@ opts = {}
|
|
44
45
|
|
45
46
|
rcluster = RClusters::SurfaceDistance.new(opts)
|
46
47
|
|
47
|
-
data = [{:lat=>-23.607581, :lon=>-46.630046,...},
|
48
|
+
data = [{:lat=>-23.607581, :lon=>-46.630046,...},
|
49
|
+
{:lat=>-23.511634, :lon=>-46.71541,...},...]
|
48
50
|
|
49
51
|
clusters = rcluster.calculate(data,200) # 200 mts as max_distance
|
50
52
|
```
|
@@ -84,15 +86,13 @@ Either in instantiation or in the `calculate` method.
|
|
84
86
|
| Option | Info | Values |
|
85
87
|
---------|-------|------
|
86
88
|
| `points`| Points to be clustered |Array of points [hashes]|
|
87
|
-
| `max_distance` | Maximum distance between points in order to cluster them | Integer. Unit `px` using de `
|
89
|
+
| `max_distance` | Maximum distance between points in order to cluster them | Integer. Unit `px` using de `ScreenDistance` class or the one matching `default_units` option if using `SurfaceDistance` |
|
88
90
|
|
89
|
-
####
|
91
|
+
#### ScreenDistance
|
90
92
|
|
91
93
|
| Option | Info | Values |
|
92
94
|
---------|-------|------
|
93
95
|
| `zoom` | Distance is processed by a Google Maps type zoom scale | Integer . Default: `12` |
|
94
|
-
| `offset` | Used for translation to projected coordinates | Default: `268435456`|
|
95
|
-
| `radius` | Earth radius | Default: `85445659.4471`|
|
96
96
|
|
97
97
|
#### SurfaceDistance
|
98
98
|
|
data/lib/rclusters.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'pixeldistance'
|
2
|
+
|
3
|
+
module RClusters
|
4
|
+
class ScreenDistance < Base
|
5
|
+
ZOOM = 12
|
6
|
+
|
7
|
+
def initialize(opts = {})
|
8
|
+
super
|
9
|
+
@zoom = opts[:zoom] || ZOOM
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def distance(lat1,lon1,lat2,lon2,opts={})
|
15
|
+
zoom = opts[:zoom] || @zoom
|
16
|
+
PixelDistance::from_coords(lat1,lon1,lat2,lon2,zoom)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/rclusters/version.rb
CHANGED
data/rclusters.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
22
|
spec.add_runtime_dependency "geokit", "~> 1.9"
|
23
|
+
spec.add_runtime_dependency "pixeldistance", "~> 0.2.1"
|
23
24
|
|
24
25
|
spec.add_development_dependency "bundler", "~> 1.9"
|
25
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rclusters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruno Salerno
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pixeldistance
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.2.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.2.1
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,7 +84,7 @@ files:
|
|
70
84
|
- bin/setup
|
71
85
|
- lib/rclusters.rb
|
72
86
|
- lib/rclusters/base.rb
|
73
|
-
- lib/rclusters/
|
87
|
+
- lib/rclusters/screen_distance.rb
|
74
88
|
- lib/rclusters/surface_distance.rb
|
75
89
|
- lib/rclusters/version.rb
|
76
90
|
- rclusters.gemspec
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module RClusters
|
2
|
-
class PixelDistance < Base
|
3
|
-
OFFSET = 268435456
|
4
|
-
RADIUS = 85445659.4471
|
5
|
-
ZOOM = 12
|
6
|
-
|
7
|
-
def initialize(opts = {})
|
8
|
-
super
|
9
|
-
@offset = opts[:offset] || OFFSET
|
10
|
-
@radius = opts[:radius] || RADIUS
|
11
|
-
@zoom = opts[:zoom] || ZOOM
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def distance(lat1,lon1,lat2,lon2,opts={})
|
17
|
-
zoom = opts[:zoom] || @zoom
|
18
|
-
|
19
|
-
x1 = lon_to_x(lon1)
|
20
|
-
y1 = lat_to_y(lat1)
|
21
|
-
x2 = lon_to_x(lon2)
|
22
|
-
y2 = lat_to_y(lat2)
|
23
|
-
|
24
|
-
Math.sqrt((x1-x2)**2 + (y1-y2)**2).to_i >> (21 - zoom)
|
25
|
-
end
|
26
|
-
|
27
|
-
def lon_to_x(lon)
|
28
|
-
(@offset + @radius * lon * Math::PI / 180).to_i
|
29
|
-
end
|
30
|
-
|
31
|
-
def lat_to_y(lat)
|
32
|
-
(@offset + @radius *
|
33
|
-
Math.log((1 + Math.sin(lat * Math::PI / 180)) /
|
34
|
-
(1 - Math.sin(lat * Math::PI / 180))) / 2)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|