Max*_*Max 5 geometry polygon geospatial node.js turfjs
我有两个多边形,它们的交叉点不可见且不可移动。我试图通过从第一个中删除第二个区域来找到它们之间的差异,然后再次找到交叉点 - 结果交叉点仍然存在并且具有公共区域。为什么会发生这种情况?如何去除两个多边形之间的交点并使它们的边界接触?
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???
}
Run Code Online (Sandbox Code Playgroud)
看来这只是精度问题:如果你检查一下面积intersection
if (intersection) {
console.log(turf.area(intersection));
}
Run Code Online (Sandbox Code Playgroud)
你会看到它的面积是 0.28925415367002694 平方米。
如果这是一个可行的解决方案,您可以使用阈值:
const threshold = 1; // configurable 1 square meter
if (intersection && turf.area(intersection) > threshold) {
console.log("there is intersection");
}
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助。
| 归档时间: |
|
| 查看次数: |
314 次 |
| 最近记录: |