名前

ST_Affine — ジオメトリに3次元アフィン変換を適用します。

概要

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

説明

3次元アフィン変換をジオメトリに適用して移動、回転、拡大縮小を一度に行います。

一つ目の形式では、次のように関数を呼んでいます。

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

これは次のような変換行列を表現しています。

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

次のようにも表現できます。

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次元アフィン変換をジオメトリに適用します。次のように関数を呼んでいます。

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

これは次のような変換行列を表現しています。

/  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  /

頂点は次のように変換されます。

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

このメソッドは上述の3次元メソッドの特異ケースです。

Enhanced: 2.0.0 多面体サーフェス対応、三角対応、TIN対応が導入されました。

Availability: 1.1.2 AffineからST_Affineに名称変更しました。

[注記]

1.3.4より前では、曲線を含むジオメトリで使用すると、この関数はクラッシュします。これは1.3.4以上で訂正されています。

This function supports Polyhedral surfaces.

This function supports Triangles and Triangulated Irregular Network Surfaces (TIN).

This function supports 3d and will not drop the z-index.

This method supports Circular Strings and Curves

-- 3次元ラインストリングをZ軸で180度回転させます。
-- ST_RotateZ()を冗長にしたものです。
 SELECT ST_AsEWKT(ST_Affine(the_geom,  cos(pi()), -sin(pi()), 0,  sin(pi()), cos(pi()), 0,  0, 0, 1,  0, 0, 0)) As using_affine,
         ST_AsEWKT(ST_Rotate(the_geom, pi())) As using_rotate
        FROM (SELECT ST_GeomFromEWKT('LINESTRING(1 2 3, 1 4 3)') As the_geom) As foo;
        using_affine         |        using_rotate
-----------------------------+-----------------------------
 LINESTRING(-1 -2 3,-1 -4 3) | LINESTRING(-1 -2 3,-1 -4 3)
(1 row)

-- 3次元ラインストリングをX軸とZ軸で180度回転させます。
SELECT ST_AsEWKT(ST_Affine(the_geom, cos(pi()), -sin(pi()), 0, sin(pi()), cos(pi()), -sin(pi()), 0, sin(pi()), cos(pi()), 0, 0, 0))
        FROM (SELECT ST_GeomFromEWKT('LINESTRING(1 2 3, 1 4 3)') As the_geom) As foo;
           st_asewkt
-------------------------------
 LINESTRING(-1 -2 -3,-1 -4 -3)
(1 row)
                

関連情報

ST_Rotate, ST_Scale, ST_Translate, ST_TransScale