gpt4 book ai didi

javascript - 检测交叉点 Turf.js,第一个和最后一个位置不相等

转载 作者:行者123 更新时间:2023-12-05 05:17:15 25 4
gpt4 key购买 nike

利用Turf.js版本 3.0.12。下面的函数应该返回两个多边形之间的交点,如果它们不相交则返回 null。多边形确实相交。我尝试了几种不同的多边形并收到相同的错误:

“错误:第一个和最后一个位置不相等。”

我引用了这个例子:http://turfjs.org/docs#intersect

checkForIntersection = () => {
const boundingBox1 = turf.polygon([
[
[-11638128.151894445, 4697704.8042823635],
[-11538591.465504704, 4932847.347657125],
[-11773734.008879466, 5032384.034046866],
[-11873270.695269207, 4797241.490672104]
]
]);

const boundingBox2 = turf.polygon([
[
[-11545948.977350365, 4658759.839788924],
[-11483057.72508946, 5032936.709591224],
[-11857234.59489176, 5095827.961852129],
[-11920125.847152665, 4721651.092049829]
]
]);

const intersection = turf.intersect(boundingBox1, boundingBox2);

console.log("intersection: ", intersection);
};

感谢您的关注!

最佳答案

这是因为每个多边形的第一个和最后一个点或位置必须相同。所以 boundingBox1 和 boundingBox2 将是:

checkForIntersection = () => {
const boundingBox1 = turf.polygon([
[
[-11638128.151894445, 4697704.8042823635],
[-11538591.465504704, 4932847.347657125],
[-11773734.008879466, 5032384.034046866],
[-11873270.695269207, 4797241.490672104],
[-11638128.151894445, 4697704.8042823635],
]
]);

const boundingBox2 = turf.polygon([
[
[-11545948.977350365, 4658759.839788924],
[-11483057.72508946, 5032936.709591224],
[-11857234.59489176, 5095827.961852129],
[-11920125.847152665, 4721651.092049829],
[-11545948.977350365, 4658759.839788924],
]
]);

const intersection = turf.intersect(boundingBox1, boundingBox2);

console.log("intersection: ", intersection);
};

关于javascript - 检测交叉点 Turf.js,第一个和最后一个位置不相等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49521791/

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