ST_Length

ST_Length takes a geometry column and returns a double column that represents the planar length of the input geometry. The length is calculated in the same units as the input geometry. For point and multipoint geometries the function will always return 0. For polygon geometries this function will return the length of the perimeter of the polygon.

FunctionSyntax
Pythonlength(geometry)
SQLST_Length(geometry)
Scalalength(geometry)

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

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
16
from geoanalytics.sql import functions as ST
from pyspark.sql import functions as F

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

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

df.select(F.round(ST.length("geometry"), 3).alias("length")).show()
Result
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
+------+
|length|
+------+
|   0.0|
|   0.0|
|18.153|
|56.682|
+------+

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.