3.0.12 • Published 8 years ago

turf-difference v3.0.12

Weekly downloads
9,959
License
MIT
Repository
github
Last release
8 years ago

turf-difference

build status

Turf difference module

turf.difference(poly1, poly2)

Finds the difference between two Polygon|polygons by clipping the second polygon from the first.

Parameters

parametertypedescription
poly1Feature.\<Polygon>input Polygon feaure
poly2Feature.\<Polygon>Polygon feature to difference from poly1

Example

var poly1 = {
  "type": "Feature",
  "properties": {
    "fill": "#0f0"
  },
  "geometry": {
    "type": "Polygon",
    "coordinates": [[
      [-46.738586, -23.596711],
      [-46.738586, -23.458207],
      [-46.560058, -23.458207],
      [-46.560058, -23.596711],
      [-46.738586, -23.596711]
    ]]
  }
};
var poly2 = {
  "type": "Feature",
  "properties": {
    "fill": "#00f"
  },
  "geometry": {
    "type": "Polygon",
    "coordinates": [[
      [-46.650009, -23.631314],
      [-46.650009, -23.5237],
      [-46.509246, -23.5237],
      [-46.509246, -23.631314],
      [-46.650009, -23.631314]
    ]]
  }
};

var differenced = turf.difference(poly1, poly2);
differenced.properties.fill = '#f00';

var polygons = {
  "type": "FeatureCollection",
  "features": [poly1, poly2]
};

//=polygons

//=differenced

Returns Feature.<Polygon>, a Polygon feature showing the area of poly1 excluding the area of poly2

Installation

Requires nodejs.

$ npm install turf-difference

Tests

$ npm test
3.0.12

8 years ago

3.0.10

8 years ago

3.0.5

8 years ago

3.0.1

8 years ago

2.0.0

9 years ago