Skip to content

KBE3D / KBCore / turf / difference

函数: difference()

difference(features: FeatureCollection<Polygon | MultiPolygon>): Feature<Polygon | MultiPolygon, GeoJsonProperties> | null

Function

Finds the difference between multiple polygons by clipping the subsequent polygon from the first.

参数

features

FeatureCollection<Polygon | MultiPolygon>

input Polygon features

返回

Feature<Polygon | MultiPolygon, GeoJsonProperties> | null

a Polygon or MultiPolygon feature showing the area of polygon1 excluding the area of polygon2 (if empty returns null)

示例

ts
var polygon1 = turf.polygon([[
  [128, -26],
  [141, -26],
  [141, -21],
  [128, -21],
  [128, -26]
]], {
  "fill": "#F00",
  "fill-opacity": 0.1
});
var polygon2 = turf.polygon([[
  [126, -28],
  [140, -28],
  [140, -20],
  [126, -20],
  [126, -28]
]], {
  "fill": "#00F",
  "fill-opacity": 0.1
});

var difference = turf.difference(turf.featureCollection([polygon1, polygon2]));

//addToMap
var addToMap = [polygon1, polygon2, difference];

KBE3D @3.0.0 Copyright © 2024-present KBE3D