我有两个位置集合(features1和features2),并且希望从这些位置删除所有的重叠。当两个集合中的位置都是多边形类型时,非常简单,我可以使用turf.difference( feature1,feature2)并用结果覆盖feature1,从而消除任何覆盖。虽然在重叠分割多边形的情况下,此操作可以返回MultiPolygon,这是正确的,但这使此过程复杂化,因为feature1可能有来自feature2的多个重叠,而turf.difference只适用于第一个。因此,我想要一种不用turf.difference就能过滤出坐标的方法。在有些情况下,feature1与7种不同的feature2重叠,而第一种方法工作得很好,但后来事情就变得糟糕了。
我尝试使用另一个草皮函数,即turf.coordEach,它遍历所有的坐标,然后检查feature2中是否存在坐标,如果是,从feature1多多边形数组中删除坐标。该函数当前如下所示:
if (type === 'MultiPolygon') {
//Iterates through all the coords in the MultiPolygon
turf.coordEach(
feature1,
function (
currentCoord,
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) {
//Checks whether the current coordinates exists in feature2
if (turf.booleanPointInPolygon(currentCoord, feature2)) {
feature1.geometry.coordinates.splice(coordIndex, 1)
}
}
)
//Should update the Location in the DB after the coordinates are spliced.
return await Location.findOneAndUpdate(
{ _id: feature._id },
{ $set: feature as any },
{ upsert: true, new: true }
).exec()
}我猜想剪接失败的地方,但我不知道如何做,在那里双/三/四重嵌套数组使我困惑。会很感激你的帮助!
发布于 2022-11-15 08:32:21
回答我自己,以防别人在不久的将来遇到同样的问题。这是一个已知的问题,将在下一个版本中合并。这是公共关系的链接。
https://stackoverflow.com/questions/74391448
复制相似问题