[英]Howto get any item (Point, LineString, Polygon) within a bounding box in mongodb
I've a problem with a query matching items inside a BoundingBox. 查询与BoundingBox中的项目匹配时出现问题。 How it's possible to match all items of type
2dsphere
(GEO JSON)? 如何匹配
2dsphere
(GEO JSON)类型的所有项目? In this case I only got the data of type Point
but the items of type LineString
won't appear inside the result. 在这种情况下,我只得到
Point
类型的数据,但LineString
类型的项目不会出现在结果中。
The schema definition looks like the following example: 模式定义类似于以下示例:
/**
* Media location values (Point, LineString, Polygon)
* @property location
* @type {Object}
*/
location:{
"type":Object,
"index":"2dsphere"
},
I've eg this items in it: 我在其中有以下内容:
[
{
"_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": [ ]
}
]
The query to fetch the items looks like the following example but it does not match LineStrings
/ Polygons
.... Think it's because of the subarrays but don't know how to include this in the query. 用于获取项目的查询看起来像下面的示例,但是它与
LineStrings
/ Polygons
...不匹配。认为这是由于子数组,但是不知道如何在查询中包括它。
{
{
"location": {
"$geoWithin": {
"$box": [
[
-39.375,
36.73888412439431
],
[
76.640625,
56.897003921272606
]
]
}
}
}
}
I found a way to get everything in a bounding box by using $geoIntersects
and create a Polygon from Bounding Box. 我找到了一种通过使用
$geoIntersects
在边界框中获取所有内容并从边界框创建多边形的方法。 Like example below. 像下面的例子。
{
"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
]
]
]
}
}
}
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.