Skip to main content

ST_Dimension

Returns the topological dimension of a geometry.

Syntax​

ST_Dimension(geometry)

Parameters​

ParameterTypeDescription
geometryGeometryInput geometry

Returns​

TypeDescription
Int32Dimension value (0, 1, or 2)

Examples​

Dimension of Point​

SELECT ST_Dimension(ST_Point(0, 0));
-- Returns: 0

Dimension of LineString​

SELECT ST_Dimension(ST_GeomFromText('LINESTRING(0 0, 1 1)'));
-- Returns: 1

Dimension of Polygon​

SELECT ST_Dimension(ST_GeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))'));
-- Returns: 2

Group by Dimension​

SELECT ST_Dimension(geom) as dim, COUNT(*) as count
FROM features
GROUP BY ST_Dimension(geom);

Filter Areal Features​

SELECT * FROM mixed_features
WHERE ST_Dimension(geom) = 2;

Notes​

  • Dimension 0: Point geometries (no length, no area)
  • Dimension 1: Line geometries (have length, no area)
  • Dimension 2: Polygon geometries (have area)
  • For Multi* types, returns the dimension of the component type
  • For GeometryCollection, returns the maximum dimension of components

See Also​