# 计算交集(intersect)
> npm install @turf/intersect
Takes two polygons and finds their intersection. If they share a border, returns the border; if they don't intersect, returns undefined.
接收两个 type 为 polygon 的多边形找到他们的交集,如果共享边界则返回边界,如果不相交则返回 null
参数
参数 | 类型 | 描述 |
---|---|---|
poly1 | Feature<Polygon> | 面 1 |
poly2 | Feature<Polygon> | 面 2 |
返回
(Feature|null) - returns a feature representing the point(s) they share (in case of a Point or MultiPoint ), the borders they share (in case of a LineString or a MultiLineString ), the area they share (in case of Polygon or MultiPolygon ). If they do not share any point, returns null.
(Feature|null) - 返回表示它们共享的点(如果是点或多点)、共享的边界(如果是LineString或MultiLineString)、共享区域(如果是多边形或多多边形)的特征。
示例
var poly1 = turf.polygon([
[
[-122.801742, 45.48565],
[-122.801742, 45.60491],
[-122.584762, 45.60491],
[-122.584762, 45.48565],
[-122.801742, 45.48565],
],
]);
var poly2 = turf.polygon([
[
[-122.520217, 45.535693],
[-122.64038, 45.553967],
[-122.720031, 45.526554],
[-122.669906, 45.507309],
[-122.723464, 45.446643],
[-122.532577, 45.408574],
[-122.487258, 45.477466],
[-122.520217, 45.535693],
],
]);
var intersection = turf.intersect(poly1, poly2);
/*
{
type: "Feature",
geometry: {
type: "Polygon",
coordinates: [
[
[-122.584762, 45.545508794628965],
[-122.584762, 45.48565],
[-122.68902729894835, 45.48565],
[-122.669906, 45.507309],
[-122.720031, 45.526554],
[-122.64038, 45.553967],
[-122.584762, 45.545508794628965]
]
]
},
properties: {}
}
*/
基础用法
Copy
动态绘制
Copy