ST_Rotate

更新时间:
复制 MD 格式

Rotates a geometry object counterclockwise by a specified angle in radians.

Syntax

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

Parameters

ParameterDescription
geomAThe geometry object to rotate.
rotRadiansThe rotation angle in radians.
x0The x coordinate of the rotation origin.
y0The y coordinate of the rotation origin.
pointOriginThe point that represents the rotation origin.

Usage notes

  • If no rotation origin is specified, the point (0 0) is used as the rotation origin.

  • Supported geometry types: circular strings, curves, polyhedral surfaces, triangles, triangulated irregular network (TIN) surfaces, and 3D geometries.

Examples

Rotate a LineString 180 degrees

SELECT ST_AsEWKT(ST_Rotate('LINESTRING (1 2,2 2)'::geometry, pi()));

Output:

        st_asewkt
-------------------------
 LINESTRING(-1 -2,-2 -2)
(1 row)
Execute the following statement to rotate a geometry object 180 degrees.

Rotate a LineString 30 degrees counterclockwise with (-1,-1) as the rotation origin

SELECT ST_AsEWKT(ST_Rotate('LINESTRING (1 2,2 2)'::geometry, pi()/6,-1,-1));

Output:

                           st_asewkt
---------------------------------------------------------------
 LINESTRING(-0.767949192431122 2.59807621135332,0.098076211353.
.316 3.09807621135332)
(1 row)
2

Rotate a LineString 90 degrees clockwise with the centroid as the rotation origin

SELECT ST_AsEWKT(ST_Rotate('LINESTRING (1 2,2 2)'::geometry, pi()/6,ST_Centroid('LINESTRING (1 2,2 2)'::geometry)));

Output:

                        st_asewkt
---------------------------------------------------------
 LINESTRING(1.06698729810778 1.75,1.93301270189222 2.25)
(1 row)
2