rp_clustering-rgeo-activerecord 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjAzODU1ZmI0ZjZlMDdlODlmYjA0NTBiOGRmMjQyMDViZGNjZDAzMw==
4
+ MmJmOWM2NjZhMmMzODM1M2EyZDhkNjUyMzJjOGU1M2NlZTQ5N2IzOQ==
5
5
  data.tar.gz: !binary |-
6
- ZTk2ZTk4NTc4YjU3M2MxZjc5ZDdlMjdhNzk1NjBhMGJjM2I4MTRjMg==
6
+ NjZlZjdkMWNhNGYwOTdiMDU4YTdlNTIzODA2OGFmMDNhYjUyOTdkYg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YTQ0OGI2Y2I0NWEyMGVlN2FlZmQ0Mzc4ZDc0N2FhMjMwNGQwNjNjZDI5NzZl
10
- ZjNhNWNmNjc5YjY4ODJjMmZkZmYwOTYwN2EzNTU5NTU3YjRlNmQ2NmUwYjkw
11
- YTc3ZDc5NGVjNzAyMjM3MDEzNGRhNWM5ZGZjZDhiNDRmZTk5Mzc=
9
+ Y2I1NTBjYzEyMTZmN2FjYTlmMDhjZDFlNGMxYjM0NWQxOTQ0ODUxMTYxMjBl
10
+ YmI4MTgyNzAzYzhiMTYzZDFlYzAwZTgxNWQ2ZTJkN2RkNjg2NmYzN2M2ZWJh
11
+ ODIyYTE0OTM0NzFlMzJkNTZhM2MxODc0ODZiOTNkNWFlYTNiYWU=
12
12
  data.tar.gz: !binary |-
13
- OTcxZjBjYTViYjU2ZTdjMjIwZjdkNGRjN2NiODFjOWM4ZjRiNjIzOWIyMTc5
14
- YzE1ZWUwOTllZjUzNjcxYjg4YzA3MzU5ZDVkNWY0YjBlOGVhMmEzYzRiNWE3
15
- NTJiYTVmZGMzNjVhMTkxNGZkY2U4NzljMzYyNzc3Nzc5MThiMTA=
13
+ NWFlODJlYWQ1Mzg2MjRmNTVlYzM0NTk0YmI3ZTQwMmY3MTlhNjE4NGVlNzQx
14
+ YTZmZGJkMWFkOGVkM2Y5M2I4YzVlZDhhNDhiMjdhOGM4ZTEwNDdmNzUzYzEx
15
+ ZDI2NDgyNTFjZmNjZTc5MjMyNDFlNTI2NjIxZjAxZDBjOWY4YzE=
data/README.md CHANGED
@@ -5,6 +5,9 @@ A RGeo PostGIS extension to provide Active Record (Model) clustering functionali
5
5
  The intention is that this Gem will eventually provide abstracted methods for
6
6
  both "on the fly" clustering, as well as cached clustering (including associated generators).
7
7
 
8
+ This Gem is currently in early development, so expect changes. On this note, if you'd like a specific clustering
9
+ algorithm or feature added, please ask.
10
+
8
11
  If you find a problem with this Gem, please don't hesitate to raise an [issue](https://github.com/robertpyke/rp_clustering-rgeo-activerecord/issues).
9
12
 
10
13
  ## Installation
@@ -53,9 +56,9 @@ e.g.
53
56
 
54
57
  query = MyModel.select(
55
58
  arel_table.st_astext(
56
- arel_table.st_centroid(arel_table.st_collect(attr))
59
+ arel_table.st_centroid(arel_table.st_collect(arel_table[:latlon]))
57
60
  ).as("cluster_centroid")
58
- ).group(arel_table[:latlon].st_snaptogrid(0.1))
61
+ ).group(arel_table[:latlon].st_snaptogrid(grid_size))
59
62
 
60
63
  # Iterate over our clusters
61
64
  query.all.each do |cluster|
@@ -57,6 +57,29 @@ module RPClustering
57
57
 
58
58
  end
59
59
 
60
+ # ST_MinimumBoundingCircle: http://www.postgis.org/docs/ST_MinimumBoundingCircle.html
61
+ #
62
+ # Implements postgis function variant:
63
+ #
64
+ # geometry ST_MinimumBoundingCircle(geometry geomA, integer num_segs_per_qt_circ=48);
65
+ #
66
+ # Returns a geometry
67
+
68
+ def st_minimumboundingcircle(num_segs=nil)
69
+ args = [self]
70
+ if num_segs
71
+ args << num_segs.to_s
72
+
73
+ ::RGeo::ActiveRecord::SpatialNamedFunction.new(
74
+ 'ST_MinimumBoundingCircle', args, [true, true, false]
75
+ )
76
+ else
77
+ ::RGeo::ActiveRecord::SpatialNamedFunction.new(
78
+ 'ST_MinimumBoundingCircle', args, [true, true]
79
+ )
80
+ end
81
+ end
82
+
60
83
  end
61
84
 
62
85
  end
@@ -73,6 +73,29 @@ module RPClustering
73
73
  )
74
74
  end
75
75
 
76
+ # ST_MinimumBoundingCircle: http://www.postgis.org/docs/ST_MinimumBoundingCircle.html
77
+ #
78
+ # Implements postgis function variant:
79
+ #
80
+ # geometry ST_MinimumBoundingCircle(geometry geomA, integer num_segs_per_qt_circ=48);
81
+ #
82
+ # Returns a geometry
83
+
84
+ def st_minimumboundingcircle(g, num_segs=nil)
85
+ args = [g]
86
+ if num_segs
87
+ args << num_segs.to_s
88
+
89
+ ::RGeo::ActiveRecord::SpatialNamedFunction.new(
90
+ 'ST_MinimumBoundingCircle', args, [true, true, false]
91
+ )
92
+ else
93
+ ::RGeo::ActiveRecord::SpatialNamedFunction.new(
94
+ 'ST_MinimumBoundingCircle', args, [true, true]
95
+ )
96
+ end
97
+ end
98
+
76
99
  end
77
100
 
78
101
  end
@@ -1,7 +1,7 @@
1
1
  module RPClustering
2
2
  module RGeo
3
3
  module ActiveRecord
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
6
6
  end
7
7
  end
@@ -25,12 +25,14 @@ Gem::Specification.new do |gem|
25
25
  gem.add_development_dependency('rake')
26
26
  gem.add_development_dependency('rdoc')
27
27
  gem.add_development_dependency('pg')
28
+ gem.add_development_dependency('squeel', '~> 1.0.16')
28
29
 
29
30
  # Deployed Gem Dependencies
30
31
  gem.add_dependency('activerecord', '~> 3.0')
31
32
  gem.add_dependency('arel', '~> 3.0.2')
32
33
  gem.add_dependency('rgeo', '~> 0.3.20')
33
34
  gem.add_dependency('rgeo-activerecord', '~> 0.4.6')
35
+
34
36
  # This Gem is specific to postgis
35
- gem.add_dependency('activerecord-postgis-adapter')
37
+ gem.add_dependency('activerecord-postgis-adapter', '~> 0.5.1')
36
38
  end
@@ -1,6 +1,7 @@
1
1
  require 'test/unit'
2
2
  require 'rgeo/active_record/adapter_test_helper'
3
3
  require 'rp_clustering-rgeo-activerecord'
4
+ require 'squeel'
4
5
 
5
6
  module RPClustering
6
7
  module RGeo
@@ -99,6 +100,46 @@ module RPClustering
99
100
 
100
101
  end
101
102
 
103
+ # Confirm that the st_minimumboundingcircle function is producing the
104
+ # expected results
105
+
106
+ def test_st_minimumboundingcircle
107
+ arel_klass = populate_ar_class(:latlon_point)
108
+
109
+ points_generated = 0
110
+ (-5..5).each do |lng|
111
+ (-5..5).each do |lat|
112
+ obj = arel_klass.new
113
+ obj.latlon = @geographic_factory.point(lng, lat)
114
+ obj.save!
115
+ points_generated+=1
116
+ end
117
+ end
118
+
119
+ # Sanity check, confirm that we have all the points we created.
120
+ count_res = arel_klass.count()
121
+ assert_equal(
122
+ points_generated,
123
+ count_res,
124
+ "The number of points generated doesn't match the number in the DB"
125
+ )
126
+
127
+ attr = arel_klass.arel_table[:latlon]
128
+ t = arel_klass.arel_table
129
+
130
+ q1 = arel_klass.select(t.st_astext(t.st_minimumboundingcircle(attr.st_collect())).as("min_bound_circle"))
131
+
132
+ assert_equal(1, q1.all.count(), "We should get a single bounding circle covering all points")
133
+
134
+ value = q1.first["min_bound_circle"]
135
+ circle = @geographic_factory.parse_wkt(value)
136
+ assert(circle.is_a?(::RGeo::Feature::Polygon), "the min_bound_circle should be a polygon")
137
+
138
+ q2 = arel_klass.where{latlon.op('&&', circle)}
139
+ assert_equal(points_generated, q2.count(), "the min_bound_circle should contain all our generated poits")
140
+
141
+ end
142
+
102
143
  end
103
144
  end
104
145
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rp_clustering-rgeo-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Pyke
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ! '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: squeel
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 1.0.16
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 1.0.16
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: activerecord
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -140,16 +154,16 @@ dependencies:
140
154
  name: activerecord-postgis-adapter
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
- - - ! '>='
157
+ - - ~>
144
158
  - !ruby/object:Gem::Version
145
- version: '0'
159
+ version: 0.5.1
146
160
  type: :runtime
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
- - - ! '>='
164
+ - - ~>
151
165
  - !ruby/object:Gem::Version
152
- version: '0'
166
+ version: 0.5.1
153
167
  description: A RGeo PostGIS extension to provide Active Record (Model) clustering
154
168
  functionality
155
169
  email: