turf-intersect
intersect
Takes two polygons and finds their intersection. If they share a border, returns the border; if they don't intersect, returns undefined.
Parameters
poly1
Feature<Polygon> the first polygonpoly2
Feature<Polygon> the second polygon
Examples
var poly1 = "type": "Feature" "properties": "fill": "#0f0" "geometry": "type": "Polygon" "coordinates": -122801742 4548565 -122801742 4560491 -122584762 4560491 -122584762 4548565 -122801742 4548565 var poly2 = "type": "Feature" "properties": "fill": "#00f" "geometry": "type": "Polygon" "coordinates": -122520217 45535693 -12264038 45553967 -122720031 45526554 -122669906 45507309 -122723464 45446643 -122532577 45408574 -122487258 45477466 -122520217 45535693 var polygons = "type": "FeatureCollection" "features": poly1 poly2; var intersection = turf; //=polygons //=intersection
Returns (Feature<Polygon> | undefined | Feature<MultiLineString>) if poly1
and poly2
overlap, returns a Polygon feature representing the area they overlap; if poly1
and poly2
do not overlap, returns undefined
; if poly1
and poly2
share a border, a MultiLineString of the locations where their borders are shared
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-intersect
Or install the Turf module that includes it as a function:
$ npm install turf