Name

ST_Affine — Applies a 2D or 3D affine transformacion to a geometry. That means a rotation, scale and translate in a single step.

Synopsis

geometry ST_Affine(bytea Geometry, double a, double b, double c, double d, double e, double f, double g, double h, double i, double Tx, double Ty, double Tz);

geometry ST_Affine(bytea Geometry, double a, double b, double d, double e, double Tx, double Ty);

Alias

Affine

Description

Applies a 2D or 3D affine transformacion to a geometry. That means a rotation, scale and translate in a single step.

In the following table transformation matrices and equations to transform the vertices are shown.

3D Transformation matrix

Equations to transform the vertices

2D Transformation matrix

Equations to transform the vertices

Coordinate Dimensions
2D3DM
Spatial Standards Support
OGC SFS for SQL. 1.1 (1999)OGC SFS for SQL. 1.1.0 (2005)OGC SFS for SQL. 1.2.0 (2006)SQL-MM Part 3
----

Examples

--Rotates 90º along Z axis
SELECT ST_AsEWKT(ST_Affine(geomA, cos(rotRadians), -sin(rotRadians), 0, sin(rotRadians), cos(rotRadians), 0, 0, 0, 1, 0, 0, 0)) 
 FROM (SELECT ST_GeomFromEWKT('LINESTRING (10 10 15, 5 2 10)') as geomA, pi()/2 as rotRadians) as foo; 

--Result
LINESTRING (-10 10 15, -2 5 10)

Related functions

ST_RotateX, ST_RotateY, ST_RotateZ, ST_Scale, ST_Translate