A interactive web application for visualizing massive H3 geospatial data on Databricks using Leaflet maps. This application demostrates the speed of exploring and visualizing any table in your Databricks workspace, which has an H3 index column. The responsiveness of the app is due using dynamic zoom levels determine the H3 resolution and refreshing the map to filter on the viewport to only pull and visualize relevant data.
This application was built in support of this Databricks Community Blog Post: Scaling Geospatial Analytics: Efficient Visualization of Massive Spatial Datasets
- Interactive Leaflet Maps: Responsive maps with dark theme styling
- H3 Hexagon Visualization: Efficient rendering of H3 geospatial data at multiple resolutions
- Dynamic Data Loading: Real-time data fetching based on map viewport and zoom level
- Multi-level Data Selection: Select your catalog, schema, table, and column selection to visualize any table in your Databricks workspace.
- Adaptive Resolution: Automatic H3 resolution adjustment based on zoom level for optimal performance
- Color-coded Heatmaps: Logarithmic color scaling for better data representation
- Databricks Integration: Seamless connection to Databricks SQL warehouses for backend aggregations
- Databricks Asset Bundles (DABS): Built using DABs to efficiently deploy to your workspace
The application is built using:
- Databricks Apps: Deploy the app directly in your Databricks workspace
- On-behalf-on authentication: Only displays data which app users have access to in Unity Catalog
- Frontend: Dash (Python web framework) with Bootstrap components
- Maps: Leaflet.js for interactive mapping
- Data Processing: Pandas and NumPy for data manipulation
- Geospatial: H3 library for hexagonal grid operations
- Database: Databricks SQL connector for data access
- Deployment: Databricks Asset Bundles for easy deployment
- Python 3.8+
- Databricks workspace access
- SQL warehouse permissions
- H3 geospatial data in your Databricks tables
-
Clone the repository:
git clone <repository-url> cd geospatial_viz_app_leaflet
-
Install dependencies:
cd app pip install -r requirements.txt
-
Set environment variables for app:
export DATABRICKS_WAREHOUSE_ID="your_warehouse_id" export DATABRICKS_HOST="your-workspace.cloud.databricks.com" export DATABRICKS_TOKEN="your_access_token"* export DATABRICKS_BUDGET_POLICY_ID="your_budget_policy_id"** export DEFAULT_CATALOG="your_catalog" export DEFAULT_SCHEMA="your_schema" export DEFAULT_TABLE="your_table" export DEFAULT_COLUMN="your_h3_column"
*Can use on-behalf-of authentication if not set, but local development requires a token **Budget policy is option when deploying the DAB
-
Set environment variables for bundle deployment (DAB):
export BUNDLE_VAR_sql_warehouse_id=$DATABRICKS_WAREHOUSE_ID export BUNDLE_VAR_budget_policy_id=$DATABRICKS_BUDGET_POLICY_ID
-
Run the application:
python app.py
- Configure your Databricks workspace in
databricks.yml
- Validate your Databricks Asset Bundle:
databricks bundle validate
- Deploy using Databricks Asset Bundles:
databricks bundle deploy
Variable | Description | Required |
---|---|---|
DATABRICKS_WAREHOUSE_ID |
SQL warehouse ID for data access | Yes |
DATABRICKS_HOST |
Databricks workspace URL | Yes |
DATABRICKS_TOKEN |
Access token for authentication | Yes* |
DATABRICKS_BUDGET_POLICY_ID |
Databricks budget policy id | No |
DEFAULT_CATALOG |
Default catalog to load | No |
DEFAULT_SCHEMA |
Default schema to load | No |
DEFAULT_TABLE |
Default table to load | No |
DEFAULT_COLUMN |
Default H3 column to visualize | No |
*Can use on-behalf-of authentication if not set
Your Databricks table should contain:
- H3 columns: Valid H3 index column
- Launch the application and wait for initial data load
- Select data source using the dropdown controls:
- Catalog β Schema β Table β Column
- Navigate the map using standard Leaflet controls
- Refresh data using the refresh button to update based on current viewport
- Zoom: Mouse wheel or zoom controls
- Pan: Click and drag to move around
- Resolution: Automatically adjusts H3 resolution based on zoom level
- Bounds: Data is filtered based on current map viewport
- Color Scale: Logarithmic scaling for better data distribution
- Legend: Interactive legend showing count ranges and colors
- Performance: Viewport-based data loading for large datasets
The application automatically adjusts H3 resolution based on zoom level:
Zoom Level | H3 Resolution | Use Case |
---|---|---|
4-7 | 5-6 | Country/region view |
8-11 | 7-9 | City/metropolitan view |
12-15 | 10-11 | Neighborhood view |
16+ | 12 | Street-level detail |
- Lazy Loading: Data is only fetched when needed
- Viewport Filtering: Queries are limited to visible map area
- Resolution Optimization: H3 resolution automatically adjusts for performance
- Server-side Processing: Performs aggregations in Databricks SQL warehouses
geospatial_viz_app_leaflet/
βββ app/
β βββ app.py # Main application file
β βββ app.yml # App configuration
β βββ requirements.txt # Python dependencies
βββ notebooks/
β βββ nb01-download-prep-large-scale-dataset.dbc # Databricks notebook for data preparation
β βββ nb01-download-prep-large-scale-dataset.ipynb # Jupyter notebook for data preparation
β βββ nb02-query-explore-large-scale-tables.dbc # Databricks notebook for data exploration
β βββ nb02-query-explore-large-scale-tables.ipynb # Jupyter notebook for data exploration
βββ resources/
β βββ geospatial_viz_app_leaflet.yml # Databricks resources
βββ databricks.yml # Bundle configuration
βββ README.md # This file
cd app
python app.py
databricks bundle validate
databricks bundle deploy --target dev
Built using Databricks, Dash, and Leaflet
Package | License | Copyright |
---|---|---|
Leaflet | BSD 2-Clause License | Copyright (c) 2010-2025, Volodymyr Agafonkin |
Dash | MIT License | Copyright (c) 2015-2024 Plotly Technologies Inc. |
Β© 2025 Databricks, Inc. All rights reserved. The source in this project is provided subject to the Databricks License [https://databricks.com/db-license-source]. All included or referenced third party libraries are subject to the licenses set forth below.