ST_GeometryN

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.

FunctionSyntax
Pythongeometry_n(geometry, n)
SQLST_GeometryN(geometry, n)
ScalageometryN(geometry, n)

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

PythonPythonSQLScala
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
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
Use dark colors for code blocksCopy
1
2
3
4
5
6
+----------------------------------------------------------+
|geometry_n                                                |
+----------------------------------------------------------+
|{"rings":[[[50,130],[60,130],[60,140],[50,140],[50,130]]]}|
|NULL                                                      |
+----------------------------------------------------------+

Version table

ReleaseNotes

1.0.0-beta

Python, SQL, and Scala functions introduced

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.