ST_QuantizeCoordinates

更新时间:
复制 MD 格式

Returns a geometry object with coordinate values 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 process.
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.

Description

ST_QuantizeCoordinates sets all non-significant digits in each coordinate value to 0. The resulting values round to the original coordinates of the geometry object, but with improved compressibility. If the geometry column uses a compressible storage type, you can compress the data to reduce disk usage.

Note the following behavior:

  • Memory size is unaffected. ST_QuantizeCoordinates does not change the in-memory size of geometry objects.

  • Default precision fallback. If you omit a precision parameter, the function uses the x coordinate precision (precX) as the default for that coordinate.

  • Negative values target digits left of the decimal point. A negative parameter value causes the function to preserve significant digits to the left of the decimal point. For example, setting precX to -2 rounds the x coordinate to the nearest 100.

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

  • May produce invalid geometry. If the specified number of significant digits is lower than the intrinsic precision of the geometry object, the function may return an invalid geometry object.

Examples

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

Output:

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