, . , - .
$geoIntersects mongoid 4.0.0.beta1, . : https://github.com/mongoid/origin/blob/master/CHANGELOG.md#new-features-1
query.geo_spacial(:location.intersects_line => [[ 1, 10 ], [ 2, 10 ]])
query.geo_spacial(:location.intersects_point => [[ 1, 10 ]])
query.geo_spacial(:location.intersects_polygon => [[ 1, 10 ], [ 2, 10 ], [ 1, 10 ]])
query.geo_spacial(:location.within_polygon => [[ 1, 10 ], [ 2, 10 ], [ 1, 10 ]])
: https://github.com/mongoid/origin/commit/30938fad644f17fe38f62cf90571b78783b900d8
mongoid (4.0.0.beta1) origin (2.1.0)
Polygon
class Polygon
include Mongoid::Document
embeds_many :loc
def find_polygons_with_point(coordinates)
Polygon.all.geo_spacial(:loc.intersects_point => coordinates)
end
end
Loc
class Loc
field :type, type: String
field :coordinates, type: Array
embedded_in :polygon
index({ coordinates: "2d" }, { min: -200, max: 200 })
end
, .
. , :)