Appearance
ST_REDUCEPRECISION
Returns a GEOGRAPHY
object with reduced precision, achieved by rounding all coordinates to a specified grid size. Features smaller than the grid size may be removed or altered, but the output will be a valid GEOGRAPHY
object.
This function is generally more accurate near the equator and for smaller geographic scales. For large-scale projections, it may introduce significant distortions.
Syntax
sql
ST_REDUCEPRECISION(<input>, <gridsize>)
Arguments
<input>
: AGEOGRAPHY
object whose precision will be reduced.<gridsize>
: AFLOAT8
value representing the grid tolerance in meters.
Returns
Returns a GEOGRAPHY
object with reduced precision. All coordinates are rounded to the specified grid size, and features smaller than this tolerance may be removed or altered. The resulting object will be a valid GEOGRAPHY
.
Example
sql
SELECT
ROUND(ST_DISTANCE(p1, p2)::NUMERIC, 2) AS original_distance_m,
ROUND(ST_DISTANCE(ST_REDUCEPRECISION(p1, 20), ST_REDUCEPRECISION(p2, 20))::NUMERIC, 2) AS distance_after_20m_grid,
ROUND(ST_DISTANCE(ST_REDUCEPRECISION(p1, 100), ST_REDUCEPRECISION(p2, 100))::NUMERIC, 2) AS distance_after_100m_grid
FROM (
SELECT
ST_POINT(10.0001, 50.0001)::GEOGRAPHY AS p1,
ST_POINT(10.0003, 50.0003)::GEOGRAPHY AS p2
) AS points;
-- original_distance_m | distance_after_20m_grid | distance_after_100m_grid
-- ---------------------+-------------------------+--------------------------
-- 26.00 | 20.00 | 0.00