• 金仓数据库 KingbaseGIS 使用手册(6.15. 仿射变换函数)


    6.15. 仿射变换函数

    6.15.1. ST_Affine

    ST_Affine — 对一个几何对象在一个步骤中进行3d仿射变换,比如转换、旋转、放大等操作 。

    用法

    geometry ST_Affine(geometry geomA, float a, float b, float c, float d, floate, 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, floatxoff, float yoff);

    描述

    对一个几何对象在一个步骤中进行3d仿射变换,比如转换、旋转、缩放等操作

    使用形式 1: 函数调用

    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: 对几何对象进行2d仿射变换.下面的函数调用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

    上述的方法的3D方法的在2D维度中的特殊情况

    提示

    2.0.0 版本支持Polyhedral Surface类型、 Triangle类型、 TIN类型.

    可用版本: 1.1.2. 从1.2.2版本开始,仿射变换函数Affine改名为ST_Affine

    注意

    1.3.4版本前,该函数如果包含CURVE类型对象会crash掉, 1.3.4+版本均已修复

    • 该函数支持 Polyhedral Surface类型几何对象.

    • 该函数支持 Triangles 和 Triangulated Irregular Network Surfaces (TIN)类型.

    • 这个函数支持3D对象, 并且不会删除z坐标(译者注: 3D对象会有3个坐标, x,y,z) .

    • 该函数支持CircularString和Curve几何类型对象

    样例

    Rotate a 3d line 180 degrees about the z axis.

    ST_Rotate();               注意 this is long-hand for doing
    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)
    
    
    --Rotate a 3d line 180 degrees in both the x and z axis
    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

    6.15.2. ST_Rotate

    ST_Rotate — 返回一个几何对象以某个点为中心点,逆时针旋转指定弧度后的对象。

    用法

    geometry ST_Rotate(geometry geomA, float rotRadians);
    geometry ST_Rotate(geometry geomA, float rotRadians, float x0, float y0);
    geometry ST_Rotate(geometry geomA, float rotRadians, geometry pointOrigin);

    描述

    返回一个几何对象以原点为中心点,逆时针旋转指定弧度后的对象. 旋转的中心点可以指定为Point几何对象的格式,或者x,y坐标的格式,如果旋转中心点没有指定,默认是按照POINT(0,0)即原点为中心点。

    • 这个函数支持3D对象,并且不会删除z坐标

    • 该函数支持CircularString和Curve几何类型对象

    • 该函数支持 Polyhedral Surface类型几何对象.

    • 该函数支持 Triangles 和 Triangulated Irregular Network Surfaces (TIN)类型.

    样例

    --Rotate 180 degrees
       SELECT ST_AsEWKT(ST_Rotate('LINESTRING(50 160, 50 50, 100 50)', pi()));
    
       st_asewkt
    ----------------------------------------------------------------------------------------------------
    LINESTRING(-50.00000000000002 -160,-50.00000000000001 -49.99999999999999,-100 -49.999999999999986)

    (1 行记录)

    --Rotate 30 degrees counter-clockwise at x=50, y=160 SELECT ST_AsEWKT(ST_Rotate('LINESTRING(50 160, 50 50, 100 50)', pi()/6, 50, 160));

    st_asewkt

    LINESTRING(50 160,104.99999999999999 64.73720558371174,148.30127018922192 89.73720558371173)

    (1 行记录)

    --Rotate 60 degrees clockwise from centroid SELECT ST_AsEWKT(ST_Rotate(geom, -pi()/3, ST_Centroid(geom))) FROM (SELECT 'LINESTRING(50 160, 50 50, 100 50)'::geometry AS geom) AS foo;

    st_asewkt

    LINESTRING(116.42245883568916 130.67207346706593,21.15966441940092 75.67207346706593,46.15966441940093 32.370803277844)

    (1 行记录)

    参考

    ST_Affine , ST_RotateX , ST_RotateY , ST_RotateZ

    6.15.3. ST_RotateX

    ST_RotateX — 将一个几何对象绕X轴旋转指定弧度

    用法

    geometry ST_RotateX(geometry geomA, float rotRadians);

    描述

    将一个几何对象绕X轴旋转指定弧度.

    样例

    --Rotate a line 90 degrees along x-axis
    SELECT ST_AsEWKT(ST_RotateX(ST_GeomFromEWKT('LINESTRING(1 2 3, 1 1 1)'),pi()/2));
    
    st_asewkt
    ---------------------------
    LINESTRING(1 -3 2,1 -1 1)

    参考

    ST_Affine , ST_RotateY , ST_RotateZ

    6.15.4. ST_RotateY

    ST_RotateY —将一个几何对象绕Y轴旋转指定弧度

    用法

    geometry ST_RotateY(geometry geomA, float rotRadians);

    描述

    将一个几何对象绕Y轴旋转指定弧度。

    样例

    --Rotate a line 90 degrees along y-axis
    SELECT ST_AsEWKT(ST_RotateY(ST_GeomFromEWKT('LINESTRING(1 2 3, 1 1 1)'),pi()/2));
    
    st_asewkt
    ---------------------------
    LINESTRING(3 2 -1,1 1 -1)

    参考

    ST_Affine , ST_RotateX , ST_RotateZ

    6.15.5. ST_RotateZ

    ST_RotateZ —将一个几何对象绕Z轴旋转指定弧度

    用法

    geometry ST_RotateZ(geometry geomA, float rotRadians);

    描述

    Rotate a geometry geomA - rotRadians about the Z axis.

    样例

    --Rotate a line 90 degrees along z-axis
    SELECT ST_AsEWKT(ST_RotateZ(ST_GeomFromEWKT('LINESTRING(1 2 3, 1 1 1)'),pi()/2));
    
    st_asewkt
    ---------------------------
    LINESTRING(-2 1 3,-1 1 1)
    
    --Rotate a curved circle around z-axis
    SELECT ST_AsEWKT(ST_RotateZ(the_geom, pi()/2))
    FROM (SELECT ST_LineToCurve(ST_Buffer(ST_GeomFromText('POINT(234 567)'), 3)) As the_geom)
    As foo;
    
    st_asewkt
    -----------------------------------------------------------------------------------------------------
    CURVEPOLYGON(CIRCULARSTRING(-567 237,-564.87867965644 236.12132034356,-564 234,-569.12132034356 231.87867965644,-567 237))

    参考

    ST_Affine , ST_RotateX , ST_RotateY

    6.15.6. ST_Scale

    ST_Scale — 通过将输入对象的坐标乘以一个系数来对对象进行缩放(缩小和放大),例如ST_Scale(geom, Xfactor,Yfactor, Zfactor).

    用法

    geometry ST_Scale(geometry geomA, float XFactor, float YFactor, float ZFactor); geometry ST_Scale(geometry geomA, float XFactor, float YFactor);

    描述

    通过将输入对象的坐标乘以一个系数来对对象进行缩放(缩小和放大),例如ST_Scale(geom, Xfactor,Yfactor, Zfactor).

    注意

    ST_Scale(geomA, XFactor, YFactor, ZFactor)是函数ST_Affine(geomA, XFactor, 0, 0, 0, YFactor, 0, 0, 0, ZFactor, 0, 0, 0)的简化版

    样例

    --Version 1: scale X, Y, Z
    SELECT ST_AsEWKT(ST_Scale(ST_GeomFromEWKT('LINESTRING(1 2 3, 1 1 1)'),0.5, 0.75, 0.8));
    
    st_asewkt
    --------------------------------------
    LINESTRING(0.5 1.5 2.4,0.5 0.75 0.8)
    
    --Version 2: Scale X Y
    SELECT ST_AsEWKT(ST_Scale(ST_GeomFromEWKT('LINESTRING(1 2 3, 1 1 1)'),0.5, 0.75));
    
    st_asewkt
    ----------------------------------
    LINESTRING(0.5 1.5 3,0.5 0.75 1)

    参考

    ST_Affine , ST_TransScale

    6.15.7. ST_Translate

    ST_Translate — 把一个几何对象根据指定的输入偏移地址,移动到一个新的位置。例如ST_Translate(geom,X,Y) 或者ST_Translate(geom, X, Y,Z).

    用法

    geometry ST_Translate(geometry g1, float deltax, float deltay);
    geometry ST_Translate(geometry g1, float deltax, float deltay, float deltaz);

    描述

    把一个几何对象根据指定的输入偏移地址,移动到一个新的位置。移动便宜地址为delta x,delta y,delta z单位,单位的定义由SRID值决定

    • 这个函数支持3D对象,并且不会删除z坐标

    • 该函数支持CircularString和Curve几何类型对象

    样例

    Move a point 1 degree longitude
    SELECT ST_AsText(ST_Translate(ST_GeomFromText('POINT(-71.01 42.37)',4326),1,0)) As wgs_transgeomtxt;
    
    wgs_transgeomtxt
    ---------------------
    POINT(-70.01 42.37)
    
    Move a linestring 1 degree longitude and 1/2 degree latitude
    SELECT ST_AsText(ST_Translate(ST_GeomFromText('LINESTRING(-71.01 42.37,-71.11 42.38)',4326) ,1,0.5)) As wgs_transgeomtxt;
    
    wgs_transgeomtxt
    ---------------------------------------
    LINESTRING(-70.01 42.87,-70.11 42.88)
    
    Move a 3d point
    SELECT ST_AsEWKT(ST_Translate(CAST('POINT(0 0 0)' As geometry), 5, 12,3));
    
    st_asewkt
    ---------
    POINT(5 12 3)
    
    Move a curve and a point
    SELECT ST_AsText(ST_Translate(ST_Collect('CURVEPOLYGON(CIRCULARSTRING(4 3,3.12 0.878,1 0,-1.121 5.1213,6 7, 8 9,4 3))','POINT(1 3)'),1,2));
    
    st_astext
    -----------------------------------------------------------------------------------------------------
    GEOMETRYCOLLECTION(CURVEPOLYGON(CIRCULARSTRING(5 5,4.12 2.878,2 2,-0.121 7.1213,7 9,9 11,5 5)),POINT(2 5))

    参考

    ST_Affine , ST_AsText , ST_GeomFromText

    6.15.8. ST_TransScale

    ST_TransScale — 根据输入的缩放倍数,对一个几何对象进行缩放,缩放因子为Xfactor和Yfactor参数,该函数只支持2D对象

    用法

    geometry ST_TransScale(geometry geomA, float deltaX, float deltaY, float XFactor, float YFactor);

    描述

    根据输入的缩放倍数,对一个几何对象进行缩放,缩放因子为Xfactor和Yfactor参数,该函数只支持2D对象

    注意

    ST_TransScale(geomA, deltaX, deltaY, XFactor,YFactor)是函数ST_Affine(geomA, XFactor, 0, 0, 0, YFactor, 0, 0, 0,1, deltaX*XFactor, deltaY*YFactor,0)的简化版

    样例

    SELECT ST_AsEWKT(ST_TransScale(ST_GeomFromEWKT('LINESTRING(1 2 3, 1 1 1)'), 0.5, 1, 1, 2));
    
    st_asewkt
    -----------------------------
    LINESTRING(1.5 6 3,1.5 4 1)
    
    --Buffer a point to get an approximation of a circle, convert to curve and then translate 1,2 and scale it 3,4
    SELECT ST_AsText(ST_Transscale(ST_LineToCurve(ST_Buffer('POINT(234 567)', 3)),1,2,3,4));
    
    st_astext
    -----------------------------------------------------------------------------------------------------
    CURVEPOLYGON(CIRCULARSTRING(714 2276,711.363961030679 2267.51471862576,705 2264,698.636038969321 2284.48528137424,714 2276))

    参考

    ST_Affine , ST_Translate

  • 相关阅读:
    【Vue】vue2使用pdfjs预览pdf文件,在线预览方式一,pdfjs文件包打开新窗口预览pdf文件
    ATA-8061射频功率放大器在心室导管式扩压电式测力传感器中的应用
    sqli-labs/Less-57
    Hugging Face 分词器新增聊天模板属性
    Shell编程总结
    分布式文件存储系统minio、大文件分片传输
    systemverilog 中的 `define ---带参数的宏函数--macro function
    .kann勒索病毒解密方法|勒索病毒解决|勒索病毒恢复|数据库修复
    2022年学Java开发的10个理由
    举个栗子!Tableau 技巧(259):文本表中省市县数据的灵活逐级下钻「方法一」
  • 原文地址:https://blog.csdn.net/arthemis_14/article/details/126303154