mongodb - 查找所有位置 $geoWithin $geoIntersects
问题描述
我想找出集合中的哪个多边形包含另一个集合中的最多点。
我正在使用一个包含餐厅数据(点)的集合和一个包含邻域数据(多边形)的集合
这两个集合都由 mongodb 提供:
https://raw.githubusercontent.com/mongodb/docs-assets/geospatial/neighborhoods.json https://raw.githubusercontent.com/mongodb/docs-assets/geospatial/restaurants.json
邻里文件:
{
"_id": {
"$oid": "55cb9c666c522cafdb053a1a"
},
"geometry": {
"coordinates": [
[
[
-73.9443878859649,
40.70042452378256
],
[
-73.94424286147482,
40.69969927964773
],
[
-73.94193078816193,
40.70072523469547
],…
]
],
"type": "Polygon"
},
"name": "Bedford"
}
餐厅文件
{
"_id" : { "$oid" : "55cba2476c522cafdb053add" },
"location" : {"coordinates":[-73.856077,40.848447] , "type":"Point" },
"name" : "Morris Park Bake Shop"
}
这是一个查找单个区域内所有餐厅的示例:
通过给定点($geoIntersects)选择一个邻域(多边形)
var neighborhood = db.neighborhoods.findOne(
{
geometry:
{
$geoIntersects:
{
$geometry: { type: "Point", coordinates: [ -73.93414657, 40.82302903 ] }
}
}
}
)
找出附近有多少家餐馆
db.restaurants.find( { location: { $geoWithin: { $geometry: neighborhood.geometry } } } ).count()
我的问题:
哪个街区的餐馆最多?
解决方案
推荐阅读
- typescript - 达到超时后调用另一个函数
- python - 为什么我在读取数据框时会得到 dtype 'object'?
- aggregate-functions - Tableau - 基于平均值的排名平均值
- java - log4j2 不登录子进程
- perl - perl中的自动格式化单词表
- c# - 如何在 C# 中将字符串日期转换为日期时间数据类型?
- haskell - 如何修复类型匹配错误
- node.js - Nodejs Electron如何摆脱Windows上下文菜单上的右键单击选项
- docker - 在 Docker Compose 集群启动后等待
- javascript - 将新键名从旧数组分配给数组