Functions / Turf.js / turf.kinks
Turf.jsMisc

turf.kinks

What is turf.kinks?

turf.kinks walks a LineString, MultiLineString, Polygon, or MultiPolygon and returns a FeatureCollection<Point> containing every self-intersection. If the collection is empty, the geometry is simple (non-self-intersecting).

JavaScript
turf.kinks(featureIn) → FeatureCollection<Point>

When would you use turf.kinks?

Use turf.kinks to validate user-drawn shapes before saving them — a polygon with kinks is invalid per the GeoJSON simple-feature model and will misbehave in turf.area, turf.union, and turf.intersect. If your app lets users draw on a MapLibre canvas, run turf.kinks on submit and highlight any returned points as errors.

In Node.js ETL, turf.kinks is the cheapest way to identify corrupt imports from Shapefile or KML files. Clean with turf.unkinkPolygon once the self-intersections are located.

Code
undefined

FAQs

What counts as a kink?

Any self-intersection — the line or ring crossing itself. Shared endpoints between successive segments (the normal structure) are not kinks.

How do I install just kinks?

npm install @turf/kinks. It depends on @turf/helpers.

How do I fix the kinks?

For polygons, use turf.unkinkPolygon — it splits a self-intersecting polygon into multiple valid polygons at the intersection points. For lines, consider turf.lineSplit at the intersection points.

Does it report every intersection or just one per pair?

It reports every intersection point found — a single loop can produce two kink points (one on each crossing). Deduplicate geographically if your validation UI should show unique events only.