This topic describes the ST_AddZ function. This function adds z-axis values to a geometry object.

Syntax

geometry  ST_AddZ(geometry    g1 , float[]  zvalues);

Parameters

Parameter Description
g1 The geometry object that you want to specify.
zvalues An array that consists of z-axis values.

Description

  • No operations are performed for a geometry object that has z-axis values.
  • This function converts a 3DM geometry into a ZM geometry by adding z-axis values.
  • Each element in an array of z-axis values corresponds to a point in the geometry. If the number of elements in the array of z-axis values is less than the number of points in the geometry, the function adds 0 as elements to the array.

Examples

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