04_Visualisation_KeplerGL(Python)

Loading...

KeplerGL Visualisation Examples

Install Required Libs

Here we are specifying a version for keplerGL. At the time of building these examples, the latest version did not provide the ability to export map configurations from the UI of a map. These are used throughout this example to make the notebook rerunable with the best configs.

%pip install h3
Python interpreter will be restarted. Requirement already satisfied: h3 in /databricks/python3/lib/python3.8/site-packages (3.7.4) WARNING: You are using pip version 21.0.1; however, version 22.1.1 is available. You should consider upgrading via the '/local_disk0/.ephemeral_nfs/envs/pythonEnv-03256acc-d7e2-40b4-a17c-cef5679e70d7/bin/python -m pip install --upgrade pip' command. Python interpreter will be restarted.
%pip install keplergl==0.2.2
Python interpreter will be restarted. Collecting keplergl==0.2.2 Downloading keplergl-0.2.2.tar.gz (7.9 MB) Requirement already satisfied: ipywidgets<8,>=7.0.0 in /databricks/python3/lib/python3.8/site-packages (from keplergl==0.2.2) (7.6.3) Collecting traittypes>=0.2.1 Downloading traittypes-0.2.1-py2.py3-none-any.whl (8.6 kB) Requirement already satisfied: geopandas>=0.5.0 in /databricks/python3/lib/python3.8/site-packages (from keplergl==0.2.2) (0.10.2) Requirement already satisfied: pandas>=0.23.0 in /databricks/python3/lib/python3.8/site-packages (from keplergl==0.2.2) (1.2.4) Requirement already satisfied: Shapely>=1.6.4.post2 in /databricks/python3/lib/python3.8/site-packages (from keplergl==0.2.2) (1.8.2) Requirement already satisfied: fiona>=1.8 in /databricks/python3/lib/python3.8/site-packages (from geopandas>=0.5.0->keplergl==0.2.2) (1.8.21) Requirement already satisfied: pyproj>=2.2.0 in /databricks/python3/lib/python3.8/site-packages (from geopandas>=0.5.0->keplergl==0.2.2) (3.3.1) Requirement already satisfied: six>=1.7 in /databricks/python3/lib/python3.8/site-packages (from fiona>=1.8->geopandas>=0.5.0->keplergl==0.2.2) (1.15.0) Requirement already satisfied: setuptools in /usr/local/lib/python3.8/dist-packages (from fiona>=1.8->geopandas>=0.5.0->keplergl==0.2.2) (52.0.0) Requirement already satisfied: click>=4.0 in /databricks/python3/lib/python3.8/site-packages (from fiona>=1.8->geopandas>=0.5.0->keplergl==0.2.2) (8.1.3) Requirement already satisfied: certifi in /databricks/python3/lib/python3.8/site-packages (from fiona>=1.8->geopandas>=0.5.0->keplergl==0.2.2) (2020.12.5) Requirement already satisfied: munch in /databricks/python3/lib/python3.8/site-packages (from fiona>=1.8->geopandas>=0.5.0->keplergl==0.2.2) (2.5.0) Requirement already satisfied: cligj>=0.5 in /databricks/python3/lib/python3.8/site-packages (from fiona>=1.8->geopandas>=0.5.0->keplergl==0.2.2) (0.7.2) Requirement already satisfied: click-plugins>=1.0 in /databricks/python3/lib/python3.8/site-packages (from fiona>=1.8->geopandas>=0.5.0->keplergl==0.2.2) (1.1.1) Requirement already satisfied: attrs>=17 in /databricks/python3/lib/python3.8/site-packages (from fiona>=1.8->geopandas>=0.5.0->keplergl==0.2.2) (20.3.0) Requirement already satisfied: traitlets>=4.3.1 in /databricks/python3/lib/python3.8/site-packages (from ipywidgets<8,>=7.0.0->keplergl==0.2.2) (5.0.5) Requirement already satisfied: nbformat>=4.2.0 in /databricks/python3/lib/python3.8/site-packages (from ipywidgets<8,>=7.0.0->keplergl==0.2.2) (5.1.3) Requirement already satisfied: ipython>=4.0.0 in /databricks/python3/lib/python3.8/site-packages (from ipywidgets<8,>=7.0.0->keplergl==0.2.2) (7.22.0) Requirement already satisfied: widgetsnbextension~=3.5.0 in /databricks/python3/lib/python3.8/site-packages (from ipywidgets<8,>=7.0.0->keplergl==0.2.2) (3.5.1) Requirement already satisfied: ipykernel>=4.5.1 in /databricks/python3/lib/python3.8/site-packages (from ipywidgets<8,>=7.0.0->keplergl==0.2.2) (5.3.4) Requirement already satisfied: jupyterlab-widgets>=1.0.0 in /databricks/python3/lib/python3.8/site-packages (from ipywidgets<8,>=7.0.0->keplergl==0.2.2) (1.0.0) Requirement already satisfied: tornado>=4.2 in /databricks/python3/lib/python3.8/site-packages (from ipykernel>=4.5.1->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (6.1) Requirement already satisfied: jupyter-client in /databricks/python3/lib/python3.8/site-packages (from ipykernel>=4.5.1->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (6.1.12) Requirement already satisfied: backcall in /databricks/python3/lib/python3.8/site-packages (from ipython>=4.0.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (0.2.0) Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in /databricks/python3/lib/python3.8/site-packages (from ipython>=4.0.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (3.0.17) Requirement already satisfied: pygments in /databricks/python3/lib/python3.8/site-packages (from ipython>=4.0.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (2.8.1) Requirement already satisfied: pexpect>4.3 in /databricks/python3/lib/python3.8/site-packages (from ipython>=4.0.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (4.8.0) Requirement already satisfied: decorator in /databricks/python3/lib/python3.8/site-packages (from ipython>=4.0.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (5.0.6) Requirement already satisfied: jedi>=0.16 in /databricks/python3/lib/python3.8/site-packages (from ipython>=4.0.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (0.17.2) Requirement already satisfied: pickleshare in /databricks/python3/lib/python3.8/site-packages (from ipython>=4.0.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (0.7.5) Requirement already satisfied: parso<0.8.0,>=0.7.0 in /databricks/python3/lib/python3.8/site-packages (from jedi>=0.16->ipython>=4.0.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (0.7.0) Requirement already satisfied: jupyter-core in /databricks/python3/lib/python3.8/site-packages (from nbformat>=4.2.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (4.7.1) Requirement already satisfied: ipython-genutils in /databricks/python3/lib/python3.8/site-packages (from nbformat>=4.2.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (0.2.0) Requirement already satisfied: jsonschema!=2.5.0,>=2.4 in /databricks/python3/lib/python3.8/site-packages (from nbformat>=4.2.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (3.2.0) Requirement already satisfied: pyrsistent>=0.14.0 in /databricks/python3/lib/python3.8/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.2.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (0.17.3) Requirement already satisfied: pytz>=2017.3 in /databricks/python3/lib/python3.8/site-packages (from pandas>=0.23.0->keplergl==0.2.2) (2020.5) Requirement already satisfied: numpy>=1.16.5 in /databricks/python3/lib/python3.8/site-packages (from pandas>=0.23.0->keplergl==0.2.2) (1.19.2) Requirement already satisfied: python-dateutil>=2.7.3 in /databricks/python3/lib/python3.8/site-packages (from pandas>=0.23.0->keplergl==0.2.2) (2.8.1) Requirement already satisfied: ptyprocess>=0.5 in /databricks/python3/lib/python3.8/site-packages (from pexpect>4.3->ipython>=4.0.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (0.7.0) Requirement already satisfied: wcwidth in /databricks/python3/lib/python3.8/site-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->ipython>=4.0.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (0.2.5) Requirement already satisfied: notebook>=4.4.1 in /databricks/python3/lib/python3.8/site-packages (from widgetsnbextension~=3.5.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (6.3.0) Requirement already satisfied: Send2Trash>=1.5.0 in /databricks/python3/lib/python3.8/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (1.5.0) Requirement already satisfied: nbconvert in /databricks/python3/lib/python3.8/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (6.0.7) Requirement already satisfied: terminado>=0.8.3 in /databricks/python3/lib/python3.8/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (0.9.4) Requirement already satisfied: pyzmq>=17 in /databricks/python3/lib/python3.8/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (20.0.0) Requirement already satisfied: jinja2 in /databricks/python3/lib/python3.8/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (2.11.3) Requirement already satisfied: argon2-cffi in /databricks/python3/lib/python3.8/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (20.1.0) Requirement already satisfied: prometheus-client in /databricks/python3/lib/python3.8/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (0.10.1) Requirement already satisfied: cffi>=1.0.0 in /databricks/python3/lib/python3.8/site-packages (from argon2-cffi->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (1.14.5) Requirement already satisfied: pycparser in /databricks/python3/lib/python3.8/site-packages (from cffi>=1.0.0->argon2-cffi->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (2.20) Requirement already satisfied: MarkupSafe>=0.23 in /databricks/python3/lib/python3.8/site-packages (from jinja2->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (1.1.1) Requirement already satisfied: pandocfilters>=1.4.1 in /databricks/python3/lib/python3.8/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (1.4.3) Requirement already satisfied: bleach in /databricks/python3/lib/python3.8/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (3.3.0) Requirement already satisfied: defusedxml in /databricks/python3/lib/python3.8/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (0.7.1) Requirement already satisfied: mistune<2,>=0.8.1 in /databricks/python3/lib/python3.8/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (0.8.4) Requirement already satisfied: nbclient<0.6.0,>=0.5.0 in /databricks/python3/lib/python3.8/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (0.5.3) Requirement already satisfied: entrypoints>=0.2.2 in /databricks/python3/lib/python3.8/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (0.3) Requirement already satisfied: jupyterlab-pygments in /databricks/python3/lib/python3.8/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (0.1.2) Requirement already satisfied: testpath in /databricks/python3/lib/python3.8/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (0.4.4) Requirement already satisfied: nest-asyncio in /databricks/python3/lib/python3.8/site-packages (from nbclient<0.6.0,>=0.5.0->nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (1.5.1) Requirement already satisfied: async-generator in /databricks/python3/lib/python3.8/site-packages (from nbclient<0.6.0,>=0.5.0->nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (1.10) Requirement already satisfied: webencodings in /databricks/python3/lib/python3.8/site-packages (from bleach->nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (0.5.1) Requirement already satisfied: packaging in /databricks/python3/lib/python3.8/site-packages (from bleach->nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (20.9) Requirement already satisfied: pyparsing>=2.0.2 in /databricks/python3/lib/python3.8/site-packages (from packaging->bleach->nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets<8,>=7.0.0->keplergl==0.2.2) (2.4.7) Building wheels for collected packages: keplergl Building wheel for keplergl (setup.py): started Building wheel for keplergl (setup.py): finished with status 'done' Created wheel for keplergl: filename=keplergl-0.2.2-py2.py3-none-any.whl size=15942747 sha256=81ad09194a4b837394569c5846a1ea94d7411dff4218055d7ce37071bfa2773d Stored in directory: /root/.cache/pip/wheels/89/d6/37/324afae5363607e96bcc059b10f1102b0661ecd9a37a6d6b3c Successfully built keplergl Installing collected packages: traittypes, keplergl Successfully installed keplergl-0.2.2 traittypes-0.2.1 WARNING: You are using pip version 21.0.1; however, version 22.1.1 is available. You should consider upgrading via the '/local_disk0/.ephemeral_nfs/envs/pythonEnv-03256acc-d7e2-40b4-a17c-cef5679e70d7/bin/python -m pip install --upgrade pip' command. Python interpreter will be restarted.
from keplergl import KeplerGl
from pyspark.sql.functions import hex, col, lit
from pyspark.sql import Row
import h3
from pyspark.sql.types import *
Databricks notebook specific function

Produces HTML that is formatted properly in Databricks notebook

def create_kepler_html(data, config, height):
  map_1 = KeplerGl(height=height, data=data, config=config)
  html = map_1._repr_html_().decode("utf-8")
  new_html = html + """<script>
      var targetHeight = "{height}px";
      var interval = window.setInterval(function() {{
        if (document.body && document.body.style && document.body.style.height !== targetHeight) {{
          document.body.style.height = targetHeight;
        }}
      }}, 250);</script>""".format(height=height)
  return new_html

Example 1 - Understanding Hexagons and Hierarchies

In this first example we show how the different resolutions of hexagons in the h3 library fit into one other in a hierarchical manner. There are functions that allow us to zoom up and down the hierarchy and we can visualise this using KeplerGL. This forms a great basis for understanding the rest of the examples.

Produce a hexagon to traverse into

First we will use a set of coordinates located in New York City to produce a hex_id at resolution 6. We can then find all the children of this hexagon using a fairly fine-grained resolution, 11.

lat = 40.7831
lng = -73.9712
resolution = 6
parent_h3 = h3.geo_to_h3(lat, lng, resolution)
 
print(parent_h3)
862a1008fffffff
res11 = [Row(x) for x in list(h3.h3_to_children(parent_h3, 11))]
 
print(res11[:10])
[<Row('8b2a10089a0efff')>, <Row('8b2a100880a3fff')>, <Row('8b2a10088373fff')>, <Row('8b2a1008d176fff')>, <Row('8b2a1008859efff')>, <Row('8b2a1008e46dfff')>, <Row('8b2a1008bd71fff')>, <Row('8b2a10088b80fff')>, <Row('8b2a1008d175fff')>, <Row('8b2a10089db2fff')>]
Create Dataframe

Now we can create a dataframe with out resolution 11 hexagons and then add columns using UDFs to get the parent values for each step up. Below we capture the parent values at resolutions 10, 9, 8, and 7.

schema = StructType([       
    StructField('hex_id', StringType(), True)
])
 
sdf = spark.createDataFrame(data=res11, schema = schema)
 
display(sdf)
 
hex_id
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
8b2a10089a0efff
8b2a100880a3fff
8b2a10088373fff
8b2a1008d176fff
8b2a1008859efff
8b2a1008e46dfff
8b2a1008bd71fff
8b2a10088b80fff
8b2a1008d175fff
8b2a10089db2fff
8b2a1008b852fff
8b2a1008d46efff
8b2a1008c84cfff
8b2a1008e448fff
8b2a1008880bfff
8b2a1008e2f4fff
8b2a1008952dfff

Truncated results, showing first 1000 rows.

@udf
def getLat(h3_id):
  return h3.h3_to_geo(h3_id)[0]
 
@udf
def getLong(h3_id):
  return h3.h3_to_geo(h3_id)[1]
 
@udf
def getParent(h3_id, parent_res):
  return h3.h3_to_parent(h3_id, parent_res)
pdf = ( sdf
   .withColumn("h3_res10", getParent("hex_id", lit(10)))
       .withColumn("h3_res9", getParent("hex_id", lit(9)))
       .withColumn("h3_res8", getParent("hex_id", lit(8)))
       .withColumn("h3_res7", getParent("hex_id", lit(7)))
       .withColumnRenamed('hex_id', "h3_res11")
    .toPandas() 
      )
 
display(pdf)
 
h3_res11
h3_res10
h3_res9
h3_res8
h3_res7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
8b2a10089a0efff
8a2a10089a0ffff
892a10089a3ffff
882a10089bfffff
872a10089ffffff
8b2a100880a3fff
8a2a100880a7fff
892a100880bffff
882a100881fffff
872a10088ffffff
8b2a10088373fff
8a2a10088377fff
892a1008837ffff
882a100883fffff
872a10088ffffff
8b2a1008d176fff
8a2a1008d177fff
892a1008d17ffff
882a1008d1fffff
872a1008dffffff
8b2a1008859efff
8a2a1008859ffff
892a100885bffff
882a100885fffff
872a10088ffffff
8b2a1008e46dfff
8a2a1008e46ffff
892a1008e47ffff
882a1008e5fffff
872a1008effffff
8b2a1008bd71fff
8a2a1008bd77fff
892a1008bd7ffff
882a1008bdfffff
872a1008bffffff
8b2a10088b80fff
8a2a10088b87fff
892a10088bbffff
882a10088bfffff
872a10088ffffff
8b2a1008d175fff
8a2a1008d177fff
892a1008d17ffff
882a1008d1fffff
872a1008dffffff
8b2a10089db2fff
8a2a10089db7fff
892a10089dbffff
882a10089dfffff
872a10089ffffff
8b2a1008b852fff
8a2a1008b857fff
892a1008b87ffff
882a1008b9fffff
872a1008bffffff
8b2a1008d46efff
8a2a1008d46ffff
892a1008d47ffff
882a1008d5fffff
872a1008dffffff
8b2a1008c84cfff
8a2a1008c84ffff
892a1008c87ffff
882a1008c9fffff
872a1008cffffff
8b2a1008e448fff
8a2a1008e44ffff
892a1008e47ffff
882a1008e5fffff
872a1008effffff
8b2a1008880bfff
8a2a1008880ffff
892a1008883ffff
882a100889fffff
872a10088ffffff
8b2a1008e2f4fff
8a2a1008e2f7fff
892a1008e2fffff
882a1008e3fffff
872a1008effffff
8b2a1008952dfff
8a2a1008952ffff
892a1008953ffff
882a100895fffff
872a10089ffffff

Truncated results, showing first 1000 rows.

map_config={
  "version": "v1",
  "config": {
    "visState": {
      "filters": [],
      "layers": [
        {
          "id": "mg08ej3",
          "type": "hexagonId",
          "config": {
            "dataId": "hex_data",
            "label": "h3_res11",
            "color": [
              18,
              147,
              154
            ],
            "columns": {
              "hex_id": "h3_res11"
            },
            "isVisible": False,
            "visConfig": {
              "opacity": 0.8,
              "colorRange": {
                "name": "Global Warming",
                "type": "sequential",
                "category": "Uber",
                "colors": [
                  "#5A1846",
                  "#900C3F",
                  "#C70039",
                  "#E3611C",
                  "#F1920E",
                  "#FFC300"
                ]
              },
              "coverage": 1,
              "enable3d": False,
              "sizeRange": [
                0,
                500
              ],
              "coverageRange": [
                0,
                1
              ],
              "elevationScale": 5
            },
            "hidden": False,
            "textLabel": [
              {
                "field": None,
                "color": [
                  255,
                  255,
                  255
                ],
                "size": 18,
                "offset": [
                  0,
                  0
                ],
                "anchor": "start",
                "alignment": "center"
              }
            ]
          },
          "visualChannels": {
            "colorField": None,
            "colorScale": "quantile",
            "sizeField": None,
            "sizeScale": "linear",
            "coverageField": None,
            "coverageScale": "linear"
          }
        },
        {
          "id": "x1gdbyj",
          "type": "hexagonId",
          "config": {
            "dataId": "hex_data",
            "label": "h3_res10",
            "color": [
              221,
              178,
              124
            ],
            "columns": {
              "hex_id": "h3_res10"
            },
            "isVisible": False,
            "visConfig": {
              "opacity": 0.8,
              "colorRange": {
                "name": "Global Warming",
                "type": "sequential",
                "category": "Uber",
                "colors": [
                  "#5A1846",
                  "#900C3F",
                  "#C70039",
                  "#E3611C",
                  "#F1920E",
                  "#FFC300"
                ]
              },
              "coverage": 1,
              "enable3d": False,
              "sizeRange": [
                0,
                500
              ],
              "coverageRange": [
                0,
                1
              ],
              "elevationScale": 5
            },
            "hidden": False,
            "textLabel": [
              {
                "field": None,
                "color": [
                  255,
                  255,
                  255
                ],
                "size": 18,
                "offset": [
                  0,
                  0
                ],
                "anchor": "start",
                "alignment": "center"
              }
            ]
          },
          "visualChannels": {
            "colorField": None,
            "colorScale": "quantile",
            "sizeField": None,
            "sizeScale": "linear",
            "coverageField": None,
            "coverageScale": "linear"
          }
        },
        {
          "id": "xrdgt51",
          "type": "hexagonId",
          "config": {
            "dataId": "hex_data",
            "label": "h3_res9",
            "color": [
              136,
              87,
              44
            ],
            "columns": {
              "hex_id": "h3_res9"
            },
            "isVisible": False,
            "visConfig": {
              "opacity": 0.8,
              "colorRange": {
                "name": "Global Warming",
                "type": "sequential",
                "category": "Uber",
                "colors": [
                  "#5A1846",
                  "#900C3F",
                  "#C70039",
                  "#E3611C",
                  "#F1920E",
                  "#FFC300"
                ]
              },
              "coverage": 1,
              "enable3d": False,
              "sizeRange": [
                0,
                500
              ],
              "coverageRange": [
                0,
                1
              ],
              "elevationScale": 5
            },
            "hidden": False,
            "textLabel": [
              {
                "field": None,
                "color": [
                  255,
                  255,
                  255
                ],
                "size": 18,
                "offset": [
                  0,
                  0
                ],
                "anchor": "start",
                "alignment": "center"
              }
            ]
          },
          "visualChannels": {
            "colorField": None,
            "colorScale": "quantile",
            "sizeField": None,
            "sizeScale": "linear",
            "coverageField": None,
            "coverageScale": "linear"
          }
        },
        {
          "id": "etz6nbl",
          "type": "hexagonId",
          "config": {
            "dataId": "hex_data",
            "label": "h3_res8",
            "color": [
              125,
              177,
              227
            ],
            "columns": {
              "hex_id": "h3_res8"
            },
            "isVisible": True,
            "visConfig": {
              "opacity": 0.15,
              "colorRange": {
                "name": "Global Warming",
                "type": "sequential",
                "category": "Uber",
                "colors": [
                  "#5A1846",
                  "#900C3F",
                  "#C70039",
                  "#E3611C",
                  "#F1920E",
                  "#FFC300"
                ]
              },
              "coverage": 0.95,
              "enable3d": False,
              "sizeRange": [
                0,
                500
              ],
              "coverageRange": [
                0,
                1
              ],
              "elevationScale": 5
            },
            "hidden": False,
            "textLabel": [
              {
                "field": None,
                "color": [
                  255,
                  255,
                  255
                ],
                "size": 18,
                "offset": [
                  0,
                  0
                ],
                "anchor": "start",
                "alignment": "center"
              }
            ]
          },
          "visualChannels": {
            "colorField": None,
            "colorScale": "quantile",
            "sizeField": None,
            "sizeScale": "linear",
            "coverageField": None,
            "coverageScale": "linear"
          }
        },
        {
          "id": "jn27fi",
          "type": "hexagonId",
          "config": {
            "dataId": "hex_data",
            "label": "h3_res7",
            "color": [
              117,
              222,
              227
            ],
            "columns": {
              "hex_id": "h3_res7"
            },
            "isVisible": True,
            "visConfig": {
              "opacity": 0.31,
              "colorRange": {
                "name": "Global Warming",
                "type": "sequential",
                "category": "Uber",
                "colors": [
                  "#5A1846",
                  "#900C3F",
                  "#C70039",
                  "#E3611C",
                  "#F1920E",
                  "#FFC300"
                ]
              },
              "coverage": 0.98,
              "enable3d": False,
              "sizeRange": [
                0,
                500
              ],
              "coverageRange": [
                0,
                1
              ],
              "elevationScale": 5
            },
            "hidden": False,
            "textLabel": [
              {
                "field": None,
                "color": [
                  255,
                  255,
                  255
                ],
                "size": 18,
                "offset": [
                  0,
                  0
                ],
                "anchor": "start",
                "alignment": "center"
              }
            ]
          },
          "visualChannels": {
            "colorField": None,
            "colorScale": "quantile",
            "sizeField": None,
            "sizeScale": "linear",
            "coverageField": None,
            "coverageScale": "linear"
          }
        }
      ],
      "interactionConfig": {
        "tooltip": {
          "fieldsToShow": {
            "hex_data": [
              {
                "name": "h3_res11",
                "format": None
              },
              {
                "name": "h3_res10",
                "format": None
              },
              {
                "name": "h3_res9",
                "format": None
              },
              {
                "name": "h3_res8",
                "format": None
              },
              {
                "name": "h3_res7",
                "format": None
              }
            ]
          },
          "compareMode": False,
          "compareType": "absolute",
          "enabled": True
        },
        "brush": {
          "size": 0.5,
          "enabled": False
        },
        "geocoder": {
          "enabled": False
        },
        "coordinate": {
          "enabled": False
        }
      },
      "layerBlending": "subtractive",
      "splitMaps": [],
      "animationConfig": {
        "currentTime": None,
        "speed": 1
      }
    },
    "mapState": {
      "bearing": 0,
      "dragRotate": False,
      "latitude": 40.79223909866621,
      "longitude": -73.99527316762153,
      "pitch": 0,
      "zoom": 13.347945326288185,
      "isSplit": False
    },
    "mapStyle": {
      "styleType": "dark",
      "topLayerGroups": {},
      "visibleLayerGroups": {
        "label": True,
        "road": True,
        "border": False,
        "building": True,
        "water": True,
        "land": True,
        "3d building": False
      },
      "threeDBuildingColor": [
        9.665468314072013,
        17.18305478057247,
        31.1442867897876
      ],
      "mapStyles": {}
    }
  }
}

Display Results for Example 1

example_1_html = create_kepler_html(data= {"hex_data": pdf }, config=map_config, height=600)
 
displayHTML(example_1_html)
User Guide: https://docs.kepler.gl/docs/keplergl-jupyter

Example 2 - Polygon and Hexagon Relationships

Now we can get into using the dataset that we worked with earlier to better understand the relationships in our data and how indexing libraries work with geospatial analysis. Below we will query some of our raw and index safegraph data to show the relationship of polygon and a h3_index.

Query Data

The following query pulls all polygons in Washington DC in a particular US ZIP code ('20001'). They key components that we are interested in displaying on the map are the ploygons for the different POIs as well as the cooresponding hex_ids that were computed at resolution 13. Supporting data points include attributes such as the location name and street address.

Here we are breaking out polygons from each individual hex_id to cut the total amount of data going into the map. because there are several hex_ids per each polygon, if we separate the Hex_ids from the rest of the POI data, we can eliminate duplicated values. This means the final HTML that is displayed is acutally less bytes total.