MongoDB如何找到哪个多边形包含指定的Point? [英] MongoDB How to find which polygon contains a specified Point?

查看:223
本文介绍了MongoDB如何找到哪个多边形包含指定的Point?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将很多多边形插入到MongoDB(2.4.8)中,希望找到指定Point所在的多边形。这似乎是一个常见问题。但从谷歌阅读所有文档后,我没有得到结果。所以创建这个问题。

例如

  db.addr_poly.insert(
{loc:
{type:Polygon,
coordinates:[[[0,0],[3,6],[6,1],[0,0]]]
$}}
db.addr_poly.insert(
{loc:
{type:Polygon,
coordinates:[[[0,0],[-3, -6],[-6,-1],[0,0]]]
}})

现在如何找到包含Point(1,1)的多边形?



任何人都可以帮助我?非常感谢!

解决方案

使用 $ geoIntersects运算符。它会查询与您传递的GeoJSON对象相交的所有形状。当你通过一个点时,它应该返回包含该点的所有形状。请记住,$ geoIntersects操作符仅适用于2dsphere索引,而不适用于2d索引。


I insert many polygons into MongoDB(2.4.8), and hope find the polygon a specified Point sits in. It seems a common question. But after reading all docs from google, I didn't get the result. So create this question.

e.g.

db.addr_poly.insert(
{ loc :
   { type : "Polygon" ,
     coordinates : [ [ [ 0 , 0 ] , [ 3 , 6 ] , [ 6 , 1 ] , [ 0 , 0 ] ] ]
} })
db.addr_poly.insert(
{ loc :
   { type : "Polygon" ,
     coordinates : [ [ [ 0 , 0 ] , [ -3 , -6 ] , [ -6 , -1 ] , [ 0 , 0 ] ] ]
} })

Now how to find the polygon which contains Point(1,1)?

Anybody can help me? Thanks a lot!

解决方案

Use the $geoIntersects operator. It queries for all shapes which intersect the GeoJSON object you pass. When you pass a point to it, it should return all shapes which include that point. Keep in mind that the $geoIntersects operator only works for 2dsphere indexes, not for 2d indexes.

这篇关于MongoDB如何找到哪个多边形包含指定的Point?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆