# difference

Finds the difference between two polygons by clipping the second polygon from the first.
通过裁剪第二个多边形来找到两个多边形之间的差异。

参数

参数 类型 描述
polygon1 Feature <(Polygon|MultiPolygon)> input Polygon feature
polygon2 Feature <(Polygon|MultiPolygon)> Polygon feature to difference from polygon1

返回

(Feature <(Polygon|MultiPolygon)>|null) - 一个多边形或多边形集合,显示不包括多边形2的面积(如果为空则返回null)。

示例

var polygon1 = turf.polygon([[
  [128, -26], // 注意:polygon首尾坐标要一致
  [141, -26],
  [141, -21],
  [128, -21],
  [128, -26]
]], {
  "fill": "#F00",
  "fill-opacity": 0.1
});
var polygon2 = turf.polygon([[
  [126, -28], // 注意:polygon首尾坐标要一致
  [140, -28],
  [140, -20],
  [126, -20],
  [126, -28]
]], {
  "fill": "#00F",
  "fill-opacity": 0.1
});

var difference = turf.difference(polygon1, polygon2);
Last Updated: 7/3/2023, 9:59:14 PM