【问题标题】:Cant remove area intersection between polygons无法删除多边形之间的区域交叉点
【发布时间】:2020-10-24 02:58:12
【问题描述】:

我有两个具有不可见和不可移动交叉点的多边形。我试图通过从第一个中删除第二个区域来找到它们之间的区别,然后再次找到交叉点 - 结果交叉点仍然存在并且具有公共区域。为什么会这样?如何去除两个多边形之间的交点并使其边界相接触?

const turf = require("@turf/turf");

const poly1 = [
    [
        [37.367249, 55.615589],
        [37.372462, 55.612478],
        [37.372463, 55.61248],
        [37.453365, 55.564205],
        [37.45336, 55.564206],
        [37.459431, 55.560583],
        [37.558005, 55.682037],
        [37.367249, 55.615589]
    ]
];
const poly2 = [
    [
        [37.336522, 55.603857],
        [37.360725, 55.57621],
        [37.408614, 55.591334],
        [37.371557, 55.613064],
        [37.336522, 55.603857]
    ]
];

const difference = turf.difference(turf.polygon(poly1), turf.polygon(poly2)); // removed poly2 from poly1, difference now is Feature<Polygon>
const intersection = turf.intersect(turf.polygon(difference.geometry.coordinates), turf.polygon(poly2));

if (intersection) { //intersection is geometry collection with polygons
    // why???
}

【问题讨论】:

    标签: node.js geometry geospatial polygon turfjs


    【解决方案1】:

    似乎只是精度问题:如果您检查intersection的区域

    if (intersection) {
      console.log(turf.area(intersection));
    }
    

    你会看到它是一个 0.28925415367002694 平方米的面积。

    如果是可行的解决方案,您可以使用阈值:

    const threshold = 1; // configurable 1 square meter
    
    if (intersection && turf.area(intersection) > threshold) {
      console.log("there is intersection");
    }
    

    希望这会有所帮助。

    【讨论】:

    • 这是一个可能的解决方案,但我正在寻找一种从另一个多边形中完全减去一个多边形的方法
    猜你喜欢
    • 2021-11-02
    • 1970-01-01
    • 2021-09-30
    • 2015-05-31
    • 2015-03-12
    • 1970-01-01
    • 2011-09-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多