ST_QuantizeCoordinates

更新时间:
复制 MD 格式

Returns a geometry whose coordinate values are rounded to a specified number of significant digits.

Syntax

geometry ST_QuantizeCoordinates(geometry g, int precX, int precY, int precZ, int precM);

Parameters

ParameterDescription
gThe geometry object to operate on.
precXThe number of decimal places for x coordinate values.
precYThe number of decimal places for y coordinate values.
precZThe number of decimal places for z coordinate values.
precMThe number of decimal places for m coordinate values.

Usage notes

  • ST_QuantizeCoordinates sets all non-significant digits in a coordinate value to 0. The result rounds to the original coordinate value, but with higher compressibility. If the geometry column uses a compressible storage type, this reduces disk usage.

  • The function does not affect the size of geometry objects in memory.

  • The function does not affect existing topological relationships between geometry objects.

  • If no precision is specified for a coordinate dimension, the precision of the x coordinate is used.

  • Negative parameter values treat significant digits as positions to the left of the decimal point. For example, setting precX to -2 preserves the x coordinate to the nearest 100.

  • If the specified precision is lower than the intrinsic precision of the geometry object, the function may return an invalid geometry.

Examples

Round a point's coordinates to 4 significant digits:

SELECT ST_AsEWKT(ST_QuantizeCoordinates(ST_GeomFromText('POINT(1.123456 1.123456)'), 4));

Output:

            st_asewkt
------------------------------------------
 POINT(1.12345123291016 1.12345123291016)
(1 row)