【发布时间】:2014-07-18 00:07:57
【问题描述】:
我有一个 Mongo 集合,我正在尝试对其执行 $geoIntersects 查询。
mongo中的数据格式为:
{
"_id" : ObjectId,
"created_at" : ISODate,
"sentiment" : 0.631925,
"yyyy-mm" : "2012-9",
"lat_lon" : [
-2.0566385,
52.84265
]
}
以以下形式运行 $geoIntersects 查询:
db.gbSmall.findOne({
lat_lon: {
$geoIntersects: {
$geometry: {
type: "Point",
coordinates: [-2.0566385,52.84265]
}
}
}
})
或
db.gbSmall.findOne({
lat_lon: {
$geoIntersects: {
$geometry: {
type: "LineString",
coordinates: [[-2.0566385,52.84265],[-3.0566385,52.84265]]
}
}
}
})
两者都正确返回记录;但是,如果我更改查询,使线穿过该点,例如:
db.gbSmall.findOne({
lat_lon: {
$geoIntersects: {
$geometry: {
type: "LineString",
coordinates: [[-1.0566385,52.84265],[-3.0566385,52.84265]]
}
}
}
})
记录没有返回。
记录是否必须落在 geoJSON lineString 的某个点上才能匹配,还是我正在执行的查询有其他问题?
【问题讨论】:
-
我可以确认您的结果。有趣的问题。我尝试使用没有小数位的数字,例如 [-3,50] 到 [-1,50] 的线是否与点 [-2,50] 相交,但没有返回任何内容。我的猜测是它与舍入精度有关。我快速浏览了源代码,但无济于事,因为我不是 c++ 大师。
-
您对此有进一步了解吗?在我头晕目眩之前,我仔细查看了源代码,但我有理由确定这是一个错误。