Functions / PostGIS / ST_Rotate
PostGISAffine Transformations

ST_Rotate

What is ST_Rotate?

ST_Rotate is a PostGIS function that rotates a geometry counter-clockwise about a specified origin by an angle in radians. It is a thin, convenient wrapper over ST_Affine for the 2D case.

SQL
1ST_Rotate(geometry geomA, float rotRadians)geometry
2ST_Rotate(geometry geomA, float rotRadians, float x0, float y0)geometry
3ST_Rotate(geometry geomA, float rotRadians, geometry pointOrigin)geometry

With no origin, rotation is about the origin (0, 0). The other overloads rotate about an explicit point.

When would you use ST_Rotate?

Use ST_Rotate to orient features to a desired heading — rotating building footprints, aligning CAD output to a site plan, or spinning a symbol around an anchor point. Combined with ST_Translate, it handles any rigid-body transform.

SQL
1-- Rotate a footprint 90° clockwise about its centroid:
2SELECT ST_Rotate(geom, -pi()/2, ST_Centroid(geom)) FROM buildings WHERE id = 1;

FAQs

What angle units does ST_Rotate use?

Radians, counter-clockwise. To rotate by 45 degrees use radians(45) or pi()/4. Negative values rotate clockwise.

How do I rotate about the feature's own centre?

Pass the centroid as the origin: ST_Rotate(geom, theta, ST_Centroid(geom)). This keeps the feature visually in place while changing its orientation. For rotation-invariant bounding, consider ST_OrientedEnvelope instead.

Does ST_Rotate handle 3D geometries?

It rotates only in the XY plane, leaving Z untouched — effectively a rotation about the vertical axis. For rotations about the X or Y axis, use ST_RotateX or ST_RotateY.

Does rotation preserve areas and distances?

Yes, in Cartesian coordinate space. On geographic CRSs (EPSG:4326) rotation distorts real-world distances because a "degree" is not constant on the sphere — for rotation that preserves real distances, reproject to a local equal-distance projection first.