查找给定的经度,纬度对是否位于MongoDB中的任何多边形中 [英] Find if given longitude, latitude pair lies in any of the polygon in MongoDB
问题描述
根据我目前对MongoDB的理解,我们通过传递[long,lat]对数组的数组来搜索集合,以检查该文档的[long,lat]对是否退出坐标[[ [], [], [] ]]
内.
As per my current understanding on MongoDB we search our collection by passing an array of [long, lat] pair arrays, to check if that document's [long, lat] pair exits inside the coordinates [[ [], [], [] ]]
.
i.e
db.SomeCollection.find({
"location":{
$geoWithin: {
$geometry: {
type: "Polygon",
coordinates: [
[[1, 2], [1, 3], [1, 4]],
[[2, 5], [2, 6], [2, 7]]
] }
}
}
})
我要寻找的是我需要将[long,lat]对输入到包含固定多边形Geofence数组的文档中,并得出结论[long,lat]对是否存在于那些[Polygonal Geofence数组]中.
What i am looking for is that i need to feed the [long, lat] pair to a document containing fixed Polygonal Geofence arrays and conclude if the [long, lat] pair exists inside any of those [Polygonal Geofence arrays].
在MongoDB中有可能吗?我的问题有效吗?
Is this possible in MongoDB? Is my question valid?
请注意:我是MongoDB以及地理空间数据的新手,因此 如果问题包含错误的术语,请原谅.
Please Note: I am novice to MongoDB as well as Geospatial Data hence forgive if the question contains wrong terminologies.
推荐答案
几天后,我回到我的问题中,找到了答案.
After few days I am returning to my question as i found the answer to it.
该解决方案发布在此处是Jacob Ribnik
因此,将其实施到我的问题中将如下所示:
hence implementing it to my problem it would be something like below:
db.Poly_Geofence_collection.find(
{
"location": {
$geoIntersects: {
$geometry: {
type: "Point",
coordinates: [1,1]
}
}
}
});
我的Poly_Geofence_collection
集合的外观如下:
{
"_id": ObjectId("SomeRandom12ByteObjectId"),
"location" : {
"type" : "Polygon",
"name" : "Location Name",
"coordinates" : [
[
[0, 0], [1, 2], [1, 1], [2, 1], [0, 0]
]
]
}
}
这篇关于查找给定的经度,纬度对是否位于MongoDB中的任何多边形中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!