ST_Geometries takes a geometry column and returns an array column. Multipoint geometries return an array of points, multipart linestrings return an array of single-path linestrings, and multipart polygons return an array of single-ring polygons.
Function | Syntax |
---|---|
Python | geometries(geometry) |
SQL | ST |
Scala | geometries(geometry) |
For more details, go to the GeoAnalytics for Microsoft Fabric API reference for geometries.
Examples
from geoanalytics_fabric.sql import functions as ST
from pyspark.sql import functions as F
data = [
("MULTIPOINT (10 10, 20 20, 30 30)",),
("MULTILINESTRING ((0 0, 10 10), (10 10, 20 20))", ),
("MULTIPOLYGON (((0 0, 5 5, 10 0), (10 0, 15 5, 20 0)))", )
]
df = spark.createDataFrame(data, ["wkt"]).select(ST.geom_from_text("wkt").alias("geometry"))
df.withColumn("geometries", ST.geometries("geometry"))\
.select("geometries", F.size("geometries").alias("num_parts"))\
.show(truncate=False)
Result
+-----------------------------------------------------------------------------------+---------+
|geometries |num_parts|
+-----------------------------------------------------------------------------------+---------+
|[{"x":10,"y":10}, {"x":20,"y":20}, {"x":30,"y":30}] |3 |
|[{"paths":[[[0,0],[10,10]]]}, {"paths":[[[10,10],[20,20]]]}] |2 |
|[{"rings":[[[0,0],[5,5],[10,0],[0,0]]]}, {"rings":[[[10,0],[15,5],[20,0],[10,0]]]}]|2 |
+-----------------------------------------------------------------------------------+---------+
Version table
Release | Notes |
---|---|
1.0.0-beta | Python, SQL, and Scala functions introduced |