如何在mongodb中存储一个圆并查看它是否与box/Geojson点重叠
我不确定是否有办法做到这一点。我需要在mongodb中有一个圆,并使用$box对该圆进行查询,以查看这两个形状是否重叠。但是,Geojson不支持圆。完成这项工作的最佳方式是什么? 圆圈的存储方式如下:如何在mongodb中存储一个圆并查看它是否与box/Geojson点重叠,mongodb,mongodb-geospatial,Mongodb,Mongodb Geospatial,我不确定是否有办法做到这一点。我需要在mongodb中有一个圆,并使用$box对该圆进行查询,以查看这两个形状是否重叠。但是,Geojson不支持圆。完成这项工作的最佳方式是什么? 圆圈的存储方式如下: places = { ... "location": { "type": "Point", "coordinates": [ -79.390756, 43.706685 ] }, "radius": 100 } 我有两个具体问题: 第一
places = {
...
"location": {
"type": "Point",
"coordinates": [
-79.390756,
43.706685
]
},
"radius": 100
}
我有两个具体问题:
places = {
...
"location": {
"type": "Point",
"coordinates": [
-79.390756,
43.706685
]
},
"radius": 100
}
“几何学”:{
“界限”:{
“东北”:{
“lat”:43.710565,
“液化天然气”:-79.3736347999999
},
“西南”:{
“lat”:43.690848,
“液化天然气”:-79.40025399999
}
}
据我所知,我不能使用$box,因为它只适用于$geointendb.places.aggregate([
{"$geoNear": {near: { type: "Point", coordinates: [ -80.459293, 40.713640] },
distanceField: "dist.calculated", maxDistance: 100000,
key: 'myLocation', query: { 'SomeField': "..." }, spherical: true}},
{ "$match" : {$expr:{ $lte:['$dist.calculated', 'radius']}}}])
这里的问题是,我必须先在100公里内运行查询,然后在聚合的另一个阶段检查距离。
有没有更有效的方法来实现这一点?谢谢。您可以将圆存储为点和半径。您可以使用
$near
查询点和$maxDistance
以米为单位,这是圆的半径。请参阅
查询以查找距离某个点一定距离处集合的所有位置,几何体字段
db.places.find(
{
location:
{ $near :
{
$geometry: { type: "Point", coordinates: [ -73.9667, 40.78 ] },
$maxDistance: 5000
}
}
}
)
查询以查找查询中的给定几何体(点、多边形(矩形))是否与集合中字段的几何体相交
//find quests bots that matches the users location
await Collection.find({ geometry:
{ $geoIntersects:
{
{
type: "Point",
coordinates: [
-73.99460599999999,
40.7347229
]
}
}
}
});
非常感谢。看起来不错。我想知道是否有一种方法可以在$geometry子句中使用$box(或具有相同功能的东西)。我使用Google Geocode Api进行部分邮政编码查找,它返回一个具有两个坐标的对象,如下所示:{“lat”:43.710565,“lng”:-79.3736347999999},“西南”:{“lat”:43.690848,“lng”:-79.40025399999999}。有没有办法用这两个坐标创建一个框,并检查它是否与圆重叠?谢谢。当然,你可以用它在边界框外创建一个框。[东北、西北、西南、东南]我的意思是使用mongdb创建具有两个角坐标的边界框…多边形有效:。只需通过重复第一个点NE使其闭合形状。[NE,NW,SW,SE,NE]很好。据我所知,无法从查询中的同一obejct读取maxDistance。我可能可以通过聚合来完成。你对此有什么建议吗?