2

我在查询匹配边界框内的项目时遇到问题。如何匹配所有类型的项目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
                    ]
                ]
            }
        }
    }
}
4

1 回答 1

3

我找到了一种通过使用$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
                        ]
                    ]
                ]
            }
        }
    }
    ]
}
于 2013-11-24T21:36:49.130 回答