turf.transformRotate
What is turf.transformRotate?
turf.transformRotate rotates any GeoJSON Feature around a pivot by an angle in degrees. Clockwise rotations are positive; counter-clockwise are negative. The operation is geodesic — each vertex moves along its own small arc around the pivot.
turf.transformRotate(geojson, angle, options?) → Feature<Geometry>Options include:
pivot—Pointto rotate around (default: centroid of the feature)mutate—boolean(defaultfalse); whentrue, mutates the input in place
When would you use turf.transformRotate?
Use turf.transformRotate for any "spin the geometry" task — rotating an overlay to match a compass heading, generating multiple rotated footprints for a shadow study, or aligning a parcel template to a street angle. On MapLibre, it is handy for placing rotated building footprints or rotating a legend overlay.
In Node.js ETL, combine it with turf.transformScale and turf.transformTranslate to build full affine transformations of geodata, for instance when aligning digitised plans to real-world coordinates.
undefinedFAQs
Which direction is positive rotation?
Clockwise, in degrees from 0 to 360 (or negative for counter-clockwise). This matches compass bearings.
What is the default pivot?
The centroid of the input feature (turf.centroid). Pass an explicit Point via options.pivot to rotate around another location — a key corner of a building, a map anchor, or a user-specified pin.
How do I install just transformRotate?
npm install @turf/transform-rotate. It depends on @turf/centroid, @turf/rhumb-bearing, @turf/rhumb-destination, and @turf/meta.
Does the rotation preserve shape and size?
Yes. Being geodesic, it rotates every vertex by the same angle about the pivot. Because real spheres have curvature the "shape" of an extremely large feature will distort slightly — for most mapping inputs this is invisible.