turf-difference
difference
Finds the difference between two polygons by clipping the second polygon from the first.
Parameters
poly1
Feature<Polygon> input Polygon feaurepoly2
Feature<Polygon> Polygon feature to difference frompoly1
Examples
var poly1 = "type": "Feature" "properties": "fill": "#0f0" "geometry": "type": "Polygon" "coordinates": -46738586 -23596711 -46738586 -23458207 -46560058 -23458207 -46560058 -23596711 -46738586 -23596711 ;var poly2 = "type": "Feature" "properties": "fill": "#00f" "geometry": "type": "Polygon" "coordinates": -46650009 -23631314 -46650009 -235237 -46509246 -235237 -46509246 -23631314 -46650009 -23631314 ; var differenced = turf;differencedpropertiesfill = '#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
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