ST_Dimension

ST_Dimension takes a geometry column and returns an integer column. The output column represents the dimensionality of the input geometry. Points and multipoints have a dimension of 0, lines 1, and polygons 2.

FunctionSyntax
Pythondimension(geometry)
SQLST_Dimension(geometry)
Scaladimension(geometry)

For more details, go to the GeoAnalytics Engine API reference for dimension.

This function implements the OpenGIS Simple Features Implementation Specification for SQL 1.2.1.

Examples

PythonPythonSQLScala
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from geoanalytics.sql import functions as ST, Linestring, MultiPoint, Point, Polygon

data = [
    ("point", "POINT (10 30)"),
    ("multipoint", "MULTIPOINT (0 0, 5 5, 0 5)"),
    ("linestring", "LINESTRING (15 15, 10 15, 12 2)"),
    ("polygon", "POLYGON ((20 30, 18 28, 22 35, 40 20))")
]

df = spark.createDataFrame(data, ["type", "wkt"])\
          .withColumn("geometry", ST.geom_from_text("wkt"))

df.select("type", ST.dimension("geometry").alias("dimension")).show()
Result
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
+----------+---------+
|      type|dimension|
+----------+---------+
|     point|        0|
|multipoint|        0|
|linestring|        1|
|   polygon|        2|
+----------+---------+

Version table

ReleaseNotes

1.0.0

Python and SQL functions introduced

1.5.0

Scala function introduced

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.