如何在mongodb的边界框中获取任何项目(点,线串,多边形) [英] Howto get any item (Point, LineString, Polygon) within a bounding box in mongodb
问题描述
我在与BoundingBox内的项目匹配的查询中遇到问题.
如何匹配所有类型为2dsphere
(GEO JSON)的项目?
在这种情况下,我只能得到类型为Point
的数据,但是类型为LineString
的项目将不会出现在结果中.
I've a problem with a query matching items inside a BoundingBox.
How it's possible to match all items of type 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.
模式定义类似于以下示例:
The schema definition looks like the following example:
/**
* 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
...不匹配.
认为这是由于子数组引起的,但不知道如何在查询中包括它.
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.
{
{
"location": {
"$geoWithin": {
"$box": [
[
-39.375,
36.73888412439431
],
[
76.640625,
56.897003921272606
]
]
}
}
}
}
推荐答案
我找到了一种方法,可以使用$geoIntersects
在边界框内获取所有内容,并从边界框创建多边形.
像下面的例子.
I found a way to get everything in a bounding box by using $geoIntersects
and create a Polygon from Bounding Box.
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
]
]
]
}
}
}
]
}
这篇关于如何在mongodb的边界框中获取任何项目(点,线串,多边形)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!