st_length

Important

Support for GEOGRAPHY values is in Public Preview. Support for GEOMETRY values is generally available.

Returns the length of the input geometry or geography value.

For the corresponding Databricks SQL function, see st_length function.

Syntax

from pyspark.databricks.sql import functions as dbf

dbf.st_length(col=<col>)

Parameters

Parameter Type Description
col pyspark.sql.Column or str A Geography or Geometry value.

Notes

If the input is a geometry, Cartesian length is returned (in the unit of the input coordinates). If the input is a geography, length on the WGS84 spheroid is returned (expressed in meters).

Examples

from pyspark.databricks.sql import functions as dbf
from pyspark.sql.functions.builtin import round
df = spark.createDataFrame([('LINESTRING(10 34,44 57,30 24)',)], ['wkt'])
df.select(round(dbf.st_length(dbf.st_geomfromtext('wkt')), 3).alias('result')).collect()
[Row(result=76.896)]