【问题标题】:MongoDB: How to determine intersection of GeoJson LineString and a Point with radiusMongoDB:如何确定 GeoJson LineString 和具有半径的点的交集
【发布时间】:2015-02-17 00:50:03
【问题描述】:

如何在 MongoDB 中使用地理空间查询来确定,由 Point 和 radius 确定的圆是否与 LineString 相交?

用例:

MongoDB GeoJson LineString 对象定义如下:

db.places.insert(
{
    loc : { type: "LineString", coordinates: [ [-121.9420624, 37.3734995], [ -121.9388008, 37.3755458], [-121.9408607, 37.3720671] ] },
    name: "Small trail"
});

用户位置是 [ -121.928887, 37.299849 ] 如何判断一个以用户位置为中心,半径为10英里的圆是否与LineString相交?

我期待一个类似的查询

db.places.find({loc : {$geoIntersects :{$geometry :{$centerSphere: [ [ -121.928887, 37.299849 ], 100 / 3959 ]}}}});

但是这个不行

【问题讨论】:

    标签: mongodb geospatial


    【解决方案1】:

    文档令人困惑,但我认为最重要的是$geoIntersects 不适用于$centerSphere。不过,$centerSphere 确实适用于 $geoWithin。这对您的用例有用吗?语义有点不同,但可能足够接近。

    【讨论】:

    • @NitinSingh 文档说$geoWithin“选择具有完全存在于指定形状内的地理空间数据的文档。”即使这条线不完全在圆圈中,这是否真的有效?你也可以反之查询(找到给定线路径的圆圈)?
    猜你喜欢
    • 2021-05-06
    • 1970-01-01
    • 2011-02-22
    • 1970-01-01
    • 2021-08-04
    • 2011-04-25
    • 2021-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多