ST_Scale

更新时间:
复制 MD 格式

Scales a geometry object by multiplying its coordinate values by the specified scaling factors.

Syntax

geometry ST_Scale(geometry geomA, float xFactor, float yFactor, float zFactor);
geometry ST_Scale(geometry geomA, float xFactor, float yFactor);
geometry ST_Scale(geometry geom, geometry factor);
geometry ST_Scale(geometry geom, geometry factor, geometry origin);

Parameters

ParameterDescription
geomA / geomThe geometry object to scale.
xFactorThe scaling factor for the x coordinate.
yFactorThe scaling factor for the y coordinate.
zFactorThe factor for the values of the y coordinate.
factorThe scaling factor, specified as a geometry point.
originThe origin of the scaling.

Usage notes

  • The factor parameter accepts a 2D, 3DM, 3DZ, or 4D point object, which sets the scaling factor for each supported dimension. If xFactor, yFactor, or zFactor is omitted, scaling is not applied to the corresponding dimension.

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

  • Geometry objects that contain M coordinates are supported.

  • If origin is specified, the function scales the geometry object in place relative to that origin — for example, using the centroid of the geometry object as the scaling origin. If origin is omitted, the function scales relative to the actual origin of the geometry object by multiplying each coordinate value by the corresponding factor.

Examples

Scale a LINESTRING using explicit x and y factors:

SELECT ST_AsText(ST_Scale('LINESTRING(2 1,1 1)'::geometry, 2, 2));
      st_astext
---------------------
 LINESTRING(4 2,2 2)
(1 row)

Scale a LINESTRING using a POINT geometry as the factor parameter:

SELECT ST_AsText(ST_Scale('LINESTRING(2 1,1 1)'::geometry, 'POINT(2 2)'::geometry));
      st_astext
---------------------
 LINESTRING(4 2,2 2)
(1 row)

Compare scaling with and without a custom origin. Both the unscaled geometry and two scaled versions are returned side by side:

SELECT
    ST_Scale(g, factor),
    ST_Scale(g, factor, 'POINT(2 1)'::geometry),
    g
FROM (
    SELECT
        'LINESTRING(2 1,1 1,1 2)'::geometry AS g,
        'POINT(3 3)'::geometry AS factor
) AS t;
1