cancel
Showing results for 
Search instead for 
Did you mean: 
missing-QuestionPost
cancel
Showing results for 
Search instead for 
Did you mean: 

h3 hex ID using Databricks Mosaic is not the same as h3.geo_to_h3

kll
New Contributor III

I am testing the Databricks Mosaic Spatial Grid Indexing method to obtain the `h3 hex` of a given lat, long.

# Get the latitude and longitude
latitude = 37.7716736
longitude = -122.4485852
 
# Get the resolution
resolution = 7
 
# Get the H3 hex ID
h3_hex_id = grid_longlatascellid(lit(latitude), lit(longitude), lit(resolution)).hex
 
# Print the H3 hex ID
print(h3_hex_id)
 
Column<'grid_longlatascellid(CAST(37.7716736 AS DOUBLE), CAST(-122.4485852 AS DOUBLE), 7)[hex]'> 

How do I see the actual hex id in the code above?

According the docs, the `h3 hex id` returned by `grid_longlatascellid` looks different from what is returned by `h3.geo_to_h3` method.

h3.geo_to_h3(float(latitude), float(longitude), 7)  
 
'872830829ffffff'
df = spark.createDataFrame([{'lon': 30., 'lat': 10.}])
df.select(grid_longlatascellid('lon', 'lat', lit(10))).show(1, False)
+----------------------------------+
|grid_longlatascellid(lon, lat, 10)|
+----------------------------------+
|                623385352048508927|

How do I obtain the `h3 hex id` using Databricks Mosaic library? I have the following imports and configurations:

import h3
from mosaic import enable_mosaic
enable_mosaic(spark, dbutils)
from mosaic import *
spark.conf.set("spark.databricks.labs.mosaic.index.system", "H3")

1 REPLY 1

Anonymous
Not applicable

Hi @Keval Shah​ 

Thank you for posting your question in our community! We are happy to assist you.

To help us provide you with the most accurate information, could you please take a moment to review the responses and select the one that best answers your question?

This will also help other community members who may have similar questions in the future. Thank you for your participation and let us know if you need any further assistance! 

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group