## Name

ST_SnapToGrid — 将输入几何体的所有点捕捉到规则网格。

## Synopsis

`geometry ST_SnapToGrid(`geometry geomA, float originX, float originY, float sizeX, float sizeY`)`;

`geometry ST_SnapToGrid(`geometry geomA, float sizeX, float sizeY`)`;

`geometry ST_SnapToGrid(`geometry geomA, float size`)`;

`geometry ST_SnapToGrid(`geometry geomA, geometry pointOrigin, float sizeX, float sizeY, float sizeZ, float sizeM`)`;

## 描述

 返回的几何图形可能会失去其简单性（请参阅ST_IsSimple）。
 在版本 1.1.0 之前，此函数始终返回 2d 几何图形。从 1.1.0 开始，返回的几何图形将具有与输入几何图形相同的维度，但更高的维度值保持不变。使用带有第二个几何参数的版本来定义所有网格尺寸。

## 示例

```--Snap your geometries to a precision grid of 10^-3
UPDATE mytable
SET geom = ST_SnapToGrid(geom, 0.001);

SELECT ST_AsText(ST_SnapToGrid(
ST_GeomFromText('LINESTRING(1.1115678 2.123, 4.111111 3.2374897, 4.11112 3.23748667)'),
0.001)
);
st_astext
-------------------------------------
LINESTRING(1.112 2.123,4.111 3.237)
--Snap a 4d geometry
SELECT ST_AsEWKT(ST_SnapToGrid(
ST_GeomFromEWKT('LINESTRING(-1.1115678 2.123 2.3456 1.11111,
4.111111 3.2374897 3.1234 1.1111, -1.11111112 2.123 2.3456 1.1111112)'),
ST_GeomFromEWKT('POINT(1.12 2.22 3.2 4.4444)'),
0.1, 0.1, 0.1, 0.01) );
st_asewkt
------------------------------------------------------------------------------
LINESTRING(-1.08 2.12 2.3 1.1144,4.12 3.22 3.1 1.1144,-1.08 2.12 2.3 1.1144)

--With a 4d geometry - the ST_SnapToGrid(geom,size) only touches x and y coords but keeps m and z the same
SELECT ST_AsEWKT(ST_SnapToGrid(ST_GeomFromEWKT('LINESTRING(-1.1115678 2.123 3 2.3456,
4.111111 3.2374897 3.1234 1.1111)'),
0.01)      );
st_asewkt
---------------------------------------------------------
LINESTRING(-1.11 2.12 3 2.3456,4.11 3.24 3.1234 1.1111)

```