Applies a 3D affine transformation to a geometry, combining translation, rotation, and scaling in a single operation.
Syntax
geometry ST_Affine(geometry geomA, float a, float b, float c, float d, float e, float f, float g, float h, float i, float xoff, float yoff, float zoff);
geometry ST_Affine(geometry geomA, float a, float b, float d, float e, float xoff, float yoff);Parameters
| Parameter | Description |
|---|---|
geomA | The geometry to transform. |
a, b, c, d, e, f, g, h, i | Affine transformation matrix coefficients. |
xoff, yoff, zoff | Translation offsets along the x-, y-, and z-axes. |
Description
Both overloads apply an affine transformation to all vertices in the geometry. Use the 13-parameter overload for 3D transformations, or the 7-parameter overload for 2D transformations.
13-parameter overload (3D)
The parameters map to the following transformation matrix:
/ a b c xoff \
| d e f yoff |
| g h i zoff |
\ 0 0 0 1 /Each vertex (x, y, z) is transformed as follows:
x' = a*x + b*y + c*z + xoff
y' = d*x + e*y + f*z + yoff
z' = g*x + h*y + i*z + zoff7-parameter overload (2D)
The parameters map to the following transformation matrix:
/ a b 0 xoff \ / a b xoff \
| d e 0 yoff | rsp. | d e yoff |
| 0 0 1 0 | \ 0 0 1 /
\ 0 0 0 1 /Each vertex is transformed as follows:
x' = a*x + b*y + xoff
y' = d*x + e*y + yoff
z' = zThis is a special case of the 3D overload, with the z coordinate unchanged.
Both overloads support CircularString, curves, PolyhedralSurface, Triangle, TIN (Triangulated Irregular Network), and 3D geometry.
Examples
Rotate POINT(1 2 3) 180 degrees simultaneously on the x-, y-, and z-axes:
SELECT ST_AsEWKT(ST_Affine(ST_GeomFromEWKT('POINT(1 2 3)'),
cos(pi()), -sin(pi()), 0, sin(pi()), cos(pi()), -sin(pi()), 0, sin(pi()), cos(pi()), 0, 0, 0));
st_asewkt
-----------------
POINT(-1 -2 -3)
(1 row)