gpt4 book ai didi

MongoDB $geoIntersects 不返回特定城市的任何数据

转载 作者:可可西里 更新时间:2023-11-01 09:38:36 26 4
gpt4 key购买 nike

我从金奈和类加罗尔城市的谷歌地图中手动获取坐标并插入到我的数据库中。对于类加罗尔市,$geoIntersect 工作得很好。然而,出于某种原因,对于钦奈市,它没有出现。我不确定我在哪里/错过了什么。在下面附上我的代码

类加罗尔城市详情

{
"_id" : ObjectId("5b2d45ef4b511713052b49f9"),
"cityId" : 10256,
"countryEn" : "india",
"countryAr" : "india ar",
"provinceEn" : "Bangalore",
"provinceAr" : "Bangalore ar",
"cityEn" : "Bangalore",
"cityAr" : "Bangalore ar",
"lat" : 12.972442,
"lon" : 77.580643,
"countryCode" : "+91",
"population" : 150257,
"boundaries" : {
"coordinates" : [
[
[
77.747618,
13.105034
],
[
77.758604,
13.039487
],
[
77.816283,
12.959201
],
[
77.825896,
12.853452
],
[
77.742125,
12.884244
],
[
77.700926,
12.797213
],
[
77.461973,
12.783821
],
[
77.412535,
12.911017
],
[
77.390562,
13.047514
],
[
77.525145,
13.150506
],
[
77.636381,
13.155855
],
[
77.747618,
13.105034
]
]
],
"type" : "Polygon"
}
}

我使用的查询

db.Cities_Master.find({
boundaries: {
$geoIntersects: {
$geometry: { type: 'Point', coordinates: [77.5476, 13.105034] },
},
},
})

金奈市详细信息

{
"_id" : ObjectId("5b2d4a734b511713052b4a01"),
"cityId" : 10255,
"countryEn" : "india",
"countryAr" : "india ar",
"provinceEn" : "chennai",
"provinceAr" : "chennai ar",
"cityEn" : "chennai",
"cityAr" : "chennai ar",
"lat" : 13.067439,
"lon" : 80.237617,
"countryCode" : "+91",
"population" : 150257,
"boundaries" : {
"coordinates" : [
[
[
80.309211,
13.257326
],
[
80.332557,
13.241285
],
[
80.332557,
13.249305
],
[
80.295478,
13.091519
],
[
80.248786,
12.838584
],
[
80.149909,
12.880089
],
[
80.097724,
12.936309
],
[
80.123816,
13.14368
],
[
80.320197,
13.199841
],
[
80.178748,
13.2092
],
[
80.239173,
13.215885
],
[
80.309211,
13.257326
]
]
],
"type" : "Polygon"
}
}

查询我以前找金奈

db.Cities_Master.find({
boundaries: {
$geoIntersects: {
$geometry: { type: 'Point', coordinates: [80.309211, 13.257326] },
},
},
})

对于 Chennai 查询,我得到没有找到记录。我是否以错误的方式或任何其他问题插入了坐标?任何帮助,将不胜感激。谢谢

最佳答案

Bangalore City 坐标由有效的闭合多边形表示,这就是 MongoDB 查询有效的原因。在 Chennai 情况下,坐标顺序不正确。您可以轻松查看here :

enter image description here

因此,要解决这个问题,您可以在数据库中重新排序不正确的坐标Chennai 的有效文档可能如下所示:

db.Cities_Master.save({
"_id" : ObjectId("5b2d4a734b511713052b4a01"),
"cityId" : 10255,
"countryEn" : "india",
"countryAr" : "india ar",
"provinceEn" : "chennai",
"provinceAr" : "chennai ar",
"cityEn" : "chennai",
"cityAr" : "chennai ar",
"lat" : 13.067439,
"lon" : 80.237617,
"countryCode" : "+91",
"population" : 150257,
"boundaries" : {
"coordinates" : [
[
[
80.309211,
13.257326
],
[
80.332557,
13.249305
],
[
80.332557,
13.241285
],
[
80.320197,
13.199841
],
[
80.295478,
13.091519
],
[
80.248786,
12.838584
],
[
80.149909,
12.880089
],
[
80.097724,
12.936309
],
[
80.123816,
13.14368
],
[
80.178748,
13.2092
],
[
80.239173,
13.215885
],
[
80.309211,
13.257326
]
]
],
"type" : "Polygon"
}
})

可以预览here .在这种情况下,您的查询工作正常。

关于MongoDB $geoIntersects 不返回特定城市的任何数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50994901/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com