turf.rewind
What is turf.rewind?
turf.rewind enforces a specific winding order on GeoJSON LineString and Polygon geometries. By default it follows the RFC 7946 "right-hand rule": exterior rings are counter-clockwise, interior rings (holes) are clockwise.
turf.rewind(geojson, options?) → Feature<Geometry>Options include:
reverse—boolean(defaultfalse); whentrue, reverses the winding order (useful for older d3/topojson tooling)mutate—boolean(defaultfalse); whentrue, mutates the input in place
When would you use turf.rewind?
Use turf.rewind to normalise GeoJSON from mixed sources before rendering — Mapbox Vector Tiles and some rendering libraries flip rendering if rings are wound the wrong way. If you import geodata from older ArcGIS exports, Shapefile conversions, or PostGIS with the legacy orientation, a single pass through turf.rewind makes the collection safe for MapLibre.
In Node.js ETL, turf.rewind ensures that area calculations in PostGIS and other downstream systems return positive values and that symbology renders correctly. It is also useful right before calling turf.area if you are unsure about ring orientation.
undefinedFAQs
What is the right-hand rule?
RFC 7946 mandates that polygon exterior rings be counter-clockwise when viewed with north up, and interior rings (holes) be clockwise. This convention makes ring orientation unambiguous across tools.
Should I use reverse: true?
Only for d3-geo and topojson pipelines, which historically used the opposite convention. For MapLibre, Mapbox, PostGIS, and GeoJSON-compliant tools, the default is correct.
How do I install just rewind?
npm install @turf/rewind. It depends on @turf/boolean-clockwise, @turf/meta, and @turf/helpers.
Does it affect rendering on MapLibre?
Yes. Wrongly wound polygons can render with swapped fill/hole regions or disappear entirely when using fill-extrusion. Running turf.rewind fixes this consistently.