Skip to main content

h3_kringdistances

Returns all H3 cell IDs (represented as long integers or strings) within grid distance k from the origin H3 cell ID, along with their distance from the origin H3 cell ID. More precisely, the result is an array of structs, where each struct contains an H3 cell id (represented as a long integer or string) and its distance from the origin H3 cell ID. The type for the H3 cell IDs in the output is the same as the type of the input H3 cell ID (first argument of the expression). Supports Spark Connect.

For the corresponding Databricks SQL function, see h3_kringdistances function.

Syntax

Python
from pyspark.databricks.sql import functions as dbf

dbf.h3_kringdistances(col1=<col1>, col2=<col2>)

Parameters

Parameter

Type

Description

col1

pyspark.sql.Column or str

An H3 cell ID, represented as a Column or string.

col2

pyspark.sql.Column, str, or int

The maximum grid distance from the H3 cell ID (first argument).

Examples

Python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([(599686042433355775, '85283473fffffff', 1,),],['h3l', 'h3s', 'res'])
df.select(dbf.h3_kringdistances('h3l', 'res').alias('result')).collect()
Output
[Row(result=[Row(cellid=599686042433355775, distance=0),     Row(cellid=599686030622195711, distance=1), Row(cellid=599686044580839423, distance=1),     Row(cellid=599686038138388479, distance=1), Row(cellid=599686043507097599, distance=1),     Row(cellid=599686015589810175, distance=1), Row(cellid=599686014516068351, distance=1)])]
Python
df.select(dbf.h3_kringdistances('h3s', 'res').alias('result')).collect()
Output
[Row(result=[Row(cellid='85283473fffffff', distance=0),     Row(cellid='85283447fffffff', distance=1), Row(cellid='8528347bfffffff', distance=1),     Row(cellid='85283463fffffff', distance=1), Row(cellid='85283477fffffff', distance=1),     Row(cellid='8528340ffffffff', distance=1), Row(cellid='8528340bfffffff', distance=1)])]