我正在尝试检查点是否在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.
更多推荐
发布评论