【发布时间】:2015-11-26 21:48:26
【问题描述】:
我在集合c 中为字段loc 定义了一个“2dsphere”索引:
db.c.createIndex( { loc : "2dsphere" } )
我在c 集合中有以下文档。它是从 [0, 0] 到 [10, 10] 的 LineString:
db.c.insert({"name": "myLine", "loc": { type: "LineString", coordinates: [ [ 0, 0 ], [ 10, 10 ] ] }})
请注意,[5, 5] 将是线上的一个点。但是,以 [5, 5] 为中心的邻近查询(使用 $near 运算符)与文档不匹配:
db.c.find({
loc: {
$near: {
$geometry: {
type: "Point" ,
coordinates: [ 5, 5 ]
},
$maxDistance: 0.1,
}
}
})
也许 LineString 不能那样工作,从地理空间查询的角度来看,只有端点(在这种情况下为 [0, 0] 和 [10, 10])是相关的?在这种情况下,是 MongoDB geo spacial queries implementation 中的限制还是 GJSON standard 中的限制?
(在我做这个小实验之前,我一直认为 LineString 和 MultiPoint 的区别在于前者考虑了连接点的线,而后者只考虑了线末端的点。经过这个实验,我看不出有什么不同...)。
【问题讨论】:
标签: mongodb geolocation geospatial