st_nrings
Applies to: Databricks Runtime 18.1 and above
Preview
This feature is in Public Preview.
Returns the total number of rings of the input polygon or multipolygon, including exterior and interior rings. For a multipolygon, returns the sum of all rings across all polygons.
For the corresponding Databricks SQL function, see st_nrings function.
Syntax
Python
from pyspark.databricks.sql import functions as dbf
dbf.st_nrings(col=<col>)
Parameters
Examples
Empty 2D polygon GEOMETRY:
Python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('POLYGON EMPTY',)], ['wkt'])
df.select(dbf.st_nrings(dbf.st_geomfromtext('wkt')).alias('result')).collect()
Output
[Row(result=0)]
4D polygon GEOGRAPHY with two rings (one exterior, one interior):
Python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('POLYGON ZM ((0 0 111 -11,10 0 222 -22,0 10 333 -33,0 0 444 -44),(1 1 555 -55,4 1 666 -66,1 4 777 -77,1 1 888 -88))',)], ['wkt'])
df.select(dbf.st_nrings(dbf.st_geogfromtext('wkt')).alias('result')).collect()
Output
[Row(result=2)]
Empty 3DZ multipolygon GEOMETRY:
Python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('MULTIPOLYGON Z EMPTY',)], ['wkt'])
df.select(dbf.st_nrings(dbf.st_geomfromtext('wkt', 4326)).alias('result')).collect()
Output
[Row(result=0)]
Multipolygon GEOGRAPHY with four rings across two polygons:
Python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('MULTIPOLYGON (((0 0,10 0,10 10,0 10,0 0),(1 1,4 1,4 4,1 4,1 1),(5 5,6 5,6 6,5 6,5 5)),((20 20,30 20,30 30,20 30,20 20)))',)], ['wkt'])
df.select(dbf.st_nrings(dbf.st_geogfromtext('wkt')).alias('result')).collect()
Output
[Row(result=4)]