मैं हाल ही में था इसके लिए खोज, और थोड़ी देर बाद मुझे निम्नलिखित मिला। हो सकता है कि किसी और .. इस के लिए उपयोग होगा ..
$ 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
# Add a $geoIntersects selection. Symbol operators must be used as shown in
# the examples to expand the criteria.
#
# @note The only valid geometry shapes for a $geoIntersects are: :line,
# :point, and :polygon.
# ...
# @example Add a geo intersect criterion for a point.
# query.geo_intersects(:location.point => [[ 1, 10 ]])
अपने प्रोजेक्ट में मैं mongoid (4.0.0.beta1) और मूल है (2.1.0) मैं एक मॉडल बहुभुज
है
class Polygon
include Mongoid::Document
# some fields
embeds_many :loc
# coordinates is an array of two points: [10, 12]
def find_polygons_with_point(coordinates)
# This is where the magic happens!
Polygon.all.geo_spacial(:loc.intersects_point => coordinates)
end
end
और एक मॉडल नियंत्रण रेखा
class Loc
field :type, type: String #Need to be set to 'Polygon' when creating a new location.
field :coordinates, type: Array
# For some reason the array has to be in the format
# [ [ [1,1], [2,3], [5,3], [1,1] ] ]
# And the first coordinate needs to be the same as the last
# to close the polygon
embedded_in :polygon
index({ coordinates: "2d" }, { min: -200, max: 200 }) #may not need min/max
end
इस कोड को सभी बहुभुज इस बिंदु के अंदर है कि देता है।
ऐसा करने के और अधिक शानदार तरीके हो सकते हैं।यदि ऐसा है तो मैं इसे सुनना चाहूंगा :)
दुर्रान के अनुसार, $ geoIntersects के लिए समर्थन Mongoid 4.0 रिलीज में होगा। – chrishol
4.0 जारी किया गया है लेकिन मुझे चेंजलॉग में '$ geoIntersects' नहीं दिखाई देता है :(https://github.com/mongoid/mongoid/blob/master/CHANGELOG.md – oyatek
या जारी नहीं किया गया? :) मैं चेंजलॉग में 4.0 देखता हूं लेकिन 4.0 – oyatek