Mongodb点在一个Polygon中没有得到结果

编程入门 行业动态 更新时间:2024-10-25 12:21:07
Mongodb点在一个Polygon中没有得到结果 - Mongoid + Rails(Mongodb Point inside a Polygon not getting results - Mongoid + Rails)

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

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] ]] } });

并查询如下:

db.areas.find({polygons: {$geoIntersects: {$geometry:{ "type" : "Point", "coordinates" : [ -22.112, -45.56 ] } } } });

但我没有结果。 有任何想法吗?

我看过这个链接: mongodb检查点是否在多边形中 搜索所有包含mongodb中的一系列点的多边形

任何帮助将不胜感激

I'm trying to check if a point is inside a polygon with mongodb (mongodb 2.6). I'm inserting the data in de collection like this:

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] ]] } });

And querying like this:

db.areas.find({polygons: {$geoIntersects: {$geometry:{ "type" : "Point", "coordinates" : [ -22.112, -45.56 ] } } } });

But I'm getting no result. Any ideas?

I've looked this links: mongodb check if point is in polygon Search all polygons that contains a series of points in mongodb

Any help will be appreciated

最满意答案

我找到了答案。 问题是,当我试图保存时,从Rails窗体的Polygon坐标被保存为String而不是Double。 在保存之前,我认为问题已经解决了。

I found the answer. The problemas was that when I tried to save, the coordinates of the Polygon from a Rails form it was saved as String and not as Double. I chaged that before save an the problem was solved.

更多推荐

本文发布于:2023-08-07 07:18:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1462382.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Mongodb   Polygon

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!