Mongodb地理位置边界搜索/查询 [英] Mongodb geolocation boundaries search/query

查看:415
本文介绍了Mongodb地理位置边界搜索/查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文档,其中包含位置框"(正方形区域)的列表.每个框由2个点表示(左下或西南,右上或东北).

I have a documents contains list of location "boxes" (square area). Each box is represented by 2 points (bottom-left or south-west, top-right or north-east).

文档,例如:

{
   locations: [
        [[bottom,left],[top,right]],
        [[bottom,left],[top,right]],
        [[bottom,left],[top,right]]
   ]
}

我将 2d 索引用于这些边界点.

I'm using 2d index for those boundaries points.

我的输入是一个特定的位置点[x,y],我想获取列表中此点位于其中的所有文件.

My input is a specific location point [x,y] and I want to fetch all documents that have at list one box that this point is located in it.

是否可以使用地理空间运算符 ? 如何编写此查询?

Is there any geospatial operator I can use to do that? How do I write this query?

推荐答案

您可以使用box运算符,请参见: http://docs.mongodb.org/manual/reference/运算符/查询/框/#op._S_box ,下面的示例直接从该页面获取:

You can use the box operator, see: http://docs.mongodb.org/manual/reference/operator/query/box/#op._S_box with the following example taken directly from that page:

db.places.find( { loc : { $geoWithin : { $box :
                                      [ [ 0 , 0 ] ,
                                        [ 100 , 100 ] ] } } } )

值得注意的是,2d索引被认为是遗留的.如果可以转换为使用GeoJSON和2dsphere索引,则可以使用$ geoWithin运算符:请参见

It is worth noting that the 2d index is considered legacy. If you can convert to using GeoJSON and a 2dsphere index, then you can use the $geoWithin operator: see

http://docs.mongodb.org/manual /reference/operator/query/geoWithin/#op._S_geoWithin

GeoJSON具有许多其他好处,尤其是可以通过Web绘图应用程序(例如OpenLayers或Leaflet)轻松传输和消化.

GeoJSON has a number of other benefits, not least of which, is that it is easily transmitted and digested by web mapping apps such as OpenLayers or Leaflet.

这篇关于Mongodb地理位置边界搜索/查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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