@turf/difference
TypeScript icon, indicating that this package has built-in type declarations

7.2.0 • Public • Published

@turf/difference

difference

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

Parameters

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(turf.featureCollection([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 single module individually:

$ npm install @turf/difference

Or install the all-encompassing @turf/turf module that includes all modules as functions:

$ npm install @turf/turf

/@turf/difference/

    Package Sidebar

    Install

    npm i @turf/difference

    Weekly Downloads

    730,120

    Version

    7.2.0

    License

    MIT

    Unpacked Size

    14.7 kB

    Total Files

    9

    Last publish

    Collaborators

    • rowanwins
    • tmcw
    • morganherlocker
    • tcql
    • mdfedderly
    • twelch
    • jamesmilneruk
    • morgan.herlocker
    • smallsaucepan