我一直在阅读mongo关于geospacial查询的文档,并且对于singl Polygon类型的东西工作得很好但是我遇到了MultiPolygon问题。我想要做的就是这个:
给出MultiPolygon概述排除区域:
{
"type" : "MultiPolygon",
"coordinates" : [
[
[
[
-117.873730659485,
33.6152089844919
],
[
-117.873065471649,
33.615048159758
],
[
-117.873044013977,
33.614690770386
],
[
-117.873666286469,
33.6146729008785
],
[
-117.873730659485,
33.6152089844919
]
]
]
]
}
我只是想传递一个Point
来查看它是否被排除在外。我已尝试$geoIntersects
只是为了确定它是否可以确定是否包含Point
,但这不起作用。最后,我想检查排除列表中是否包含 not ,但如果没有额外的$not
运算符,查询会更简单...这就是我一直在尝试的内容:
var geoPoint = {type: 'Point', coordinates: [-117.8731230, 33.6150696]};
db.myCollection.aggregate([
{$match: {'exclusionsPolygons': {$geoIntersects: {$geometry: geoPoint}}}}
]);
请注意,如果我使用GeoJSON
类型Polygon
执行相同的操作,那么它可以正常运行:
鉴于此单一多边形:
{
"type" : "Polygon",
"coordinates" : [
[
[
-117.8711744,
33.6129677
],
[
-117.8751744,
33.6129677
],
[
-117.874444839148,
33.6162171973226
],
[
-117.87287399259,
33.6172714730352
],
[
-117.871410434393,
33.6165209730032
],
[
-117.8711744,
33.6129677
]
]
]
}
此查询仅用于查找并返回其奇异多边形包含该点的项目:
var geoPoint = {type: 'Point', coordinates: [-117.8731230, 33.6150696]};
db.myCollection.aggregate([
{$match: {'singularPolygon': {$geoIntersects: {$geometry: geoPoint}}}}
]);