查找给定的经度、纬度对是否位于 MongoDB 中的任何多边形中
Find if given longitude, latitude pair lies in any of the polygon in MongoDB
根据我目前对 MongoDB 的理解,我们通过传递一个 [long, lat] 对数组来搜索我们的集合,以检查该文档的 [long, lat] 对是否存在于坐标 [[ [], [], [] ]]
.
我,即
db.SomeCollection.find({
"location":{
$geoWithin: {
$geometry: {
type: "Polygon",
coordinates: [
[[1, 2], [1, 3], [1, 4]],
[[2, 5], [2, 6], [2, 7]]
] }
}
}
})
我正在寻找的是,我需要将 [long, lat] 对提供给包含固定多边形地理围栏数组的文档,并判断 [long, lat] 对是否存在于任何这些 [多边形地理围栏数组中].
这在 MongoDB 中可行吗?我的问题有效吗?
Please Note: I am novice to MongoDB as well as Geospatial Data hence
forgive if the question contains wrong terminologies.
几天后我回到我的问题,因为我找到了答案。
解决方案发布在 here by Jacob Ribnik。
因此将其实施到我的问题中,如下所示:
db.Poly_Geofence_collection.find(
{
"location": {
$geoIntersects: {
$geometry: {
type: "Point",
coordinates: [1,1]
}
}
}
});
我的 Poly_Geofence_collection
collection 看起来像:
{
"_id": ObjectId("SomeRandom12ByteObjectId"),
"location" : {
"type" : "Polygon",
"name" : "Location Name",
"coordinates" : [
[
[0, 0], [1, 2], [1, 1], [2, 1], [0, 0]
]
]
}
}
根据我目前对 MongoDB 的理解,我们通过传递一个 [long, lat] 对数组来搜索我们的集合,以检查该文档的 [long, lat] 对是否存在于坐标 [[ [], [], [] ]]
.
我,即
db.SomeCollection.find({
"location":{
$geoWithin: {
$geometry: {
type: "Polygon",
coordinates: [
[[1, 2], [1, 3], [1, 4]],
[[2, 5], [2, 6], [2, 7]]
] }
}
}
})
我正在寻找的是,我需要将 [long, lat] 对提供给包含固定多边形地理围栏数组的文档,并判断 [long, lat] 对是否存在于任何这些 [多边形地理围栏数组中].
这在 MongoDB 中可行吗?我的问题有效吗?
Please Note: I am novice to MongoDB as well as Geospatial Data hence forgive if the question contains wrong terminologies.
几天后我回到我的问题,因为我找到了答案。
解决方案发布在 here by Jacob Ribnik。
因此将其实施到我的问题中,如下所示:
db.Poly_Geofence_collection.find(
{
"location": {
$geoIntersects: {
$geometry: {
type: "Point",
coordinates: [1,1]
}
}
}
});
我的 Poly_Geofence_collection
collection 看起来像:
{
"_id": ObjectId("SomeRandom12ByteObjectId"),
"location" : {
"type" : "Polygon",
"name" : "Location Name",
"coordinates" : [
[
[0, 0], [1, 2], [1, 1], [2, 1], [0, 0]
]
]
}
}