Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Applies to:
Databricks Runtime 18.1 and above
Important
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
from pyspark.databricks.sql import functions as dbf
dbf.st_nrings(col=<col>)
Parameters
| Parameter | Type | Description |
|---|---|---|
col |
pyspark.sql.Column or str |
A Geography or Geometry value. |
Examples
Empty 2D polygon GEOMETRY:
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()
[Row(result=0)]
4D polygon GEOGRAPHY with two rings (one exterior, one interior):
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()
[Row(result=2)]
Empty 3DZ multipolygon GEOMETRY:
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()
[Row(result=0)]
Multipolygon GEOGRAPHY with four rings across two polygons:
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()
[Row(result=4)]