gpt4 book ai didi

MongoDB - 使用 $polygon 或 $geometry 的 $geoWithin 查询给出不同的结果

转载 作者:IT老高 更新时间:2023-10-28 13:29:59 28 4
gpt4 key购买 nike

使用 MongoDB 3.2 我正在尝试对点集合使用 2dsphere 查询。

假设我有一个集合 cust_5_abcd,在 the_geom 字段上有一个 2dsphere 索引。

在集合中添加几何图形:

db.cust_5_abcd.insert({
"chps0" : "Texte d'une ligne",
"the_geom" : {
"type" : "Point",
"coordinates" : [
1.032715,
40.380028
]
}})

现在我正在尝试使用 $geoWithin 查询此点,以获取特定多边形内的所有数据。如果我将 $geometry 与 GeoJSON 定义一起使用,或者与 $polygon 和严格坐标一起使用,这就是我得到不同结果的地方。也许文档中的某些内容丢失或我误解了。

$geometry 没有结果:

db.cust_5_abcd.find(  { the_geom: 
{ $geoWithin:
{ $geometry:
{
"type": "Polygon",
"coordinates": [
[
[ -16.237793, 40.162083 ],
[ -16.237793, 51.835778 ],
[ -13.776855, 51.835778 ],
[ -13.776855, 41.426253 ],
[ 14.765625, 41.426253 ],
[ 14.765625, 40.162083 ],
[ -16.237793, 40.162083 ]
]
]
}
}
}
})

使用 $polygon 返回我的点:

db.cust_5_abcd.find( { the_geom: 
{ $geoWithin:
{ $polygon:
[
[ -16.237793, 40.162083 ],
[ -16.237793, 51.835778 ],
[ -13.776855, 51.835778 ],
[ -13.776855, 41.426253 ],
[ 14.765625, 41.426253 ],
[ 14.765625, 40.162083 ],
[ -16.237793, 40.162083 ]
]
}
}
})

最佳答案

从 mongodb 人那里得到答案:https://jira.mongodb.org/browse/SERVER-24549?focusedCommentId=1293398&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-1293398

When using $polygon a planar geometry is calculated, and the point falls inside the polygon you describe. But when you use GeoJSON a spherical geometry is used, and the point falls outside the geometry

现在的问题是我不能在 $geoIntersect 上使用 $polygon 例如或与其他几何形状然后是多边形。

关于MongoDB - 使用 $polygon 或 $geometry 的 $geoWithin 查询给出不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37676794/

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