What is @turf/unkink-polygon?
@turf/unkink-polygon is a module in the Turf.js library that is used to convert polygons with self-intersections (kinks) into simple polygons without self-intersections. This is useful for ensuring that polygon geometries are valid and can be used in various geospatial analyses.
What are @turf/unkink-polygon's main functionalities?
Unkink Polygon
This feature takes a polygon with self-intersections and returns a FeatureCollection of polygons without self-intersections. The code sample demonstrates how to use the `unkinkPolygon` function to process a polygon and output the resulting simple polygons.
const turf = require('@turf/turf');
const unkinkPolygon = require('@turf/unkink-polygon');
const polygon = turf.polygon([[
[-12.034835, 8.901183],
[-12.060413, 8.899826],
[-12.03638, 8.873199],
[-12.059383, 8.871418],
[-12.034835, 8.901183]
]]);
const result = unkinkPolygon(polygon);
console.log(result);
Other packages similar to @turf/unkink-polygon
jsts
JSTS (JavaScript Topology Suite) is a JavaScript library for processing and analyzing planar geometric objects. It provides a wide range of geometric operations, including the ability to handle self-intersecting polygons. Compared to @turf/unkink-polygon, JSTS offers more comprehensive geometric processing capabilities but may be more complex to use for simple tasks.
martinez-polygon-clipping
Martinez Polygon Clipping is a library for performing boolean operations on polygons, such as union, intersection, difference, and xor. It can handle self-intersecting polygons and is known for its performance. While it provides similar functionality to @turf/unkink-polygon in terms of handling complex polygons, it focuses more on boolean operations rather than just unkinking polygons.
@turf/unkink-polygon
unkinkPolygon
Takes a kinked polygon and returns a feature collection of polygons that have
no kinks.
Uses simplepolygon internally.
Parameters
Examples
const poly = turf.polygon([[[0, 0], [2, 0], [0, 2], [2, 2], [0, 0]]]);
const result = turf.unkinkPolygon(poly);
const addToMap = [poly, result]
Returns FeatureCollection<Polygon> Unkinked polygons
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/unkink-polygon
Or install the all-encompassing @turf/turf module that includes all modules as functions:
$ npm install @turf/turf