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 Engine API reference for geometry_n.

This function implements the OpenGIS Simple Features Implementation Specification SQL 1.2.1.

Examples

PythonPythonSQLScala
1
2
3
4
5
6
7
8
9
10
11

from geoanalytics.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
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

Python and SQL functions introduced

1.5.0

Scala function introduced

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

You can no longer sign into this site. Go to your ArcGIS portal or the ArcGIS Location Platform dashboard to perform management tasks.

Your ArcGIS portal

Create, manage, and access API keys and OAuth 2.0 developer credentials, hosted layers, and data services.

Your ArcGIS Location Platform dashboard

Manage billing, monitor service usage, and access additional resources.

Learn more about these changes in the What's new in Esri Developers June 2024 blog post.

Close