turf.booleanClockwise
What is turf.booleanClockwise?
turf.booleanClockwise inspects a linear ring and returns true if its vertices wind clockwise, false otherwise. It accepts a LineString Feature, a LineString geometry, or a raw coordinates array.
turf.booleanClockwise(line) → booleanWhen would you use turf.booleanClockwise?
Use turf.booleanClockwise when preparing polygons for systems that enforce winding order — the GeoJSON spec prefers counter-clockwise outer rings and clockwise holes, and some renderers (or ST_MakeValid equivalents) reject polygons that violate this. Check with booleanClockwise, then reverse with your own .reverse() or pass the polygon through turf.rewind to get a spec-compliant result.
It is also the quickest way to detect improperly digitised shapes during ETL: an unexpected clockwise outer ring often signals that data was imported from a CAD or proprietary format that uses the opposite convention.
1const ring = [[0, 0], [1, 1], [1, 0], [0, 0]];
2turf.booleanClockwise(ring); // trueFAQs
How do I install Turf.js to use this function?
Install npm install @turf/boolean-clockwise and import import { booleanClockwise } from '@turf/boolean-clockwise', or use turf.booleanClockwise via @turf/turf.
What does it return for a degenerate ring?
For a ring with zero enclosed area (all collinear points), the result is implementation-defined. Validate with turf.booleanValid if your data may contain degenerate geometry.
How do I fix a ring with the wrong winding order?
Reverse the coordinates array or call turf.rewind(feature, { reverse: true }) to flip. Pass the result back through booleanClockwise to confirm.
Does booleanClockwise work on whole polygons?
Not directly — it operates on one ring at a time. For a Polygon Feature, loop over geometry.coordinates (outer ring first, then holes) and call booleanClockwise on each.