st_geometryn
Preview
This feature is in Public Preview.
Returns the 1-based n-th element of the input multi geometry, or None if it doesn't exist.
For the corresponding Databricks SQL function, see st_geometryn function.
Syntax
Python
from pyspark.databricks.sql import functions as dbf
dbf.st_geometryn(col1=<col1>, col2=<col2>)
Parameters
Parameter | Type | Description |
|---|---|---|
|
| A Geometry value. |
|
| The 1-based index of the geometry to return. |
Examples
Python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('GEOMETRYCOLLECTION(POINT(4 5),LINESTRING(10 3,24 37,44 85))',)], ['wkt'])
df.select(dbf.st_asewkt(dbf.st_geometryn(dbf.st_geomfromtext('wkt', 4326), 2)).alias('result')).collect()
Output
[Row(result='SRID=4326;LINESTRING(10 3,24 37,44 85)')]
Python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('MULTIPOLYGON(EMPTY,((0 0,10 0,0 10,0 0),(1 1,9 1,1 9,1 1)))',)], ['wkt'])
df.select(dbf.st_asewkt(dbf.st_geometryn(dbf.st_geomfromtext('wkt'), 2)).alias('result')).collect()
Output
[Row(result='POLYGON((0 0,10 0,0 10,0 0),(1 1,9 1,1 9,1 1))')]
Python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('POINT(1 2)',)], ['wkt'])
df.select(dbf.st_asewkt(dbf.st_geometryn(dbf.st_geomfromtext('wkt'), 1)).alias('result')).collect()
Output
[Row(result='POINT(1 2)')]