rgeo-activerecord 4.0.1 → 4.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +6 -0
- data/lib/rgeo-activerecord.rb +8 -1
- data/lib/rgeo/active_record/arel_spatial_queries.rb +10 -10
- data/lib/rgeo/active_record/common_adapter_elements.rb +9 -9
- data/lib/rgeo/active_record/geometry_mixin.rb +5 -5
- data/lib/rgeo/active_record/spatial_expressions.rb +48 -48
- data/lib/rgeo/active_record/spatial_factory_store.rb +2 -2
- data/lib/rgeo/active_record/version.rb +1 -1
- metadata +2 -3
- data/lib/rgeo/active_record.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9351a4fcf488090206ad83a19229b92643bf910e
|
4
|
+
data.tar.gz: e51d6642a744aeafe7272fd6a4c6a74d58ef90c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2b967416e333ea7b00f482b077837cd6ff6938a4829dd226e63dfde2383d3ee65d41829465826da8e1c5efc6097dfa8954064cc7bdd263f5b441e11a8830148
|
7
|
+
data.tar.gz: 3e01c93cf12d161ca74c130d63faeb80a7d1912d24c4f39eb49f9e36f07ea4db9a4e3e71307bb7f4e314238a6608317859d56802f6a0531108c1ec89f5de813b
|
data/History.md
CHANGED
data/lib/rgeo-activerecord.rb
CHANGED
@@ -1 +1,8 @@
|
|
1
|
-
require "rgeo
|
1
|
+
require "rgeo"
|
2
|
+
require "active_record"
|
3
|
+
require "rgeo/active_record/version"
|
4
|
+
require "rgeo/active_record/spatial_expressions"
|
5
|
+
require "rgeo/active_record/spatial_factory_store"
|
6
|
+
require "rgeo/active_record/arel_spatial_queries"
|
7
|
+
require "rgeo/active_record/common_adapter_elements"
|
8
|
+
require "rgeo/active_record/geometry_mixin"
|
@@ -40,11 +40,11 @@ module RGeo
|
|
40
40
|
# an RGeo feature, or a spatial attribute.
|
41
41
|
def visit_in_spatial_context(node, collector)
|
42
42
|
case node
|
43
|
-
when
|
43
|
+
when String
|
44
44
|
collector << "#{st_func('ST_WKTToSQL')}(#{quote(node)})"
|
45
|
-
when
|
45
|
+
when RGeo::Feature::Instance
|
46
46
|
collector << visit_RGeo_Feature_Instance(node, collector)
|
47
|
-
when
|
47
|
+
when RGeo::Cartesian::BoundingBox
|
48
48
|
collector << visit_RGeo_Cartesian_BoundingBox(node, collector)
|
49
49
|
else
|
50
50
|
visit(node, collector)
|
@@ -54,7 +54,7 @@ module RGeo
|
|
54
54
|
|
55
55
|
# This node wraps an RGeo feature and gives it spatial expression constructors.
|
56
56
|
class SpatialConstantNode
|
57
|
-
include
|
57
|
+
include RGeo::ActiveRecord::SpatialExpressions
|
58
58
|
|
59
59
|
# The delegate should be the RGeo feature.
|
60
60
|
def initialize(delegate)
|
@@ -69,7 +69,7 @@ module RGeo
|
|
69
69
|
|
70
70
|
# Make sure the standard Arel visitors can handle RGeo feature objects by default.
|
71
71
|
|
72
|
-
|
72
|
+
Arel::Visitors::Visitor.class_eval do
|
73
73
|
def visit_RGeo_ActiveRecord_SpatialConstantNode(node, collector)
|
74
74
|
if respond_to?(:visit_in_spatial_context)
|
75
75
|
visit_in_spatial_context(node.delegate, collector)
|
@@ -79,17 +79,17 @@ module RGeo
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
|
82
|
+
Arel::Visitors::Dot.class_eval do
|
83
83
|
alias :visit_RGeo_Feature_Instance :visit_String
|
84
84
|
alias :visit_RGeo_Cartesian_BoundingBox :visit_String
|
85
85
|
end
|
86
86
|
|
87
|
-
|
87
|
+
Arel::Visitors::DepthFirst.class_eval do
|
88
88
|
alias :visit_RGeo_Feature_Instance :terminal
|
89
89
|
alias :visit_RGeo_Cartesian_BoundingBox :terminal
|
90
90
|
end
|
91
91
|
|
92
|
-
|
92
|
+
Arel::Visitors::ToSql.class_eval do
|
93
93
|
alias :visit_RGeo_Feature_Instance :visit_String
|
94
94
|
alias :visit_RGeo_Cartesian_BoundingBox :visit_String
|
95
95
|
end
|
@@ -98,8 +98,8 @@ module RGeo
|
|
98
98
|
# the arguments and return values, so that it can provide context to
|
99
99
|
# visitors that want to interpret syntax differently when dealing with
|
100
100
|
# spatial elements.
|
101
|
-
class SpatialNamedFunction <
|
102
|
-
include
|
101
|
+
class SpatialNamedFunction < Arel::Nodes::NamedFunction
|
102
|
+
include SpatialExpressions
|
103
103
|
|
104
104
|
def initialize(name, expr, spatial_flags = [], aliaz = nil)
|
105
105
|
super(name, expr, aliaz)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# autoload AbstractAdapter
|
2
|
-
|
2
|
+
ActiveRecord::ConnectionAdapters::AbstractAdapter
|
3
3
|
|
4
4
|
module RGeo
|
5
5
|
module ActiveRecord
|
@@ -25,14 +25,14 @@ module RGeo
|
|
25
25
|
|
26
26
|
def self.geometric_type_from_name(name)
|
27
27
|
case name.to_s
|
28
|
-
when /^geometry/i then
|
29
|
-
when /^point/i then
|
30
|
-
when /^linestring/i then
|
31
|
-
when /^polygon/i then
|
32
|
-
when /^geometrycollection/i then
|
33
|
-
when /^multipoint/i then
|
34
|
-
when /^multilinestring/i then
|
35
|
-
when /^multipolygon/i then
|
28
|
+
when /^geometry/i then Feature::Geometry
|
29
|
+
when /^point/i then Feature::Point
|
30
|
+
when /^linestring/i then Feature::LineString
|
31
|
+
when /^polygon/i then Feature::Polygon
|
32
|
+
when /^geometrycollection/i then Feature::GeometryCollection
|
33
|
+
when /^multipoint/i then Feature::MultiPoint
|
34
|
+
when /^multilinestring/i then Feature::MultiLineString
|
35
|
+
when /^multipolygon/i then Feature::MultiPolygon
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -6,7 +6,7 @@ module RGeo
|
|
6
6
|
|
7
7
|
module GeometryMixin
|
8
8
|
# The default JSON generator Proc. Renders geometry fields as WKT.
|
9
|
-
DEFAULT_JSON_GENERATOR =
|
9
|
+
DEFAULT_JSON_GENERATOR = Proc.new(&:to_s)
|
10
10
|
|
11
11
|
@json_generator = DEFAULT_JSON_GENERATOR
|
12
12
|
|
@@ -27,9 +27,9 @@ module RGeo
|
|
27
27
|
value = block
|
28
28
|
elsif value == :geojson
|
29
29
|
require "rgeo/geo_json"
|
30
|
-
value =
|
30
|
+
value = proc { |geom| GeoJSON.encode(geom) }
|
31
31
|
end
|
32
|
-
if value.is_a?(
|
32
|
+
if value.is_a?(Proc)
|
33
33
|
@json_generator = value
|
34
34
|
else
|
35
35
|
@json_generator = DEFAULT_JSON_GENERATOR
|
@@ -54,5 +54,5 @@ module RGeo
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
|
58
|
-
.add(
|
57
|
+
RGeo::Feature::MixinCollection::GLOBAL.for_type(RGeo::Feature::Geometry)
|
58
|
+
.add(RGeo::ActiveRecord::GeometryMixin)
|
@@ -3,7 +3,7 @@ module RGeo
|
|
3
3
|
# Returns true if spatial expressions (i.e. the methods in the
|
4
4
|
# SpatialExpressions module) are supported.
|
5
5
|
def self.spatial_expressions_supported?
|
6
|
-
defined?(
|
6
|
+
defined?(Arel::Nodes::NamedFunction)
|
7
7
|
end
|
8
8
|
|
9
9
|
# A set of spatial expression builders.
|
@@ -16,7 +16,7 @@ module RGeo
|
|
16
16
|
|
17
17
|
def st_function(function, *args)
|
18
18
|
spatial_info = args.last.is_a?(::Array) ? args.pop : []
|
19
|
-
|
19
|
+
SpatialNamedFunction.new(function, [self] + args, spatial_info)
|
20
20
|
end
|
21
21
|
|
22
22
|
#--
|
@@ -24,109 +24,109 @@ module RGeo
|
|
24
24
|
#++
|
25
25
|
|
26
26
|
def st_dimension
|
27
|
-
|
27
|
+
SpatialNamedFunction.new("ST_Dimension", [self], [false, true])
|
28
28
|
end
|
29
29
|
|
30
30
|
def st_geometrytype
|
31
|
-
|
31
|
+
SpatialNamedFunction.new("ST_GeometryType", [self], [false, true])
|
32
32
|
end
|
33
33
|
|
34
34
|
def st_astext
|
35
|
-
|
35
|
+
SpatialNamedFunction.new("ST_AsText", [self], [false, true])
|
36
36
|
end
|
37
37
|
|
38
38
|
def st_asbinary
|
39
|
-
|
39
|
+
SpatialNamedFunction.new("ST_AsBinary", [self], [false, true])
|
40
40
|
end
|
41
41
|
|
42
42
|
def st_srid
|
43
|
-
|
43
|
+
SpatialNamedFunction.new("ST_SRID", [self], [false, true])
|
44
44
|
end
|
45
45
|
|
46
46
|
def st_isempty
|
47
|
-
|
47
|
+
SpatialNamedFunction.new("ST_IsEmpty", [self], [false, true])
|
48
48
|
end
|
49
49
|
|
50
50
|
def st_issimple
|
51
|
-
|
51
|
+
SpatialNamedFunction.new("ST_IsSimple", [self], [false, true])
|
52
52
|
end
|
53
53
|
|
54
54
|
def st_boundary
|
55
|
-
|
55
|
+
SpatialNamedFunction.new("ST_Boundary", [self], [true, true])
|
56
56
|
end
|
57
57
|
|
58
58
|
def st_envelope
|
59
|
-
|
59
|
+
SpatialNamedFunction.new("ST_Envelope", [self], [true, true])
|
60
60
|
end
|
61
61
|
|
62
62
|
def st_equals(rhs)
|
63
|
-
|
63
|
+
SpatialNamedFunction.new("ST_Equals", [self, rhs], [false, true, true])
|
64
64
|
end
|
65
65
|
|
66
66
|
def st_disjoint(rhs)
|
67
|
-
|
67
|
+
SpatialNamedFunction.new("ST_Disjoint", [self, rhs], [false, true, true])
|
68
68
|
end
|
69
69
|
|
70
70
|
def st_intersects(rhs)
|
71
|
-
|
71
|
+
SpatialNamedFunction.new("ST_Intersects", [self, rhs], [false, true, true])
|
72
72
|
end
|
73
73
|
|
74
74
|
def st_touches(rhs)
|
75
|
-
|
75
|
+
SpatialNamedFunction.new("ST_Touches", [self, rhs], [false, true, true])
|
76
76
|
end
|
77
77
|
|
78
78
|
def st_crosses(rhs)
|
79
|
-
|
79
|
+
SpatialNamedFunction.new("ST_Crosses", [self, rhs], [false, true, true])
|
80
80
|
end
|
81
81
|
|
82
82
|
def st_within(rhs)
|
83
|
-
|
83
|
+
SpatialNamedFunction.new("ST_Within", [self, rhs], [false, true, true])
|
84
84
|
end
|
85
85
|
|
86
86
|
def st_contains(rhs)
|
87
|
-
|
87
|
+
SpatialNamedFunction.new("ST_Contains", [self, rhs], [false, true, true])
|
88
88
|
end
|
89
89
|
|
90
90
|
def st_overlaps(rhs)
|
91
|
-
|
91
|
+
SpatialNamedFunction.new("ST_Overlaps", [self, rhs], [false, true, true])
|
92
92
|
end
|
93
93
|
|
94
94
|
def st_relate(rhs, matrix = nil)
|
95
95
|
args = [self, rhs]
|
96
96
|
args << matrix.to_s if matrix
|
97
|
-
|
97
|
+
SpatialNamedFunction.new("ST_Relate", args, [false, true, true, false])
|
98
98
|
end
|
99
99
|
|
100
100
|
def st_distance(rhs, units = nil)
|
101
101
|
args = [self, rhs]
|
102
102
|
args << units.to_s if units
|
103
|
-
|
103
|
+
SpatialNamedFunction.new("ST_Distance", args, [false, true, true, false])
|
104
104
|
end
|
105
105
|
|
106
106
|
def st_intersection(rhs)
|
107
|
-
|
107
|
+
SpatialNamedFunction.new("ST_Intersection", [self, rhs], [true, true, true])
|
108
108
|
end
|
109
109
|
|
110
110
|
def st_difference(rhs)
|
111
|
-
|
111
|
+
SpatialNamedFunction.new("ST_Difference", [self, rhs], [true, true, true])
|
112
112
|
end
|
113
113
|
|
114
114
|
def st_union(rhs)
|
115
|
-
|
115
|
+
SpatialNamedFunction.new("ST_Union", [self, rhs], [true, true, true])
|
116
116
|
end
|
117
117
|
|
118
118
|
def st_symdifference(rhs)
|
119
|
-
|
119
|
+
SpatialNamedFunction.new("ST_SymDifference", [self, rhs], [true, true, true])
|
120
120
|
end
|
121
121
|
|
122
122
|
def st_buffer(distance, units = nil)
|
123
123
|
args = [self, distance.to_f]
|
124
124
|
args << units.to_s if units
|
125
|
-
|
125
|
+
SpatialNamedFunction.new("ST_Buffer", args, [true, true, false])
|
126
126
|
end
|
127
127
|
|
128
128
|
def st_convexhull
|
129
|
-
|
129
|
+
SpatialNamedFunction.new("ST_ConvexHull", [self], [true, true])
|
130
130
|
end
|
131
131
|
|
132
132
|
#--
|
@@ -134,19 +134,19 @@ module RGeo
|
|
134
134
|
#++
|
135
135
|
|
136
136
|
def st_x
|
137
|
-
|
137
|
+
SpatialNamedFunction.new("ST_X", [self], [false, true])
|
138
138
|
end
|
139
139
|
|
140
140
|
def st_y
|
141
|
-
|
141
|
+
SpatialNamedFunction.new("ST_Y", [self], [false, true])
|
142
142
|
end
|
143
143
|
|
144
144
|
def st_z
|
145
|
-
|
145
|
+
SpatialNamedFunction.new("ST_Z", [self], [false, true])
|
146
146
|
end
|
147
147
|
|
148
148
|
def st_m
|
149
|
-
|
149
|
+
SpatialNamedFunction.new("ST_M", [self], [false, true])
|
150
150
|
end
|
151
151
|
|
152
152
|
#--
|
@@ -154,25 +154,25 @@ module RGeo
|
|
154
154
|
#++
|
155
155
|
|
156
156
|
def st_startpoint
|
157
|
-
|
157
|
+
SpatialNamedFunction.new("ST_StartPoint", [self], [true, true])
|
158
158
|
end
|
159
159
|
|
160
160
|
def st_endpoint
|
161
|
-
|
161
|
+
SpatialNamedFunction.new("ST_EndPoint", [self], [true, true])
|
162
162
|
end
|
163
163
|
|
164
164
|
def st_isclosed
|
165
|
-
|
165
|
+
SpatialNamedFunction.new("ST_IsClosed", [self], [false, true])
|
166
166
|
end
|
167
167
|
|
168
168
|
def st_isring
|
169
|
-
|
169
|
+
SpatialNamedFunction.new("ST_IsRing", [self], [false, true])
|
170
170
|
end
|
171
171
|
|
172
172
|
def st_length(units = nil)
|
173
173
|
args = [self]
|
174
174
|
args << units.to_s if units
|
175
|
-
|
175
|
+
SpatialNamedFunction.new("ST_Length", args, [false, true, false])
|
176
176
|
end
|
177
177
|
|
178
178
|
#--
|
@@ -180,11 +180,11 @@ module RGeo
|
|
180
180
|
#++
|
181
181
|
|
182
182
|
def st_numpoints
|
183
|
-
|
183
|
+
SpatialNamedFunction.new("ST_NumPoints", [self], [false, true])
|
184
184
|
end
|
185
185
|
|
186
186
|
def st_pointn(n)
|
187
|
-
|
187
|
+
SpatialNamedFunction.new("ST_PointN", [self, n.to_i], [true, true, false])
|
188
188
|
end
|
189
189
|
|
190
190
|
#--
|
@@ -194,15 +194,15 @@ module RGeo
|
|
194
194
|
def st_area(units = nil)
|
195
195
|
args = [self]
|
196
196
|
args << units.to_s if units
|
197
|
-
|
197
|
+
SpatialNamedFunction.new("ST_StartPoint", args, [false, true, false])
|
198
198
|
end
|
199
199
|
|
200
200
|
def st_centroid
|
201
|
-
|
201
|
+
SpatialNamedFunction.new("ST_Centroid", [self], [true, true])
|
202
202
|
end
|
203
203
|
|
204
204
|
def st_pointonsurface
|
205
|
-
|
205
|
+
SpatialNamedFunction.new("ST_PointOnSurface", [self], [true, true])
|
206
206
|
end
|
207
207
|
|
208
208
|
#--
|
@@ -210,17 +210,17 @@ module RGeo
|
|
210
210
|
#++
|
211
211
|
|
212
212
|
def st_exteriorring
|
213
|
-
|
213
|
+
SpatialNamedFunction.new("ST_ExteriorRing", [self], [true, true])
|
214
214
|
end
|
215
215
|
|
216
216
|
def st_numinteriorrings
|
217
217
|
# Note: the name difference is intentional. The standard
|
218
218
|
# names this function incorrectly.
|
219
|
-
|
219
|
+
SpatialNamedFunction.new("ST_NumInteriorRing", [self], [false, true])
|
220
220
|
end
|
221
221
|
|
222
222
|
def st_interiorringn(n)
|
223
|
-
|
223
|
+
SpatialNamedFunction.new("ST_InteriorRingN", [self, n.to_i], [true, true, false])
|
224
224
|
end
|
225
225
|
|
226
226
|
#--
|
@@ -228,11 +228,11 @@ module RGeo
|
|
228
228
|
#++
|
229
229
|
|
230
230
|
def st_numgeometries
|
231
|
-
|
231
|
+
SpatialNamedFunction.new("ST_NumGeometries", [self], [false, true])
|
232
232
|
end
|
233
233
|
|
234
234
|
def st_geometryn(n)
|
235
|
-
|
235
|
+
SpatialNamedFunction.new("ST_GeometryN", [self, n.to_i], [true, true, false])
|
236
236
|
end
|
237
237
|
end
|
238
238
|
end
|
@@ -241,7 +241,7 @@ end
|
|
241
241
|
# Add tools to build spatial structures in the AST.
|
242
242
|
|
243
243
|
# Allow chaining of spatial expressions from attributes
|
244
|
-
|
244
|
+
Arel::Attribute.send :include, RGeo::ActiveRecord::SpatialExpressions
|
245
245
|
|
246
246
|
module Arel
|
247
247
|
# Create a spatial constant node.
|
@@ -249,6 +249,6 @@ module Arel
|
|
249
249
|
# string in WKT format). It supports chaining with the functions
|
250
250
|
# defined by RGeo::ActiveRecord::SpatialExpressions.
|
251
251
|
def self.spatial(arg)
|
252
|
-
|
252
|
+
RGeo::ActiveRecord::SpatialConstantNode.new(arg)
|
253
253
|
end
|
254
254
|
end
|
@@ -33,9 +33,9 @@ module RGeo
|
|
33
33
|
|
34
34
|
def default_for_attrs(attrs)
|
35
35
|
if attrs[:sql_type] =~ /geography/
|
36
|
-
|
36
|
+
Geographic.spherical_factory(to_factory_attrs(attrs))
|
37
37
|
else
|
38
|
-
|
38
|
+
Cartesian.preferred_factory(to_factory_attrs(attrs))
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rgeo-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Azuma, Tee Parham
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rgeo
|
@@ -92,7 +92,6 @@ files:
|
|
92
92
|
- LICENSE.txt
|
93
93
|
- README.md
|
94
94
|
- lib/rgeo-activerecord.rb
|
95
|
-
- lib/rgeo/active_record.rb
|
96
95
|
- lib/rgeo/active_record/arel_spatial_queries.rb
|
97
96
|
- lib/rgeo/active_record/common_adapter_elements.rb
|
98
97
|
- lib/rgeo/active_record/geometry_mixin.rb
|
data/lib/rgeo/active_record.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# RGeo is a spatial data library for Ruby, provided by the "rgeo" gem.
|
2
|
-
#
|
3
|
-
# The optional RGeo::ActiveRecord module provides spatial extensions for
|
4
|
-
# ActiveRecord, and a set of tools and helpers for writing RGeo-based
|
5
|
-
# spatial connection adapters.
|
6
|
-
|
7
|
-
require "rgeo"
|
8
|
-
require "active_record"
|
9
|
-
require "rgeo/active_record/version"
|
10
|
-
require "rgeo/active_record/spatial_expressions"
|
11
|
-
require "rgeo/active_record/spatial_factory_store"
|
12
|
-
require "rgeo/active_record/arel_spatial_queries"
|
13
|
-
require "rgeo/active_record/common_adapter_elements"
|
14
|
-
require "rgeo/active_record/geometry_mixin"
|