gpt4 book ai didi

node.js - 无法删除多边形之间的区域交叉点

转载 作者:行者123 更新时间:2023-12-03 12:13:01 25 4
gpt4 key购买 nike

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

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???
}

最佳答案

看来这只是精度问题:如果您检查 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");
}
希望这可以帮助。

关于node.js - 无法删除多边形之间的区域交叉点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62714487/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com