All Products
Search
Document Center

PolarDB:ST_AddZ

Last Updated:Mar 28, 2026

Adds z-axis values to a geometry object. If the geometry already has z-axis values, the function returns it unchanged.

Syntax

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

Parameters

ParameterDescription
g1The geometry object to update.
zvaluesAn array of z-axis values, one per point in the geometry. If the array has fewer elements than the geometry has points, the function pads the remaining points with 0.

Usage notes

  • If g1 already has z-axis values, no operation is performed.

  • For a 3DM geometry (a geometry with M coordinates but no Z), the function converts it to a ZM geometry by adding the specified z-axis values.

Examples

Point and PointM

Add a z-axis value to a 2D point:

SELECT ST_AsText(ST_AddZ(ST_MakePoint(116.345, 31.257), '{3.129}'::float8[]));

Output:

POINT Z (116.345 31.257 3.129)

Add a z-axis value to a point with an M coordinate (PointM → POINT ZM):

SELECT ST_AsText(ST_AddZ(ST_MakePointM(116.345, 31.257, 0.006), '{3.129}'::float8[]));

Output:

POINT ZM (116.345 31.257 3.129 0.006)

LineString and LineStringM

Add z-axis values to a 2D linestring:

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

Output:

LINESTRING Z (110.268550710707 19.912797729366 68.890150670893,110.26842843605 19.912673441389 69.183771011419,110.268391117929 19.912635081628 69.281459503807)

Add z-axis values to a linestring with M coordinates (LINESTRING M → LINESTRING ZM):

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

Output:

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)

Polygon and PolygonM

Add z-axis values to a 2D polygon:

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

Output:

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

Add z-axis values to a polygon with M coordinates (POLYGON M → POLYGON ZM):

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

Output:

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