简体   繁体   English

MongoDB $ geoIntersects与LineString类型不匹配

[英]MongoDB $geoIntersects does not match LineString type

I have a Mongo collection on which I am trying to perform a $geoIntersects query. 我有一个Mongo集合,正在尝试执行$ geoIntersects查询。

The data in mongo is in the form of: mongo中的数据的形式为:

{
    "_id" : ObjectId,
    "created_at" : ISODate,
    "sentiment" : 0.631925,
    "yyyy-mm" : "2012-9",
    "lat_lon" : [
        -2.0566385,
        52.84265
    ]
}

Running a $geoIntersects query in the form of: 以以下形式运行$ geoIntersects查询:

db.gbSmall.findOne({
    lat_lon: {
        $geoIntersects: {
            $geometry: {
                type: "Point",
                coordinates: [-2.0566385,52.84265]
            }
        }
    }
})

or 要么

db.gbSmall.findOne({
    lat_lon: {
        $geoIntersects: {
            $geometry: {
                type: "LineString",
                coordinates: [[-2.0566385,52.84265],[-3.0566385,52.84265]]
            }
        }
    }
})

both properly return the record; 都正确返回记录; however, if I change the query so the line runs through the point, such as: 但是,如果我更改查询,则该行贯穿该点,例如:

db.gbSmall.findOne({
    lat_lon: {
        $geoIntersects: {
            $geometry: {
                type: "LineString",
                coordinates: [[-1.0566385,52.84265],[-3.0566385,52.84265]]
            }
        }
    }
})

the record is not returned. 记录不返回。

Does a record have to fall on a point of a geoJSON lineString to be matched, or is there something else wrong with the query I am performing? 记录是否必须落在要匹配的geoJSON lineString的点上,或者我执行的查询是否还存在其他问题?

If you run the same query in Postgis, you get the answer true. 如果在Postgis中运行相同的查询,则答案为true。

Select ST_Intersects(ST_GeomFromText('POINT(-2.0566385 52.84265)', 4326),
 ST_GeomFromText('LINESTRING(-1.0566385 52.84265,-3.0566385 52.84265)', 4326));

You also get the same answer for a similar sanity check query: 对于类似的健全性检查查询,您也会得到相同的答案:

Select ST_Intersects(ST_GeomFromText('POINT(-2 50)',4326),
 ST_GeomFromText('LINESTRING(-3 50, -1 50)',4326));

whereas both the MongoDB versions return nothing for the equivalent queries you gave above. 而两个MongoDB版本对于您在上面给出的等效查询均不返回任何内容。

To me this looks like a bug. 对我来说,这似乎是一个错误。 I checked the MongoDB source code and their tests and there isn't one for point on line except with end points. 我检查了MongoDB源代码和它们的测试,除了端点之外,没有一个在线上的点。 The MongoDB intersects functions found in https://github.com/mongodb/mongo/blob/master/src/mongo/db/geo/geoquery.cpp actually use the 3rd party s2 module to do the actual mathematical intersections, see https://github.com/mongodb/mongo/blob/master/src/third_party/s2/s2latlngrect.cc . https://github.com/mongodb/mongo/blob/master/src/mongo/db/geo/geoquery.cpp中找到的MongoDB相交函数实际上使用了第三方s2模块来进行实际的数学相交,请参见https: //github.com/mongodb/mongo/blob/master/src/third_party/s2/s2latlngrect.cc That is as far as I have got. 据我所知。

I am not posing this as an answer, as I don't have one, but the formatting is nicer than in comments. 我没有将其作为答案,因为我没有答案,但是格式比注释中的格式好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM