英文:
$geoWithin query fail to retrieve point included in the queried polygon - v2
问题
I've already asked the same question in this post. My example was subject to earth curvature issue so let's have a look at another one.
This time I have two nested polygons. A large one and a smaller one. Performing a $geoWithin query with the larger one returns no document, while the document is found using the smaller polygon. Any thoughts?
The document I'm trying to query is located on an island on the west coast of France.
{
"_id": {
"$oid": "625fec0f6476793a4581d172"
},
"featureOfInterest": {
"samplingFeature": {
"geometry": {
"type": "Point",
"coordinates": [
-2.3433781679840138,
46.713764788942484
]
},
"name": [
{
"lang": "en",
"text": "France"
}
],
"type": "Feature"
}
}
}
And the query:
db.collection.aggregate([
{
$match: {
"$or": [
// Largest polygon - returns no document
{
"samplingFeature.geometry": {
"$geoWithin": {
"$geometry": {
"type": "Polygon",
"coordinates": [
[[-55.722656, 34.161818], [58.007813, 34.161818], [58.007813, 53.540307], [-55.722656, 53.540307], [-55.722656, 34.161818]]
]
}
}
}
},
// Smallest polygon - returns the document
//{
// "samplingFeature.geometry": {
// "$geoWithin": {
// "$geometry": {
// "type": "Polygon",
// "coordinates": [[[-5.800781, 42.682435], [9.316406, 42.682435], [9.316406, 50.625073], [-5.800781, 50.625073], [-5.800781, 42.682435]]]
// }
// }
//}
//}
]
}
}
])
英文:
I've already ask the same question in this post. My example was subject to earth curvature issue so lets have a look to another one.
This time I have two nested polygons. A large one and a smaller one. Performing a $geoWithin query with the larger one return no document while the document is found using the smaller polygon. Any thoughts?
https://mongoplayground.net/p/V_3-s-itngA
The document I'm trying to query which is located on an island on France west coast.
{
"_id": {
"$oid": "625fec0f6476793a4581d172"
},
"featureOfInterest": {
"samplingFeature": {
"geometry": {
"type": "Point",
"coordinates": [
-2.3433781679840138,
46.713764788942484
]
},
"name": [
{
"lang": "en",
"text": "France"
}
],
"type": "Feature"
}
}
}
And the query
db.collection.aggregate([
{
$match: {
"$or": [
//Largest polygon - return no document
{
"samplingFeature.geometry": {
"$geoWithin": {
"$geometry": {
"type": "Polygon",
"coordinates": [
[[-55.722656,34.161818],[58.007813,34.161818],[ 58.007813,53.540307],[ -55.722656, 53.540307], [-55.722656,34.161818]]]
}
}
}
},
//Smallest polygon - return the document
//{
// "samplingFeature.geometry": {
// "$geoWithin": {
// "$geometry": {
// "type": "Polygon",
// "coordinates": [[[-5.800781, 42.682435], [9.316406, 42.682435], [9.316406, 50.625073], [-5.800781, 50.625073], [-5.800781, 42.682435]]]
// }
// }
//}
//}
]
}
}
])
答案1
得分: 1
你已经把地球弯曲了。你帖子中的坐标制成了这些框:
标记明显在更大的框外面。
请使用我在你之前问题的答案中提供的jsfddle链接,而不是使用地球仪或其他来源获取你的图像。两点之间的最短路径不一定遵循经度和纬度。请阅读有关Mongo地理空间查询中使用的大圆线计算的数学知识。
英文:
You've bent the planet other way round. The coordinates in your post make these boxes:
the marker is clearly outside the the larger box.
Please use the link to jsfddle in my answer to your previous question instead of globes, or wherever you get your image from. The shortest path between 2 points far away does not necessarily follow longitudes and latitudes. Please read about the math of Geodesic calculations used in mongo geospatial queries.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论