修改Geometry对象,增加Z坐标值。
语法
geometry ST_AddZ(geometry g1 , float[] zvalues);
参数
参数名称 | 描述 |
---|---|
g1 | 目标Geometry对象。 |
zvalues | Z坐标值数组。 |
描述
- 对于已经有Z值的Geometry对象,不做任何处理。
- 对于Geometry 3DM,增加Z坐标值后转为Geometry ZM对象。
- Z坐标数组的元素与Geometry包含的point一一对应,如果Z坐标元素个数小于points数量,则补0处理。
示例
--test point & pointm
SELECT ST_AsText(ST_addZ(ST_MakePoint(116.345, 31.257), '{3.129}'::float8[]));
st_astext
--------------------------------
POINT Z (116.345 31.257 3.129)
(1 row)
SELECT ST_AsText(ST_addZ(ST_MakePointM(116.345, 31.257, 0.006), '{3.129}'::float8[]));
st_astext
---------------------------------------
POINT ZM (116.345 31.257 3.129 0.006)
(1 row)
--test Linestring & LinestringM
SELECT ST_AsText(ST_addZ('LINESTRING(110.268550710707 19.912797729366,110.26842843605 19.912673441389,110.268391117929 19.912635081628)'::geometry, '{68.890150670893,69.183771011419,69.281459503807}'::float8[]));
st_astext
------------------------------------------------------------------------------------------------------------------------------------------------------------------
LINESTRING Z (110.268550710707 19.912797729366 68.890150670893,110.26842843605 19.912673441389 69.183771011419,110.268391117929 19.912635081628 69.281459503807)
(1 row)
SELECT ST_AsText(ST_addZ('LINESTRING M(110.268550710707 19.912797729366 0.0002,110.26842843605 19.912673441389 0.0008,110.268391117929 19.912635081628 0.0019)'::geometry, '{68.890150670893,69.183771011419,69.281459503807}'::float8[]));
st_astext
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
LINESTRING ZM (110.268550710707 19.912797729366 68.890150670893 0.0002,110.26842843605 19.912673441389 69.183771011419 0.0008,110.268391117929 19.912635081628 69.281459503807 0.0019)
(1 row)
--test polygon & polygonM
SELECT ST_AsText(ST_addZ('POLYGON((110.271437131412 19.916296059835,110.271458864211 19.916327373408,110.271472618849 19.916347078401,110.271494504499 19.916378842523,110.271525107774 19.916422797481,110.271559942483 19.916473012678,110.271588184066 19.916514021908,110.271608951741 19.916544548085,110.271637533517 19.916586350525,110.271662184676 19.916622302994,110.27168697878 19.916658943238,110.271690317318 19.916663834658,110.271437131412 19.916296059835))'::geometry, '{66.754327018745,66.76812185145,66.775424819085,66.788278159307,66.806879613697,66.82753102727,66.844599057935,66.857178772322,66.86311322099,66.869851471601,66.876122904615,66.8772665672,66.754327018745}'::float8[]));
st_astext
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
POLYGON Z ((110.271437131412 19.916296059835 66.754327018745,110.271458864211 19.916327373408 66.76812185145,110.271472618849 19.916347078401 66.775424819085,110.271494504499 19.916378842523 66.788278159307,110.271525107774 19.916422797481 66.806879613697,110.271559942483 19.916473012678 66.82753102727,110.271588184066 19.916514021908 66.844599057935,110.271608951741 19.916544548085 66.857178772322,110.271637533517 19.916586350525 66.86311322099,110.271662184676 19.916622302994 66.869851471601,110.27168697878 19.916658943238 66.876122904615,110.271690317318 19.916663834658 66.8772665672,110.271437131412 19.916296059835 66.754327018745))
(1 row)
SELECT ST_AsText(ST_addZ('POLYGON M((110.271437131412 19.916296059835 0.001,110.271458864211 19.916327373408 0.001,110.271472618849 19.916347078401 0.001,110.271494504499 19.916378842523 0.001,110.271525107774 19.916422797481 0.001,110.271559942483 19.916473012678 0.001,110.271588184066 19.916514021908 0.001,110.271608951741 19.916544548085 0.001,110.271637533517 19.916586350525 0.001,110.271662184676 19.916622302994 0.001,110.27168697878 19.916658943238 0.001,110.271690317318 19.916663834658 0.001,110.271437131412 19.916296059835 0.001))'::geometry, '{66.754327018745,66.76812185145,66.775424819085,66.788278159307,66.806879613697,66.82753102727,66.844599057935,66.857178772322,66.86311322099,66.869851471601,66.876122904615,66.8772665672,66.754327018745}'::float8[]));
st_astext
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
POLYGON ZM ((110.271437131412 19.916296059835 66.754327018745 0.001,110.271458864211 19.916327373408 66.76812185145 0.001,110.271472618849 19.916347078401 66.775424819085 0.001,110.271494504499 19.916378842523 66.788278159307 0.001,110.271525107774 19.916422797481 66.806879613697 0.001,110.271559942483 19.916473012678 66.82753102727 0.001,110.271588184066 19.916514021908 66.844599057935 0.001,110.271608951741 19.916544548085 66.857178772322 0.001,110.271637533517 19.916586350525 66.86311322099 0.001,110.271662184676 19.916622302994 66.869851471601 0.001,110.27168697878 19.916658943238 66.876122904615 0.001,110.271690317318 19.916663834658 66.8772665672 0.001,110.271437131412 19.916296059835 66.754327018745 0.001))
(1 row)