Categories:

Geospatial Functions

ST_DIMENSION

Given a value of type GEOGRAPHY, return the “dimension” of the value. The dimension of a GEOGRAPHY value is:

  • Point/MultiPoint: 0.

  • Line/MultiLine: 1.

  • Polygon/MultiPolygon: 2.

  • GeometryCollection: The dimension of the collection is equal to the maximum dimension of all the values inside the collection. For example if a GeometryCollection contains a point (dimension 0), and a line (dimension 1), then the dimension of the collection is 1.

  • Feature: The dimension of the Feature is the same as the dimension of the geospatial object in the Feature.

  • FeatureCollection: The rule is the same as for GeometryCollection.

The returned values (0, 1, 2) correspond to the common meaning of the word “dimension”: a polygon is a two-dimensional object, a line is a one-dimensional object, and a point is a zero-dimensional object.

Syntax

ST_DIMENSION( <geography_expression> )

Arguments

geography_expression

The argument must be an expression of type GEOGRAPHY.

Returns

A value of type INTEGER.

Usage Notes

  • If the function is passed NULL, the function returns NULL. If the function is passed a GeometryCollection containing 1 or more NULL elements and no non-NULL elements, the function returns 0.

    Note that some other systems return different values for NULL inputs.

Examples

The following example demonstrates the ST_DIMENSION function:

create table geospatial_table_02 (g GEOGRAPHY);
insert into geospatial_table_02 values
    ('POINT(-122.35 37.55)'),
    ('MULTIPOINT((-122.35 37.55), (0.00 -90.0))'),
    ('LINESTRING(-124.20 42.00, -120.01 41.99)'),
    ('LINESTRING(-124.20 42.00, -120.01 41.99, -122.5 42.01)'),
    ('MULTILINESTRING((-124.20 42.00, -120.01 41.99, -122.5 42.01), (10.0 0.0, 20.0 10.0, 30.0 0.0))'),
    ('POLYGON((-124.20 42.00, -120.01 41.99, -121.1 42.01, -124.20 42.00))'),
    ('MULTIPOLYGON(((-124.20 42.00, -120.01 41.99, -121.1 42.01, -124.20 42.0)),   ((20.0 20.0, 40.0 20.0, 40.0 40.0, 20.0 40.0, 20.0 20.0)))')
    ;    ;
select st_dimension(g) as dimension, st_aswkt(g)
    from geospatial_table_02;
+-----------+----------------------------------------------------------------------------------------------------+
| DIMENSION | ST_ASWKT(G)                                                                                        |
|-----------+----------------------------------------------------------------------------------------------------|
|         0 | POINT(-122.35 37.55)                                                                               |
|         0 | MULTIPOINT((-122.35 37.55),(0 -90))                                                                |
|         1 | LINESTRING(-124.2 42,-120.01 41.99)                                                                |
|         1 | LINESTRING(-124.2 42,-120.01 41.99,-122.5 42.01)                                                   |
|         1 | MULTILINESTRING((-124.2 42,-120.01 41.99,-122.5 42.01),(10 0,20 10,30 0))                          |
|         2 | POLYGON((-124.2 42,-120.01 41.99,-121.1 42.01,-124.2 42))                                          |
|         2 | MULTIPOLYGON(((-124.2 42,-120.01 41.99,-121.1 42.01,-124.2 42)),((20 20,40 20,40 40,20 40,20 20))) |
+-----------+----------------------------------------------------------------------------------------------------+