This topic describes the ST_Affine function. This function applies a 3D affine transformation to a geometry object. After the transformation, you can perform operations, such as translation, rotation, and scaling, on the geometry object at the same time.
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 object that you want to specify. |
a | The parameter that is used to specify an affine transformation. |
b | The parameter that is used to specify an affine transformation. |
c | The parameter that is used to specify an affine transformation. |
d | The parameter that is used to specify an affine transformation. |
e | The parameter that is used to specify an affine transformation. |
f | The parameter that is used to specify an affine transformation. |
g | The parameter that is used to specify an affine transformation. |
h | The parameter that is used to specify an affine transformation. |
i | The parameter that is used to specify an affine transformation. |
xoff | The parameter that is used to specify an affine transformation. |
yoff | The parameter that is used to specify an affine transformation. |
zoff | The parameter that is used to specify an affine transformation. |
Description
- Method 1: If the expression of the ST_Affine function is ST_Affine(geom, a, b, c, d, e, f, g, h, i, xoff, yoff, zoff), the function represents the following transformation matrix:
/ a b c xoff \ | d e f yoff | | g h i zoff | \ 0 0 0 1 /
- The following expressions show how vertices of the geometry object are transformed.
All translation and scaling functions are represented by an affine transformation.
x' = a*x + b*y + c*z + xoff y' = d*x + e*y + f*z + yoff z' = g*x + h*y + i*z + zoff
- Method 2: If the expression of the ST_Affine function is ST_Affine(geom, a, b, d, e, xoff, yoff), the function represents 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 /
- The following expressions show how the vertices of the geometry object are transformed:
x' = a*x + b*y + xoff y' = d*x + e*y + yoff z' = z
This method is a subcase of the preceding 3D methods.
- This function supports circular strings, curves, polyhedral surfaces, triangles, triangulated irregular network (TIN) surfaces, and 3D objects.
Examples
The following examples show how to rotate a geometry object 180 degrees on the x-axis,
y-axis, and z-axis 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));
st_asewkt
-----------------
POINT(-1 -2 -3)
(1 row)