本文介绍了如何在数组子字段中使用$ geoIntersects/2dsphere执行查找?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含文档的集合,每个文档都有一个包含多边形的字段数组.

I have a collection with documents and each has a field array with polygons.

我想测试我的多边形geoIntersect是否与那些多边形中的任何一个相交.如果有帮助,它们都是盒形的.

I want to test if my polygon geoIntersects any of those polygons. They are all box-shaped if it helps.

如果您要添加我要测试的数组中的多边形的可能性,我会添加奖励积分.我不想让它与自己相交...

I will add bounty points if you add in the possibility of having my polygon in that array I'm testing. I wouldn't want it intersect with itself...

城市:

{_id, buildings:[ {coo:{shape:"Polygon", coordinates:[ [0,0], [4,0], [4,5], [5,0],[0,0] ] }, {coo:{shape:"Polygon", coordinates:[ [0,0], [4,0], [4,5], [5,0],[0,0] ] } ] }}

想象一下我在数组中大约有100个左右的元素.我想确定,对于给定的形状,它是否可以与数组中的任何其他多边形或不与其他多边形相交(同样,不包括其自身在内).

Imagine I have around 100 or so elements in the array.I want to determine if, for a given shape, that might be included inside the array, if it intersects any or none of the other polygons (again, excluding itself it is in there).

推荐答案

尝试一下:

<collection>.findOne({ 'polygons': { $geoIntersects: { $geometry: { type: "Point", coordinates: [Longitude, Latitude] } } } }

这篇关于如何在数组子字段中使用$ geoIntersects/2dsphere执行查找?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 13:35