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
| Parameter | Description |
|---|---|
geomA / geom | The geometry object to scale. |
xFactor | The scaling factor for the x coordinate. |
yFactor | The scaling factor for the y coordinate. |
zFactor | The factor for the values of the y coordinate. |
factor | The scaling factor, specified as a geometry point. |
origin | The origin of the scaling. |
Usage notes
The
factorparameter accepts a 2D, 3DM, 3DZ, or 4D point object, which sets the scaling factor for each supported dimension. IfxFactor,yFactor, orzFactoris 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
originis 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. Iforiginis 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;