ST_RotateX
What is ST_RotateX?
ST_RotateX is a PostGIS function that rotates a geometry about the X axis by the given angle in radians. It is a 3D transformation that changes Y and Z coordinates while leaving X unchanged.
ST_RotateX(geometry geomA, float rotRadians) → geometryEquivalent to ST_Affine(geom, 1, 0, 0, 0, cos(θ), -sin(θ), 0, sin(θ), cos(θ), 0, 0, 0).
When would you use ST_RotateX?
Use ST_RotateX for 3D modelling tasks — tilting a building model forward, orienting a sensor frustum, or flipping a 3D mesh about a horizontal axis. It is most useful in CAD, BIM, and 3D city-model pipelines, not typical 2D mapping.
1-- Tilt a 3D roof polygon 30° about the X axis:
2SELECT ST_RotateX(geom, radians(30)) FROM roof_polygons;FAQs
What's the difference between ST_RotateX, ST_RotateY, and ST_RotateZ?
Each rotates about the named Cartesian axis. ST_RotateX spins geometry in the YZ plane (Y and Z change), ST_RotateY spins in the XZ plane, ST_RotateZ spins in the XY plane. ST_RotateZ is identical to plain ST_Rotate for 2D geometries.
What angle units does it use?
Radians, with a right-hand-rule sign convention (positive is counter-clockwise when looking back along the +X axis). Use radians(deg) if you prefer degrees.
Does ST_RotateX work on 2D geometries?
Technically yes — but since 2D geometries have Z = 0, rotating about the X axis only adds a Z component scaled by Y. The result is a 3D geometry, so plan your schema if you call this on 2D input.
Can I rotate about an arbitrary axis?
Not with a single function. Compose ST_Translate, ST_RotateX/Y/Z, and another ST_Translate to implement rotation about an arbitrary line — translate so the axis passes through origin, rotate, then translate back.