PostGIS之路——幾何物件編輯(二)

劍西樓發表於2017-03-22
1、ST_Reverse

返回幾何物件頂點順序相反的幾何物件。

geometry ST_Reverse(geometry g1);

示例SQL:

SELECT ST_AsText(the_geom) as line, ST_AsText(ST_Reverse(the_geom)) As reverseline
FROM
(SELECT ST_MakeLine(ST_MakePoint(1,2),
ST_MakePoint(1,10)) As the_geom) as foo;

2、ST_Rotate、ST_RotateX、ST_RotateY、ST_RotateZ

幾何物件旋轉(原點、X軸、Y軸、Z軸)。

geometry ST_Rotate(geometry geomA, float rotRadians);
geometry ST_Rotate(geometry geomA, float rotRadians, float x0, float y0);
geometry ST_Rotate(geometry geomA, float rotRadians, geometry pointOrigin);

geometry ST_RotateX(geometry geomA, float rotRadians);

geometry ST_RotateY(geometry geomA, float rotRadians);

geometry ST_RotateZ(geometry geomA, float rotRadians);

示例SQL:

SELECT ST_AsEWKT(ST_Rotate('LINESTRING (50 160, 50 50, 100 50)', pi()));

SELECT ST_AsEWKT(ST_RotateX(ST_GeomFromEWKT('LINESTRING(1 2 3, 1 1 1)'), pi()/2));

3、ST_Scale

按照一定比例調整幾何物件座標,即每個X、Y、Z乘以相應的大小。

geometry ST_Scale(geometry geomA, float XFactor, float YFactor, float ZFactor);
geometry ST_Scale(geometry geomA, float XFactor, float YFactor);

示例SQL:

SELECT ST_AsEWKT(ST_Scale(ST_GeomFromEWKT('LINESTRING(1 2 3, 1 1 1)'), 0.5, 0.75, 0.8));

4、ST_Segmentize

返回一個修改後的幾何物件,沒有分段長度超過的給定的距離。距離只在二維計算,

geometry ST_Segmentize(geometry geomA, float max_length);

示例SQL:

SELECT ST_AsText(ST_Segmentize(ST_GeomFromText('POLYGON((-29 28, -30 40, -29 28))'),10));

5、ST_SetPoint

將線段上給定位置的點替換為設定的點。(替換線上的點)

geometry ST_SetPoint(geometry linestring, integer zerobasedposition, geometry point);

示例SQL:

SELECT ST_AsText(ST_SetPoint('LINESTRING(-1 2,-1 3)', 0, 'POINT(-1 1)'));

6、ST_SetSRID

給幾何物件設定SRID。

geometry ST_SetSRID(geometry geom, integer srid);

示例SQL:

SELECT ST_Transform(ST_SetSRID(ST_Point(-123.365556, 48.428611),4326),3785) As spere_merc;

7、ST_SnapToGrid

將幾何物件頂點捕捉到網格。

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

示例SQL:

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

8、ST_Snap

根據輸入和參考幾何物件捕捉幾何物件。



geometry ST_Snap(geometry input, geometry reference, float tolerance);

示例SQL:





8、ST_Transform

將幾何物件轉化到指定空間參考。

geometry ST_Transform(geometry g1, integer srid);

示例SQL:

SELECT ST_AsText(ST_Transform(ST_GeomFromText('POLYGON((743238 2967416,743238 2967450,
743265 2967450,743265.625 2967416,743238 2967416))',2249),4326)) As wgs_geom;

9、ST_Translate

對幾何物件作偏移。

geometry ST_Translate(geometry g1, float deltax, float deltay);
geometry ST_Translate(geometry g1, float deltax, float deltay, float deltaz);

示例SQL:

SELECT ST_AsText(ST_Translate(ST_GeomFromText('POINT(-71.01 42.37)',4326),1,0)) As
wgs_transgeomtxt;

10、ST_TransScale

對2D幾何物件作偏移和縮放。

geometry ST_TransScale(geometry geomA, float deltaX, float deltaY, float XFactor, float YFactor);

示例SQL:

SELECT ST_AsEWKT(ST_TransScale(ST_GeomFromEWKT('LINESTRING(1 2 3, 1 1 1)'), 0.5, 1, 1, 2));

相關文章