首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用MultiPolygon和turf.js过滤出坐标

用MultiPolygon和turf.js过滤出坐标
EN

Stack Overflow用户
提问于 2022-11-10 15:27:17
回答 1查看 29关注 0票数 0

我有两个位置集合(features1和features2),并且希望从这些位置删除所有的重叠。当两个集合中的位置都是多边形类型时,非常简单,我可以使用turf.difference( feature1,feature2)并用结果覆盖feature1,从而消除任何覆盖。虽然在重叠分割多边形的情况下,此操作可以返回MultiPolygon,这是正确的,但这使此过程复杂化,因为feature1可能有来自feature2的多个重叠,而turf.difference只适用于第一个。因此,我想要一种不用turf.difference就能过滤出坐标的方法。在有些情况下,feature1与7种不同的feature2重叠,而第一种方法工作得很好,但后来事情就变得糟糕了。

我尝试使用另一个草皮函数,即turf.coordEach,它遍历所有的坐标,然后检查feature2中是否存在坐标,如果是,从feature1多多边形数组中删除坐标。该函数当前如下所示:

代码语言:javascript
复制
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()
  }

我猜想剪接失败的地方,但我不知道如何做,在那里双/三/四重嵌套数组使我困惑。会很感激你的帮助!

EN

回答 1

Stack Overflow用户

发布于 2022-11-15 08:32:21

回答我自己,以防别人在不久的将来遇到同样的问题。这是一个已知的问题,将在下一个版本中合并。这是公共关系的链接

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74391448

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档