I have a Mongo collection on which I am trying to perform a $geoIntersects query.
The data in mongo is in the form of:
{
"_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:
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?
If you run the same query in Postgis, you get the answer 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.
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. 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 . 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.