Class: Mongoid::Geospatial::GeometryField
- Inherits:
-
Array
- Object
- Array
- Mongoid::Geospatial::GeometryField
show all
- Defined in:
- lib/mongoid_geospatial/fields/geometry_field.rb,
lib/mongoid_geospatial/wrappers/rgeo.rb
Overview
Main Geometry Array Holds Lines/Polygons.…
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.demongoize(o) ⇒ Object
37
38
39
|
# File 'lib/mongoid_geospatial/fields/geometry_field.rb', line 37
def demongoize(o)
new(o)
end
|
Instance Method Details
#bounding_box ⇒ Object
Also known as:
bbox
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/mongoid_geospatial/fields/geometry_field.rb', line 7
def bounding_box
max_x, min_x = -Float::MAX, Float::MAX
max_y, min_y = -Float::MAX, Float::MAX
each do |point|
max_y = point[1] if point[1] > max_y
min_y = point[1] if point[1] < min_y
max_x = point[0] if point[0] > max_x
min_x = point[0] if point[0] < min_x
end
[[min_x, min_y], [max_x, max_y]]
end
|
#center_point ⇒ Object
Also known as:
center
20
21
22
23
|
# File 'lib/mongoid_geospatial/fields/geometry_field.rb', line 20
def center_point
min, max = *bbox
[(min[0] + max[0]) / 2.0, (min[1] + max[1]) / 2.0]
end
|
#radius(r = 1) ⇒ Object
26
27
28
|
# File 'lib/mongoid_geospatial/fields/geometry_field.rb', line 26
def radius(r = 1)
[center, r]
end
|
#radius_sphere(r = 1, unit = :km) ⇒ Object
30
31
32
|
# File 'lib/mongoid_geospatial/fields/geometry_field.rb', line 30
def radius_sphere(r = 1, unit = :km)
radius r.to_f / Mongoid::Geospatial.earth_radius[unit]
end
|