ST_NDims

更新时间:
复制 MD 格式

Returns the coordinate dimension of a geometry object: 2 for (X,Y), 3 for (X,Y,Z) or (X,Y,M), and 4 for (X,Y,Z,M). This function supports 3D objects and preserves z coordinates.

Syntax

integer ST_NDims(geometry g1);

Parameters

ParameterDescription
g1The geometry object to evaluate.

Examples

The following query shows the return value for each coordinate dimension in a single call:

SELECT
  ST_NDims('POINT(0 1)'::geometry)        AS d2point,
  ST_NDims('POINT(0 1 2)'::geometry)      AS d3point_z,
  ST_NDims('POINTM(0 1 2)'::geometry)     AS d3point_m,
  ST_NDims('POINT(0 1 2 3)'::geometry)    AS d4point;

Expected output:

 d2point | d3point_z | d3point_m | d4point
---------+-----------+-----------+---------
       2 |         3 |         3 |       4
(1 row)

Both 3DZ POINT(x y z) and 3DM POINTM(x y m) return 3, because both have three coordinate components.