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.
Function | Syntax |
---|---|
Python | length(geometry) |
SQL | ST |
Scala | length(geometry) |
For more details, go to the GeoAnalytics for Microsoft Fabric API reference for length.
This function implements the OpenGIS Simple Features Implementation Specification for SQL 1.2.1
Examples
from geoanalytics_fabric.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()
+------+
|length|
+------+
| 0.0|
| 0.0|
|18.153|
|56.682|
+------+
Version table
Release | Notes |
---|---|
1.0.0-beta | Python, SQL, and Scala functions introduced |