mirror of
https://github.com/Turfjs/turf.git
synced 2026-02-01 16:57:21 +00:00
- No longer have bench and test call prepare explicitly - bench.js, test.js, types.ts all use the local copy of the code, not the built copy - Fixed quite a few bench.js files that were just broken - Rework root package.json for build clarity - Change prepare scripts to build so that they don't run on publish Co-authored-by: Matt Fedderly <mfedderly@palantir.com> Co-authored-by: Rowan Winsemius <rowanwins@yahoo.com.au>
@turf/difference
difference
Finds the difference between two polygons by clipping the second polygon from the first.
Parameters
polygon1Feature<(Polygon | MultiPolygon)> input Polygon featurepolygon2Feature<(Polygon | MultiPolygon)> Polygon feature to difference from polygon1
Examples
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(polygon1, polygon2);
//addToMap
var addToMap = [polygon1, polygon2, difference];
Returns (Feature<(Polygon | MultiPolygon)> | null) a Polygon or MultiPolygon feature showing the area of polygon1 excluding the area of polygon2 (if empty returns null)
This module is part of the Turfjs project, an open source module collection dedicated to geographic algorithms. It is maintained in the Turfjs/turf repository, where you can create PRs and issues.
Installation
Install this module individually:
$ npm install @turf/difference
Or install the Turf module that includes it as a function:
$ npm install @turf/turf