如何在mongodb的边界框中获取任何项目(点,线字符串,多边形)
Howto get any item (Point, LineString, Polygon) within a bounding box in mongodb
我在查询中与边界框中的项目匹配时遇到问题。如何匹配所有类型 2dsphere
(GEO JSON) 的项目?在这种情况下,我只获得了 Point
类型的数据,但 LineString
类型的项目不会出现在结果中。
架构定义如以下示例所示:
/**
* Media location values (Point, LineString, Polygon)
* @property location
* @type {Object}
*/
location:{
"type":Object,
"index":"2dsphere"
},
例如,我在其中有以下项目:
[
{
"_account": "52796da308d618090b000001",
"_id": "5284e5798a1c039735000001",
"location": {
"coordinates": [
8.663705555555556,
50.10165277777778
],
"type": "Point"
},
"name": "Foto.JPG",
"preview": "/img/thumbs/13719-3zavxm.JPG",
"type": "image/jpeg",
"added": "2013-11-14T15:00:09.113Z",
"latlng": [ ],
"shares": [ ],
"shared": false,
"tags": [ ]
},
{
"_account": "52796da308d618090b000001",
"name": "Filtererd_Track.kml",
"type": "application/vnd.google-earth.kml+xml",
"_id": "5284e5c48a1c039735000002",
"added": "2013-11-14T15:01:24.280Z",
"latlng": [ ],
"shares": [ ],
"shared": false,
"tags": [ ]
},
{
"_account": "52796da308d618090b000001",
"_id": "5284e5c48a1c039735000003",
"location": {
"coordinates": [
[
9.49653,
50.94791
],
[
9.49731,
50.94811
],
[
9.49744,
50.94812
],
[
9.49755,
50.94808
],
[
9.4991,
50.94579
],
[
9.49969,
50.94545
],
[
9.50037,
50.94525
],
[
9.50136,
50.9452
],
[
9.50851,
50.98557
]
],
"type": "LineString"
},
"name": "test 2.gpx",
"preview": "/img/thumbs/13719-14rvt8w.png",
"type": "application/gpx+xml",
"added": "2013-11-14T15:01:24.529Z",
"latlng": [ ],
"shares": [ ],
"shared": false,
"tags": [ ]
}
]
获取项目的查询类似于以下示例,但它与 LineStrings
/Polygons
....认为这是因为子数组,但不知道如何将其包含在查询中。
{
{
"location": {
"$geoWithin": {
"$box": [
[
-39.375,
36.73888412439431
],
[
76.640625,
56.897003921272606
]
]
}
}
}
}
我找到了一种方法,通过使用$geoIntersects
并从边界框创建一个多边形来获取边界框中的所有内容。如下例所示。
{
"location": {
"$geoIntersects": {
"$geometry": {
"type": "Polygon",
"coordinates": [
[
[
5.372314453125,
52.288322586002984
],
[
12.623291015625,
52.288322586002984
],
[
12.623291015625,
49.67829251994456
],
[
5.372314453125,
49.67829251994456
],
[
5.372314453125,
52.288322586002984
]
]
]
}
}
}
]
}
相关文章:
- 正在将数据主题添加到所有项目
- 动态地改变“”的URL;添加新项目”;链接使用javascript/jquery
- 如何检查管道中未定义的项目
- 有没有一种方法可以添加相同的项目val=“0”;4〃;到JavaScript中数组的每个对象
- 学生搜索项目jquery/javascript
- 如何获取不属于我项目的上一页的URL
- Dojo:访问dijit.form.Select中单击的项目
- 角度的项目列表 ng 重复,ng 单击显示全宽描述
- 我需要为我的朋友在这个项目上提供帮助
- 如何从 HTML 查询中删除项目
- 在Meteor项目中安装并包含npm模块后出错
- 当在Ember中点击一个项目时,我如何将一个活动类添加到项目列表中
- SVG/JavaScript:尝试选择和更改多边形点
- 将单击事件添加到附加的项目中
- 通过另一个php应用程序将我的项目推送到Github存储库中
- 在javascript中搜索项目列表的性能
- 如何将本地依赖项添加到npm项目中
- angularjs移除焦点上的活动类并添加到下一个项目
- 如何获取谷歌地图多边形的当前fillColor
- 如何在mongodb的边界框中获取任何项目(点,线字符串,多边形)