ST_GeometryN takes a geometry column and a numeric column or value (n) and returns a geometry column.
The output column contains the nth single-part geometry from a multipart geometry. When n=0
, the first
single-part geometry is returned. If the nth geometry doesn't exist, null
is returned.
Function | Syntax |
---|---|
Python | geometry |
SQL | ST |
Scala | geometry |
For more details, go to the GeoAnalytics for Microsoft Fabric API reference for geometry_n.
This function implements the OpenGIS Simple Features Implementation Specification SQL 1.2.1.
Examples
from geoanalytics_fabric.sql import functions as ST, Polygon
data = [
(Polygon([[[40,120],[90,120],[90,150],[40,150],[40,120]],[[50,130],[60,130],[60,140],[50,140],[50,130]]]),),
(Polygon([[[20,0],[30,20],[40,0],[20,0]]]),)
]
df = spark.createDataFrame(data, ["polygon"])
df.select(ST.geometry_n("polygon", 1).alias("geometry_n")).show(truncate=False)
Result
+----------------------------------------------------------+
|geometry_n |
+----------------------------------------------------------+
|{"rings":[[[50,130],[60,130],[60,140],[50,140],[50,130]]]}|
|NULL |
+----------------------------------------------------------+
Version table
Release | Notes |
---|---|
1.0.0-beta | Python, SQL, and Scala functions introduced |