Name

ST_Scale — Scales a geometry by given factors.

Synopsis

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

Description

Scales the geometry to a new size by multiplying the ordinates with the corresponding factor parameters.

The version taking a geometry as the factor parameter allows passing a 2d, 3dm, 3dz or 4d point to set scaling factor for all supported dimensions. Missing dimensions in the factor point are equivalent to no scaling the corresponding dimension.

The three-geometry variant allows a "false origin" for the scaling to be passed in. This allows "scaling in place", for example using the centroid of the geometry as the false origin. Without a false origin, scaling takes place relative to the actual origin, so all coordinates are just multiplied by the scale factor.

[Note]

Prior to 1.3.4, this function crashes if used with geometries that contain CURVES. This is fixed in 1.3.4+

Availability: 1.1.0.

Enhanced: 2.0.0 support for Polyhedral surfaces, Triangles and TIN was introduced.

Enhanced: 2.2.0 support for scaling all dimension (factor parameter) was introduced.

Enhanced: 2.5.0 support for scaling relative to a local origin (origin parameter) was introduced.

This function supports Polyhedral surfaces.

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

This method supports Circular Strings and Curves.

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

This function supports M coordinates.

To match the width and height of another geometry, divide its bounding-box dimensions by the corresponding input dimensions and use the resulting ratios as scale factors. The origin controls which point stays fixed during scaling.

Examples

This example scales X, Y, and Z values.

Code
SELECT ST_Scale('LINESTRING(1 2 3,1 1 1)', 0.5, 0.75, 0.8);
Output
LINESTRING(0.5 1.5 2.4,0.5 0.75 0.8)
Figure
Geometry figure for visual-st-scale-01

This example scales X and Y values.

Code
SELECT ST_Scale('LINESTRING(1 2 3,1 1 1)', 0.5, 0.75);
Output
LINESTRING(0.5 1.5 3,0.5 0.75 1)
Figure
Geometry figure for visual-st-scale-02

This example scales X, Y, Z, and M values.

Code
SELECT ST_Scale('LINESTRING(1 2 3 4,1 1 1 1)',
    ST_MakePoint(0.5, 0.75, 2, -1));
Output
LINESTRING(0.5 1.5 6 -4,0.5 0.75 2 -1)
Figure
Geometry figure for visual-st-scale-03

This example scales X and Y values using a false origin.

Code
SELECT ST_Scale('LINESTRING(1 1,2 2)', 'POINT(2 2)', 'POINT(1 1)'::geometry);
Output
LINESTRING(1 1,3 3)
Figure
Geometry figure for visual-st-scale-04

This example constructs an ellipse centered at (10, 20), with X radius 8, Y radius 4, and rotated 30 degrees counter-clockwise. Scaling and rotation use the center as their origin, so the ellipse keeps both its position and SRID.

Code
WITH params AS (
  SELECT
    ST_SetSRID(ST_Point(10, 20), 3857) AS center,
    8.0 AS x_radius,
    4.0 AS y_radius,
    radians(30) AS angle
)
SELECT ST_Rotate(
         ST_Scale(
           ST_Buffer(center, 1, 'quad_segs=32'),
           ST_MakePoint(x_radius, y_radius),
           center
         ),
         angle,
         center
       ) AS ellipse
FROM params;

Match a target width of 12 and height of 6 while keeping the lower-left corner of a 4-by-2 input fixed.

Code
SELECT ST_AsText(ST_Scale(
    ST_MakeEnvelope(10, 20, 14, 22),
    ST_Point(12.0 / 4, 6.0 / 2),
    ST_Point(10, 20)
));
Output
POLYGON((10 20,10 26,22 26,22 20,10 20))
Figure
Geometry figure for visual-st-scale-05