如何在 MongoDB 中保存的 geoJson 中查找多边形

How to find polygon in geoJson saved in MongoDB

我得到了一些我放入 MongoDB 库中的 geoJSON 文件。 geoJSON 模式是标准化的,所以我希望不要更改它。 geoJSON 文件表示由一组区域(多边形)定义的标记 一个标签可能包含多个多边形 不同的标签可能包含相同的区域或多边形。

geoJSON 文件如下:

{
    "_id": {
        "$oid": "5570864ee4b08fb4e548beb6"
    },
    "type": "FeatureCollection",
    "crs": {
        "type": "name",
        "properties": {
            "name": "urn:ogc:def:crs:OGC:1.3:CRS84"
        }
    },
    "features": [
        {
            "type": "Feature",
            "properties": {
                "ida": "2335",
                "name": "myName",                    
                 ...,
                "surf_m2": 13432292
            },
            "geometry": {
                "type": "MultiPolygon",
                "coordinates": [
                    [
                        [
                            [
                                -1.366403393656118,
                                47.19539498257428
                            ],
                            [
                                -1.357701323667323,
                                47.19374649592587
                            ],
                            [
                                -1.357566935700819,
                                47.1932311120653
                            ],
                            [
                                -1.357111040694128,
                                47.192966611925904
                            ],
                            ...
                        ]
                    ]
                ]
            }
        }
    ]
}

图片我有很多这样的文档。

我如何查询 shell 中的 mongoDB 以查找在基础中可用的多边形内的区域(按名称、ID 或其他)。

我已经试过了:

db.Collection.find({"features":{"$geoIntersects":{"$geometry":{"type":"Point", "coordinates":[-1.3545706,47.166627 ]}}}})

db.runCommand( { geoNear : "Collection" ,near : { type : "Point",coordinates:[-1.3545706,47.166627]},spherical : true }

我的问题是我无法到达坐标,因为它不能在根级别直接访问,但在 features.geometry.coordinates。

求助...

这是运行时的方法,将 GPS 位置替换为您想要的位置。

db.CollectionName.find({"features.geometry":{"$geoIntersects":{"$geometry":{"type":"Point", "coordinates":[ -1.346784,47.141102]}}}})