What is @turf/kinks?
@turf/kinks is a module in the Turf.js library that is used to detect self-intersections (kinks) in GeoJSON polygons. This is useful for validating and cleaning up spatial data to ensure that polygons are well-formed and do not contain any self-intersecting lines.
What are @turf/kinks's main functionalities?
Detecting Kinks in Polygons
This feature allows you to detect self-intersections in a given GeoJSON polygon. The code sample creates a polygon with a self-intersection and uses the `turf.kinks` function to find and log the kinks.
const turf = require('@turf/turf');
const polygon = turf.polygon([[
[-12.034835, 8.901183],
[-12.060413, 8.899826],
[-12.03638, 8.873199],
[-12.034835, 8.901183]
]]);
const kinks = turf.kinks(polygon);
console.log(kinks);
Other packages similar to @turf/kinks
jsts
JSTS (JavaScript Topology Suite) is a JavaScript library of spatial predicates and functions for processing geometry. It provides more comprehensive geometry operations compared to @turf/kinks, including robust algorithms for intersection, union, and difference operations.
martinez-polygon-clipping
Martinez Polygon Clipping is a library for performing boolean operations on polygons, such as union, intersection, and difference. While it does not specifically focus on detecting kinks, it can be used to handle complex polygon operations and ensure valid geometries.
@turf/kinks
kinks
Takes a linestring, multi-linestring, multi-polygon, or polygon and returns points at all self-intersections.
Parameters
Examples
var poly = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [[
[-12.034835, 8.901183],
[-12.060413, 8.899826],
[-12.03638, 8.873199],
[-12.059383, 8.871418],
[-12.034835, 8.901183]
]]
}
};
var kinks = turf.kinks(poly);
var resultFeatures = kinks.features.concat(poly);
var result = {
"type": "FeatureCollection",
"features": resultFeatures
};
Returns FeatureCollection<Point> self-intersections
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/kinks
Or install the Turf module that includes it as a function:
$ npm install @turf/turf