PostGISGeometry Accessors

ST_CoordDim

What is ST_CoordDim?

ST_CoordDim is a PostGIS function that returns the coordinate dimension of a geometry — 2 for XY, 3 for XYZ or XYM, and 4 for XYZM.

SQL
ST_CoordDim(geometry g)integer

This value reflects the storage format of the geometry, not its topological dimension. A 3D point and a 3D polygon both return 3.

When would you use ST_CoordDim?

Use ST_CoordDim to inspect or branch on the dimensionality of incoming data — for example to skip Z-aware processing on a mixed table or to validate an import pipeline that expects 3D data:

SQL
1SELECT id, geom
2FROM tracks
3WHERE ST_CoordDim(geom) = 3;

Also useful in quality-assurance queries (SELECT ST_CoordDim(geom), COUNT(*) FROM features GROUP BY 1) to confirm that all geometries share the expected dimensionality.

FAQs

How does ST_CoordDim differ from ST_NDims?

They return the same integer for all standard PostGIS geometries — ST_NDims is the PostGIS-native name and ST_CoordDim is the SQL/MM-standard alias. Either one works.

What is the difference from ST_Dimension?

ST_Dimension returns the topological dimension of the geometry (0 for point, 1 for line, 2 for polygon), independent of Z/M storage. ST_CoordDim returns the number of coordinate values per vertex (2, 3, or 4).

Can ST_CoordDim tell me whether my geometry has Z or M?

Not directly — both POINT Z and POINT M return 3. Use ST_Zmflag if you need to distinguish Z from M.

Is ST_CoordDim affected by SRID?

No. SRID is CRS metadata; dimensionality is a storage property independent of the CRS.