class Mongoid::Geospatial::GeometryField
Main Geometry Array Holds Lines/Polygons.…
Public Class Methods
demongoize(o)
click to toggle source
Database -> Object
# File lib/mongoid_geospatial/fields/geometry_field.rb, line 37 def demongoize(o) new(o) end
Public Instance Methods
bounding_box()
click to toggle source
# 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
Also aliased as: bbox
center_point()
click to toggle source
# 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
Also aliased as: center
radius(r = 1)
click to toggle source
# File lib/mongoid_geospatial/fields/geometry_field.rb, line 26 def radius(r = 1) [center, r] end
radius_sphere(r = 1, unit = :km)
click to toggle source
# 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
Private Instance Methods
points()
click to toggle source
# File lib/mongoid_geospatial/wrappers/rgeo.rb, line 20 def points self.map do |pair| RGeo::Geographic.spherical_factory.point(*pair) end end