geos-extensions 0.0.6 → 0.0.7
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.
- data/Rakefile +1 -1
- data/geos-extensions.gemspec +2 -2
- data/lib/active_record_extensions/geospatial_scopes.rb +257 -76
- data/lib/geos_extensions.rb +9 -1
- data/test/geospatial_scopes_test.rb +174 -0
- data/test/writer_test.rb +14 -0
- metadata +4 -4
data/Rakefile
CHANGED
data/geos-extensions.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{geos-extensions}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["J Smith"]
|
12
|
-
s.date = %q{2011-03-
|
12
|
+
s.date = %q{2011-03-21}
|
13
13
|
s.description = %q{Extensions for the GEOS library.}
|
14
14
|
s.email = %q{code@zoocasa.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -23,10 +23,46 @@ module Geos
|
|
23
23
|
# * st_within
|
24
24
|
# * st_dwithin
|
25
25
|
#
|
26
|
-
# The first argument to each
|
26
|
+
# The first argument to each of these methods can be a Geos::Geometry-based
|
27
27
|
# object or anything readable by Geos.read along with an optional
|
28
28
|
# options Hash.
|
29
29
|
#
|
30
|
+
# For ordering, we have the following:
|
31
|
+
#
|
32
|
+
# The following scopes take no arguments:
|
33
|
+
#
|
34
|
+
# * order_by_ndims
|
35
|
+
# * order_by_npoints
|
36
|
+
# * order_by_nrings
|
37
|
+
# * order_by_numgeometries
|
38
|
+
# * order_by_numinteriorring
|
39
|
+
# * order_by_numinteriorrings
|
40
|
+
# * order_by_numpoints
|
41
|
+
# * order_by_length3d
|
42
|
+
# * order_by_length
|
43
|
+
# * order_by_length2d
|
44
|
+
# * order_by_perimeter
|
45
|
+
# * order_by_perimeter2d
|
46
|
+
# * order_by_perimeter3d
|
47
|
+
#
|
48
|
+
# These next scopes allow you to specify a geometry argument for
|
49
|
+
# measurement:
|
50
|
+
#
|
51
|
+
# * order_by_distance
|
52
|
+
# * order_by_distance_sphere
|
53
|
+
# * order_by_maxdistance
|
54
|
+
# * order_by_hausdorffdistance (additionally allows you to set the
|
55
|
+
# densify_frac argument)
|
56
|
+
# * order_by_distance_spheroid (requires an additional SPHEROID
|
57
|
+
# string to calculate against)
|
58
|
+
#
|
59
|
+
# These next scopes allow you to specify a SPHEROID string to calculate
|
60
|
+
# against:
|
61
|
+
#
|
62
|
+
# * order_by_length2d_spheroid
|
63
|
+
# * order_by_length3d_spheroid
|
64
|
+
# * order_by_length_spheroid
|
65
|
+
#
|
30
66
|
# == Options
|
31
67
|
#
|
32
68
|
# * :column - the column to compare against. The default is 'the_geom'.
|
@@ -35,6 +71,8 @@ module Geos
|
|
35
71
|
# * :wkb_options - in order to facilitate some conversions, geometries
|
36
72
|
# are converted to WKB. The default is `{:include_srid => true}` to
|
37
73
|
# force the geometry to use PostGIS's Extended WKB.
|
74
|
+
# * :desc - the order_by scopes have an additional :desc option to alllow
|
75
|
+
# for DESC ordering.
|
38
76
|
#
|
39
77
|
# == SRID Detection
|
40
78
|
#
|
@@ -71,108 +109,251 @@ module Geos
|
|
71
109
|
within
|
72
110
|
}.freeze
|
73
111
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
112
|
+
ZERO_ARGUMENT_MEASUREMENTS = %w{
|
113
|
+
ndims
|
114
|
+
npoints
|
115
|
+
nrings
|
116
|
+
numgeometries
|
117
|
+
numinteriorring
|
118
|
+
numinteriorrings
|
119
|
+
numpoints
|
120
|
+
length3d
|
121
|
+
length
|
122
|
+
length2d
|
123
|
+
perimeter
|
124
|
+
perimeter2d
|
125
|
+
perimeter3d
|
126
|
+
}
|
80
127
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
128
|
+
ONE_GEOMETRY_ARGUMENT_MEASUREMENTS = %w{
|
129
|
+
distance
|
130
|
+
distance_sphere
|
131
|
+
maxdistance
|
132
|
+
}
|
85
133
|
|
86
|
-
|
87
|
-
|
134
|
+
ONE_ARGUMENT_MEASUREMENTS = %w{
|
135
|
+
length2d_spheroid
|
136
|
+
length3d_spheroid
|
137
|
+
length_spheroid
|
138
|
+
}
|
88
139
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
140
|
+
def self.included(base)
|
141
|
+
base.class_eval do
|
142
|
+
class << self
|
143
|
+
protected
|
144
|
+
def set_srid_or_transform(column_srid, geom_srid, geos)
|
145
|
+
sql = if column_srid != geom_srid
|
146
|
+
if column_srid == -1 || geom_srid == -1
|
147
|
+
%{ST_SetSRID(?, #{column_srid})}
|
148
|
+
else
|
149
|
+
%{ST_Transform(?, #{column_srid})}
|
150
|
+
end
|
151
|
+
else
|
152
|
+
%{?}
|
153
|
+
end
|
154
|
+
|
155
|
+
sanitize_sql([ sql, geos.to_ewkb ])
|
93
156
|
end
|
94
157
|
|
95
|
-
|
158
|
+
def read_geos(geom, column_srid)
|
159
|
+
if geom.is_a?(String) && geom =~ /^SRID=default;/
|
160
|
+
geom = geom.sub(/default/, column_srid.to_s)
|
161
|
+
end
|
162
|
+
Geos.read(geom)
|
163
|
+
end
|
96
164
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
165
|
+
def read_geom_srid(geos)
|
166
|
+
if geos.srid == 0
|
167
|
+
-1
|
168
|
+
else
|
169
|
+
geos.srid
|
170
|
+
end
|
101
171
|
end
|
102
172
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
173
|
+
def default_options(options)
|
174
|
+
{
|
175
|
+
:column => 'the_geom',
|
176
|
+
:use_index => true
|
177
|
+
}.merge(options || {})
|
107
178
|
end
|
108
179
|
|
109
|
-
|
110
|
-
if
|
111
|
-
|
180
|
+
def function_name(function, use_index)
|
181
|
+
if use_index
|
182
|
+
"ST_#{function}"
|
112
183
|
else
|
113
|
-
|
184
|
+
"_ST_#{function}"
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
def build_function_call(function, geom = nil, options = {}, function_options = {})
|
189
|
+
options = default_options(options)
|
190
|
+
|
191
|
+
function_options = {
|
192
|
+
:additional_args => 0
|
193
|
+
}.merge(function_options)
|
194
|
+
|
195
|
+
''.tap do |ret|
|
196
|
+
column_name = self.connection.quote_table_name(options[:column])
|
197
|
+
ret << "#{function_name(function, options[:use_index])}(#{self.quoted_table_name}.#{column_name}"
|
198
|
+
|
199
|
+
if geom
|
200
|
+
column_srid = self.srid_for(options[:column])
|
201
|
+
|
202
|
+
geos = read_geos(geom, column_srid)
|
203
|
+
geom_srid = read_geom_srid(geos)
|
204
|
+
|
205
|
+
ret << %{, #{self.set_srid_or_transform(column_srid, geom_srid, geos)}}
|
206
|
+
end
|
207
|
+
|
208
|
+
ret << ', ?' * function_options[:additional_args]
|
209
|
+
ret << %{)#{options[:append]}}
|
114
210
|
end
|
115
|
-
else
|
116
|
-
%{\#{function}(\#{column_name}, ?)}
|
117
211
|
end
|
118
212
|
|
213
|
+
def additional_ordering(options = nil)
|
214
|
+
options ||= {}
|
215
|
+
|
216
|
+
''.tap do |ret|
|
217
|
+
if options[:desc]
|
218
|
+
ret << ' DESC'
|
219
|
+
end
|
220
|
+
|
221
|
+
if options[:nulls]
|
222
|
+
ret << " NULLS #{options[:nulls].to_s.upcase}"
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
def assert_arguments_length(args, min, max)
|
228
|
+
raise ArgumentError.new("wrong number of arguments (#{args.length} for #{min}-#{max})") unless
|
229
|
+
args.length.between?(min, max)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
RELATIONSHIPS.each do |relationship|
|
235
|
+
src, line = <<-EOF, __LINE__ + 1
|
236
|
+
#{SCOPE_METHOD} :st_#{relationship}, lambda { |*args|
|
237
|
+
assert_arguments_length(args, 1, 2)
|
238
|
+
|
119
239
|
{
|
120
|
-
:conditions =>
|
121
|
-
|
122
|
-
|
123
|
-
|
240
|
+
:conditions => build_function_call(
|
241
|
+
'#{relationship}',
|
242
|
+
*args
|
243
|
+
)
|
124
244
|
}
|
125
245
|
}
|
126
246
|
EOF
|
127
247
|
base.class_eval(src, __FILE__, line)
|
128
248
|
end
|
129
249
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
options = {
|
136
|
-
:column => 'the_geom',
|
137
|
-
:use_index => true
|
138
|
-
}.merge(args.extract_options!)
|
139
|
-
|
140
|
-
geom, distance = Geos.read(args.first), args[1]
|
141
|
-
|
142
|
-
column_name = ::ActiveRecord::Base.connection.quote_table_name(options[:column])
|
143
|
-
column_srid = self.srid_for(options[:column])
|
144
|
-
geom_srid = if geom.srid == 0
|
145
|
-
-1
|
146
|
-
else
|
147
|
-
geom.srid
|
148
|
-
end
|
149
|
-
|
150
|
-
function = if options[:use_index]
|
151
|
-
'ST_dwithin'
|
152
|
-
else
|
153
|
-
'_ST_dwithin'
|
154
|
-
end
|
155
|
-
|
156
|
-
conditions = if column_srid != geom_srid
|
157
|
-
if column_srid == -1 || geom_srid == -1
|
158
|
-
%{\#{function}(\#{column_name}, ST_SetSRID(?, \#{column_srid}), ?)}
|
159
|
-
else
|
160
|
-
%{\#{function}(\#{column_name}, ST_Transform(?, \#{column_srid}), ?)}
|
161
|
-
end
|
162
|
-
else
|
163
|
-
%{\#{function}(\#{column_name}, ?, ?)}
|
164
|
-
end
|
250
|
+
base.class_eval do
|
251
|
+
send(SCOPE_METHOD, :st_dwithin, lambda { |*args|
|
252
|
+
assert_arguments_length(args, 2, 3)
|
253
|
+
geom, distance, options = args
|
165
254
|
|
166
255
|
{
|
167
256
|
:conditions => [
|
168
|
-
|
169
|
-
geom.to_ewkb,
|
257
|
+
build_function_call('dwithin', geom, options, :additional_args => 1),
|
170
258
|
distance
|
171
259
|
]
|
172
260
|
}
|
173
|
-
}
|
174
|
-
|
175
|
-
|
261
|
+
})
|
262
|
+
end
|
263
|
+
|
264
|
+
ZERO_ARGUMENT_MEASUREMENTS.each do |measurement|
|
265
|
+
src, line = <<-EOF, __LINE__ + 1
|
266
|
+
#{SCOPE_METHOD} :order_by_#{measurement}, lambda { |*args|
|
267
|
+
assert_arguments_length(args, 0, 1)
|
268
|
+
options = args[0]
|
269
|
+
|
270
|
+
function_call = build_function_call('#{measurement}', nil, options)
|
271
|
+
function_call << additional_ordering(options)
|
272
|
+
|
273
|
+
{
|
274
|
+
:order => function_call
|
275
|
+
}
|
276
|
+
}
|
277
|
+
EOF
|
278
|
+
base.class_eval(src, __FILE__, line)
|
279
|
+
end
|
280
|
+
|
281
|
+
ONE_GEOMETRY_ARGUMENT_MEASUREMENTS.each do |measurement|
|
282
|
+
src, line = <<-EOF, __LINE__ + 1
|
283
|
+
#{SCOPE_METHOD} :order_by_#{measurement}, lambda { |*args|
|
284
|
+
assert_arguments_length(args, 1, 2)
|
285
|
+
geom, options = args
|
286
|
+
|
287
|
+
function_call = build_function_call('#{measurement}', geom, options)
|
288
|
+
function_call << additional_ordering(options)
|
289
|
+
|
290
|
+
{
|
291
|
+
:order => function_call
|
292
|
+
}
|
293
|
+
}
|
294
|
+
EOF
|
295
|
+
base.class_eval(src, __FILE__, line)
|
296
|
+
end
|
297
|
+
|
298
|
+
ONE_ARGUMENT_MEASUREMENTS.each do |measurement|
|
299
|
+
src, line = <<-EOF, __LINE__ + 1
|
300
|
+
#{SCOPE_METHOD} :order_by_#{measurement}, lambda { |*args|
|
301
|
+
assert_arguments_length(args, 1, 2)
|
302
|
+
argument, options = args
|
303
|
+
|
304
|
+
function_call = build_function_call('#{measurement}', nil, options, :additional_args => 1)
|
305
|
+
function_call << additional_ordering(options)
|
306
|
+
|
307
|
+
{
|
308
|
+
:order => sanitize_sql([ function_call, argument ])
|
309
|
+
}
|
310
|
+
}
|
311
|
+
EOF
|
312
|
+
base.class_eval(src, __FILE__, line)
|
313
|
+
end
|
314
|
+
|
315
|
+
base.class_eval do
|
316
|
+
send(SCOPE_METHOD, :order_by_hausdorffdistance, lambda { |*args|
|
317
|
+
assert_arguments_length(args, 1, 3)
|
318
|
+
options = args.extract_options!
|
319
|
+
geom, densify_frac = args
|
320
|
+
|
321
|
+
function_call = build_function_call(
|
322
|
+
'hausdorffdistance',
|
323
|
+
geom,
|
324
|
+
options,
|
325
|
+
:additional_args => (densify_frac.present? ? 1 : 0)
|
326
|
+
)
|
327
|
+
function_call << additional_ordering(options)
|
328
|
+
|
329
|
+
{
|
330
|
+
:order => sanitize_sql([
|
331
|
+
function_call,
|
332
|
+
densify_frac
|
333
|
+
])
|
334
|
+
}
|
335
|
+
})
|
336
|
+
|
337
|
+
send(SCOPE_METHOD, :order_by_distance_spheroid, lambda { |*args|
|
338
|
+
assert_arguments_length(args, 2, 3)
|
339
|
+
geom, spheroid, options = args
|
340
|
+
|
341
|
+
function_call = build_function_call(
|
342
|
+
'distance_spheroid',
|
343
|
+
geom,
|
344
|
+
options,
|
345
|
+
:additional_args => 1
|
346
|
+
)
|
347
|
+
function_call << additional_ordering(options)
|
348
|
+
|
349
|
+
{
|
350
|
+
:order => sanitize_sql([
|
351
|
+
function_call,
|
352
|
+
spheroid
|
353
|
+
])
|
354
|
+
}
|
355
|
+
})
|
356
|
+
end
|
176
357
|
end
|
177
358
|
end
|
178
359
|
end
|
data/lib/geos_extensions.rb
CHANGED
@@ -196,9 +196,17 @@ module Geos
|
|
196
196
|
# option to create a PostGIS-style EWKT output.
|
197
197
|
def to_wkt(options = {})
|
198
198
|
writer = WktWriter.new
|
199
|
+
|
200
|
+
# Older versions of the Geos library don't allow for options here.
|
201
|
+
args = if WktWriter.instance_method(:write).arity < -1
|
202
|
+
[ options ]
|
203
|
+
else
|
204
|
+
[]
|
205
|
+
end
|
206
|
+
|
199
207
|
ret = ''
|
200
208
|
ret << "SRID=#{self.srid};" if options[:include_srid]
|
201
|
-
ret << writer.write(self,
|
209
|
+
ret << writer.write(self, *args)
|
202
210
|
ret
|
203
211
|
end
|
204
212
|
|
@@ -84,5 +84,179 @@ if ENV['TEST_ACTIVERECORD']
|
|
84
84
|
assert_equal([1, 2, 3], Foo.st_disjoint('SRID=4269; POINT(100 100)', :column => :the_other_geom).all.collect(&:id).sort)
|
85
85
|
assert_equal([3], Foo.st_contains('SRID=4269; POINT(7 7)', :column => :the_other_geom).all.collect(&:id).sort)
|
86
86
|
end
|
87
|
+
|
88
|
+
def test_order_by_distance
|
89
|
+
assert_equal([3, 1, 2], Foo.order_by_distance('POINT(1 1)').all.collect(&:id))
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_order_by_distance_desc
|
93
|
+
assert_equal([2, 1, 3], Foo.order_by_distance('POINT(1 1)', :desc => true).all.collect(&:id))
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_order_by_distance_sphere
|
97
|
+
assert_equal([3, 1, 2], Foo.order_by_distance_sphere('POINT(1 1)').all.collect(&:id))
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_order_by_distance_sphere_desc
|
101
|
+
assert_equal([2, 1, 3], Foo.order_by_distance_sphere('POINT(1 1)', :desc => true).all.collect(&:id))
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_order_by_maxdistance
|
105
|
+
assert_equal([1, 3, 2], Foo.order_by_maxdistance('POINT(1 1)').all.collect(&:id))
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_order_by_maxdistance_desc
|
109
|
+
assert_equal([2, 3, 1], Foo.order_by_maxdistance('POINT(1 1)', :desc => true).all.collect(&:id))
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_order_by_ndims
|
113
|
+
assert_equal([1, 2, 3], Foo.order_by_ndims.order('id').all.collect(&:id))
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_order_by_ndims_desc
|
117
|
+
assert_equal([1, 2, 3], Foo.order_by_ndims(:desc => true).order('id').all.collect(&:id))
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_order_by_npoints
|
121
|
+
assert_equal([1, 2, 3], Foo.order_by_npoints.order('id').all.collect(&:id))
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_order_by_npoints_desc
|
125
|
+
assert_equal([3, 1, 2], Foo.order_by_npoints(:desc => true).order('id').all.collect(&:id))
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_order_by_nrings
|
129
|
+
assert_equal([1, 2, 3], Foo.order_by_nrings.order('id').all.collect(&:id))
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_order_by_nrings_desc
|
133
|
+
assert_equal([3, 1, 2], Foo.order_by_nrings(:desc => true).order('id').all.collect(&:id))
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_order_by_numgeometries
|
137
|
+
assert_equal([1, 2, 3], Foo.order_by_numgeometries.order('id').all.collect(&:id))
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_order_by_numgeometries_desc
|
141
|
+
assert_equal([1, 2, 3], Foo.order_by_numgeometries(:desc => true).order('id').all.collect(&:id))
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_order_by_numinteriorring
|
145
|
+
assert_equal([3, 1, 2], Foo.order_by_numinteriorring.order('id').all.collect(&:id))
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_order_by_numinteriorring_desc
|
149
|
+
assert_equal([1, 2, 3], Foo.order_by_numinteriorring(:desc => true).order('id').all.collect(&:id))
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_order_by_numinteriorrings
|
153
|
+
assert_equal([3, 1, 2], Foo.order_by_numinteriorrings.order('id').all.collect(&:id))
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_order_by_numinteriorrings_desc
|
157
|
+
assert_equal([1, 2, 3], Foo.order_by_numinteriorrings(:desc => true).order('id').all.collect(&:id))
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_order_by_numpoints
|
161
|
+
assert_equal([1, 2, 3], Foo.order_by_numpoints.order('id').all.collect(&:id))
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_order_by_numpoints_desc
|
165
|
+
assert_equal([1, 2, 3], Foo.order_by_numpoints(:desc => true).order('id').all.collect(&:id))
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_order_by_length3d
|
169
|
+
assert_equal([1, 2, 3], Foo.order_by_length3d.order('id').all.collect(&:id))
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_order_by_length3d_desc
|
173
|
+
assert_equal([1, 2, 3], Foo.order_by_length3d(:desc => true).order('id').all.collect(&:id))
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_order_by_length
|
177
|
+
assert_equal([1, 2, 3], Foo.order_by_length.order('id').all.collect(&:id))
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_order_by_length_desc
|
181
|
+
assert_equal([1, 2, 3], Foo.order_by_length(:desc => true).order('id').all.collect(&:id))
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_order_by_length2d
|
185
|
+
assert_equal([1, 2, 3], Foo.order_by_length2d.order('id').all.collect(&:id))
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_order_by_length2d_desc
|
189
|
+
assert_equal([1, 2, 3], Foo.order_by_length2d(:desc => true).order('id').all.collect(&:id))
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_order_by_length3d_spheroid
|
193
|
+
assert_equal([1, 2, 3], Foo.order_by_length3d_spheroid('SPHEROID["WGS 84", 6378137, 298.257223563]').order('id').all.collect(&:id))
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_order_by_length3d_spheroid_desc
|
197
|
+
assert_equal([1, 2, 3], Foo.order_by_length3d_spheroid('SPHEROID["WGS 84", 6378137, 298.257223563]', :desc => true).order('id').all.collect(&:id))
|
198
|
+
end
|
199
|
+
|
200
|
+
|
201
|
+
def test_order_by_length2d_spheroid
|
202
|
+
assert_equal([1, 2, 3], Foo.order_by_length3d_spheroid('SPHEROID["WGS 84", 6378137, 298.257223563]').order('id').all.collect(&:id))
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_order_by_length2d_spheroid_desc
|
206
|
+
assert_equal([1, 2, 3], Foo.order_by_length3d_spheroid('SPHEROID["WGS 84", 6378137, 298.257223563]', :desc => true).order('id').all.collect(&:id))
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_order_by_length_spheroid
|
210
|
+
assert_equal([1, 2, 3], Foo.order_by_length3d_spheroid('SPHEROID["WGS 84", 6378137, 298.257223563]').order('id').all.collect(&:id))
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_order_by_length_spheroid_desc
|
214
|
+
assert_equal([1, 2, 3], Foo.order_by_length3d_spheroid('SPHEROID["WGS 84", 6378137, 298.257223563]', :desc => true).order('id').all.collect(&:id))
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_order_by_perimeter
|
218
|
+
assert_equal([1, 2, 3], Foo.order_by_perimeter.order('id').all.collect(&:id))
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_order_by_perimeter_desc
|
222
|
+
assert_equal([3, 1, 2], Foo.order_by_perimeter(:desc => true).order('id').all.collect(&:id))
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_order_by_perimeter2d
|
226
|
+
assert_equal([1, 2, 3], Foo.order_by_perimeter2d.order('id').all.collect(&:id))
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_order_by_perimeter2d_desc
|
230
|
+
assert_equal([3, 1, 2], Foo.order_by_perimeter2d(:desc => true).order('id').all.collect(&:id))
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_order_by_perimeter3d
|
234
|
+
assert_equal([1, 2, 3], Foo.order_by_perimeter3d.order('id').all.collect(&:id))
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_order_by_perimeter3d_desc
|
238
|
+
assert_equal([3, 1, 2], Foo.order_by_perimeter3d(:desc => true).order('id').all.collect(&:id))
|
239
|
+
end
|
240
|
+
|
241
|
+
def test_order_by_hausdorffdistance
|
242
|
+
assert_equal([1, 3, 2], Foo.order_by_hausdorffdistance('POINT(1 1)').all.collect(&:id))
|
243
|
+
end
|
244
|
+
|
245
|
+
def test_order_by_hausdorffdistance_desc
|
246
|
+
assert_equal([2, 3, 1], Foo.order_by_hausdorffdistance('POINT(1 1)', :desc => true).all.collect(&:id))
|
247
|
+
end
|
248
|
+
|
249
|
+
def test_order_by_hausdorffdistance_with_densify_frac
|
250
|
+
assert_equal([1, 3, 2], Foo.order_by_hausdorffdistance('POINT(1 1)', 0.314).all.collect(&:id))
|
251
|
+
end
|
252
|
+
|
253
|
+
|
254
|
+
def test_order_by_distance_spheroid
|
255
|
+
assert_equal([2, 3, 1], Foo.order_by_distance_spheroid('POINT(10 10)', 'SPHEROID["WGS 84", 6378137, 298.257223563]').order('id').all.collect(&:id))
|
256
|
+
end
|
257
|
+
|
258
|
+
def test_order_by_distance_spheroid_desc
|
259
|
+
assert_equal([1, 3, 2], Foo.order_by_distance_spheroid('POINT(10 10)', 'SPHEROID["WGS 84", 6378137, 298.257223563]', :desc => true).order('id').all.collect(&:id))
|
260
|
+
end
|
87
261
|
end
|
88
262
|
end
|
data/test/writer_test.rb
CHANGED
@@ -283,5 +283,19 @@ class GeosWriterTests < Test::Unit::TestCase
|
|
283
283
|
out.read
|
284
284
|
)
|
285
285
|
end
|
286
|
+
|
287
|
+
def test_to_wkt_handles_binary_geos_arity
|
288
|
+
if @point.to_wkt(:rounding_precision => 0) =~ /^POINT\s*\((\d+(\.\d+)?)\s*(\d+(\.\d+)?)\)$/
|
289
|
+
lng, lat = $1.to_f, $3.to_f
|
290
|
+
end
|
291
|
+
|
292
|
+
if defined?(Geos::FFIGeos)
|
293
|
+
assert_equal(lng, 10.0, 0.000001)
|
294
|
+
assert_equal(lat, 10.0, 0.000001)
|
295
|
+
else
|
296
|
+
assert_equal(lng, 10.00, 0.000001)
|
297
|
+
assert_equal(lat, 10.01, 0.000001)
|
298
|
+
end
|
299
|
+
end
|
286
300
|
end
|
287
301
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geos-extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 7
|
10
|
+
version: 0.0.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- J Smith
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-03-
|
18
|
+
date: 2011-03-21 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|