Polygon里面的Mongodb Point没有得到结果 - Mongoid + Rails

时间:2015-09-25 03:18:15

标签: mongodb ruby-on-rails-4 mongoid

我试图用mongodb(mongodb 2.6)检查一个点是否在多边形内。 我在de collection中插入数据,如下所示:

"db": {
   "name": "mongodb",
   "url": "mongodb://username:password@iad-mongos2.objectrocket.com:port/dbName?ssl=true",
   "debug": true,
   "connector": "mongodb"
  }

像这样查询:

db.areas.insert({"polygons":
                      {"type":"Polygon",
                         coordinates:
                          [[[-23.0651232, -45.6374645],
                            [-23.0557255, -45.6435585],
                            [-23.0370072, -45.6383228],
                            [-23.0299772, -45.6351471],
                            [-23.0025649, -45.6480217],
                            [-22.9723022, -45.6554031],
                            [-22.9340493, -45.6032181],
                            [-22.9353140, -45.5925751],
                            [-22.9383177, -45.5855370],
                            [-22.9601320, -45.5560112],
                            [-22.9645577, -45.5597878],
                            [-22.9938740, -45.5675125],
                            [-22.9939530, -45.5690575],
                            [-23.0217620, -45.5712891],
                            [-23.0241319, -45.5719757],
                            [-23.0258697, -45.5711174],
                            [-23.0268966, -45.5721474],
                            [-23.0656365, -45.6372499],
                            [-23.0651232, -45.6374645]
                        ]]
                      }
                 });

但我没有得到任何结果。有什么想法吗?

我看过这个链接: mongodb check if point is in polygon Search all polygons that contains a series of points in mongodb

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

我找到了答案。 问题在于,当我试图保存时,来自Rails表单的Polygon坐标保存为String而不是Double。 在保存之前,我认为问题已经解决了。