名称

ST_Affine — 对几何体应用 3D 仿射变换。

大纲

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);

描述

对几何体应用 3D 仿射变换,一步完成平移、旋转、缩放等操作。

版本1:调用

Code
ST_Affine(geom, a, b, c, d, e, f, g, h, i, xoff, yoff, zoff)

表示变换矩阵

Code
/ a b c xoff \
| d e f yoff |
| g h i zoff |
\ 0 0 0     1 /

并且顶点变换如下:

Code
x' = a*x + b*y + c*z + xoff
y' = d*x + e*y + f*z + yoff
z' = g*x + h*y + i*z + zoff

下面所有的平移/缩放函数都是通过这样的仿射变换来表达的。

版本 2:对几何体应用 2d 仿射变换。 调用

Code
ST_Affine(geom, a, b, d, e, xoff, yoff)

表示变换矩阵

Code
/ 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 /
\ 0 0 0    1 /

并且顶点变换如下:

Code
x' = a*x + b*y + xoff
y' = d*x + e*y + yoff
z' = z 

此方法是上述 3D 方法的子情况。

增强功能:引入了2.0.0 对多面体曲面、三角形和三角网的支持。

可用性:1.1.2。 1.2.2 中名称从 Affine 更改为 ST_Affine

[注意]

在 1.3.4 之前,此函数在与包含曲线的几何图形一起使用时崩溃。 此问题已在 1.3.4 及更高版本中得到纠正

该函数支持多面体曲面。

此函数支持三角形和不规则三角网面 (TIN)。

该函数支持 3d 并且不会丢失 z-index。

此方法支持圆形字符串和曲线。

示例

Rotate a 3D line 180 degrees about the z axis. Note this is long-hand for doing ST_Rotate();

Code
SELECT ST_Affine(geom, cos(pi()), -sin(pi()), 0, sin(pi()), cos(pi()), 0, 0, 0, 1, 0, 0, 0) As using_affine,
    ST_Rotate(geom, pi()) As using_rotate
   FROM (SELECT 'LINESTRING(1 2 3,1 4 3)'::geometry As geom) As foo;
栅格输出
using_affine         |        using_rotate
-----------------------------+-----------------------------
 LINESTRING(-1 -2 3,-1 -4 3) | LINESTRING(-1 -2 3,-1 -4 3)
(1 row)
Figure
Geometry figure for visual-st-affine-01

Rotate a 3D line 180 degrees in both the x and z axis.

Code
SELECT ST_Affine(geom, cos(pi()), -sin(pi()), 0, sin(pi()), cos(pi()), -sin(pi()), 0, sin(pi()), cos(pi()), 0, 0, 0)
    FROM (SELECT 'LINESTRING(1 2 3,1 4 3)'::geometry As geom) As foo;
栅格输出
LINESTRING(-1 -2 -3,-1 -4 -3)
Figure
Geometry figure for visual-st-affine-02