Fork me on GitHub

ST_Dimension

Signature

INT ST_Dimension(GEOMETRY geom);

Description

Return the dimension of geom:

  • 0 for POINTs
  • 1 for LINESTRINGs
  • 2 for POLYGONs
  • The largest dimension of the components of a GEOMETRYCOLLECTION

Examples

SELECT ST_Dimension('MULTIPOINT((4 4), (1 1), (1 0), (0 3)))');
-- Answer: 0

SELECT ST_Dimension('LINESTRING(2 1, 1 3, 5 2)');
-- Answer: 1

SELECT ST_Dimension('MULTIPOLYGON(((0 2, 3 2, 3 6, 0 6, 0 2)),
                                  ((5 0, 7 0, 7 1, 5 1, 5 0)))');
-- Answer: 2

SELECT ST_Dimension('GEOMETRYCOLLECTION(
                       MULTIPOINT((4 4), (1 1), (1 0), (0 3)),
                       LINESTRING(2 6, 6 2),
                       POLYGON((1 2, 4 2, 4 6, 1 6, 1 2)))');
-- Answer: 2
See also