Functions / PostGIS / ST_RotateZ
PostGISAffine Transformations

ST_RotateZ

What is ST_RotateZ?

ST_RotateZ is a PostGIS function that rotates a geometry about the Z axis by the given angle in radians. Z coordinates are unchanged; X and Y are rotated in the XY plane. For 2D geometries, this is equivalent to ST_Rotate about the origin.

SQL
ST_RotateZ(geometry geomA, float rotRadians)geometry

Equivalent to ST_Affine(geom, cos(θ), -sin(θ), 0, sin(θ), cos(θ), 0, 0, 0, 1, 0, 0, 0).

When would you use ST_RotateZ?

Use ST_RotateZ to rotate geometries in the horizontal plane while explicitly preserving Z — rotating a 3D building footprint about its vertical axis, or expressing the intent "rotate about the vertical axis" in a 3D pipeline where you want the code to read unambiguously.

SQL
SELECT ST_RotateZ(geom, pi()/4) FROM buildings;

FAQs

Is ST_RotateZ the same as ST_Rotate?

For 2D geometries and rotations about the origin, yes — they produce identical output. ST_RotateZ has a clearer name in 3D contexts, and ST_Rotate has overloads that accept an origin point, which ST_RotateZ does not.

What axis convention does it use?

Counter-clockwise positive when looking down the +Z axis (i.e. from above onto the XY plane). This is the standard right-hand-rule convention.

Does it preserve Z coordinates?

Yes — every Z value is kept intact. Only X and Y are transformed. This makes it safe to call on 3D geometries without flattening them.

How do I rotate about a vertical axis other than the Z axis?

Translate so the desired vertical axis passes through the origin, call ST_RotateZ, then translate back. Use ST_Centroid(geom) or a chosen anchor point as the translation target.