Applies a 3D affine transformation to a geometry object in one step, combining translation, rotation, and scaling into a single operation.
Syntax
3D transformation (13 parameters):
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)2D transformation (7 parameters):
geometry ST_Affine(geometry geomA, float a, float b, float d, float e, float xoff, float yoff)Parameters
| Parameter | Description |
|---|---|
geomA | The geometry object to transform. |
a, b, c, d, e, f, g, h, i | Coefficients of the transformation matrix. |
xoff, yoff, zoff | Translation offsets along the x, y, and z axes. |
How it works
3D transformation
The 13-parameter form applies 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) of the geometry is transformed to (x', y', z') 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 + zoff2D transformation
The 7-parameter form is a subcase of the 3D form. It applies the following 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 /Vertices are transformed as:
x' = a*x + b*y + xoff
y' = d*x + e*y + yoff
z' = zThe z coordinate is unchanged.
Supported geometry types
ST_Affine supports the following geometry types:
Circular strings and curves
Polyhedral surfaces
Triangles and Triangulated Irregular Network (TIN) surfaces
3D objects
Examples
Rotate 180 degrees on all three axes simultaneously
The following example rotates a point 180 degrees on the x, y, and z axes at the same time.
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
)
);Result:
st_asewkt
-----------------
POINT(-1 -2 -3)
(1 row)