I am new to using Mosaic on Databricks. The task is to create a Heatmap with the counts within Hexagons of H3 resolution. Since the dataset is quite large I am opting for Mosaic. As the first step I am trying to create the hexagons covering the given area but the following code does not generate hexagons covering the full square as illustrated below:

from pyspark.sql.functions import *
from mosaic import enable_mosaic
enable_mosaic(spark, dbutils)

from pyspark import SparkContext
from pyspark.sql import functions as F
import mosaic as mos

from mosaic import st_point

lons = [-80., -80., -70., -70., -80.]
lats = [ 35.,  45.,  45.,  35.,  35.]

bounds_df = (
  .createDataFrame({"lon": lon, "lat": lat} for lon, lat in zip(lons, lats))
  .withColumn("point_geom", st_point("lon", "lat"))

from mosaic import st_makeline

bounds_df = (

from mosaic import st_makepolygon

bounds_df = bounds_df.select(st_makepolygon("bounding_ring").alias("bounds"))

hexs = (bounds_df
       .select(mos.mosaic_explode("bounds", lit(5)))


hexs "index_id" "h3"

enter image description here

Do you know why there are gaps in between the hexagons?

1 Answer 1


This function only displays a sample of the dataset hence you see the gaps between the hexagons.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.