Skip to content

Commit

Permalink
Add 3D choropleth notebook example (#819)
Browse files Browse the repository at this point in the history
* Add 3D choropleth example

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
giswqs and pre-commit-ci[bot] authored Jul 6, 2024
1 parent 7a813f1 commit 2fbf0d8
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 0 deletions.
130 changes: 130 additions & 0 deletions docs/maplibre/3d_choropleth.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[![image](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://demo.leafmap.org/lab/index.html?path=maplibre/3d_choropleth.ipynb)\n",
"[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/opengeos/leafmap/blob/master/docs/maplibre/3d_choropleth.ipynb)\n",
"[![image](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/opengeos/leafmap/HEAD)\n",
"\n",
"**Create a 3D choropleth map of Europe with countries extruded**\n",
"\n",
"This source code of this example is adapted from the MapTiler SDK JS example - [Create a 3D choropleth map of Europe with countries extruded](https://docs.maptiler.com/sdk-js/examples/fill-extrusion).\n",
"\n",
"Uncomment the following line to install [leafmap](https://leafmap.org) if needed."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# %pip install \"leafmap[maplibre]\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import leafmap.maplibregl as leafmap"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To run this notebook, you will need an [API key](https://docs.maptiler.com/cloud/api/authentication-key/) from [MapTiler](https://www.maptiler.com/cloud/). Once you have the API key, you can uncomment the following code block and replace `YOUR_API_KEY` with your actual API key. Then, run the code block code to set the API key as an environment variable."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# import os\n",
"# os.environ[\"MAPTILER_KEY\"] = \"YOUR_API_KEY\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"m = leafmap.Map(center=[19.43, 49.49], zoom=3, pitch=60, style=\"basic\")\n",
"source = {\n",
" \"type\": \"geojson\",\n",
" \"data\": \"https://docs.maptiler.com/sdk-js/assets/Mean_age_of_women_at_first_marriage_in_2019.geojson\",\n",
"}\n",
"m.add_source(\"countries\", source)\n",
"layer = {\n",
" \"id\": \"eu-countries\",\n",
" \"source\": \"countries\",\n",
" \"type\": \"fill-extrusion\",\n",
" \"paint\": {\n",
" \"fill-extrusion-color\": [\n",
" \"interpolate\",\n",
" [\"linear\"],\n",
" [\"get\", \"age\"],\n",
" 23.0,\n",
" \"#fff5eb\",\n",
" 24.0,\n",
" \"#fee6ce\",\n",
" 25.0,\n",
" \"#fdd0a2\",\n",
" 26.0,\n",
" \"#fdae6b\",\n",
" 27.0,\n",
" \"#fd8d3c\",\n",
" 28.0,\n",
" \"#f16913\",\n",
" 29.0,\n",
" \"#d94801\",\n",
" 30.0,\n",
" \"#8c2d04\",\n",
" ],\n",
" \"fill-extrusion-opacity\": 1,\n",
" \"fill-extrusion-height\": [\"*\", [\"get\", \"age\"], 5000],\n",
" },\n",
"}\n",
"first_symbol_layer_id = m.find_first_symbol_layer()[\"id\"]\n",
"m.add_layer(layer, first_symbol_layer_id)\n",
"m.add_layer_control()\n",
"m"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![](https://i.imgur.com/fLgqYTa.png)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
6 changes: 6 additions & 0 deletions docs/maplibre/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ Use extrusions to display buildings' height in 3D.

[![](https://i.imgur.com/9QeicaE.png)](https://leafmap.org/maplibre/3d_buildings)

## Create a 3D choropleth map

Create a 3D choropleth map of Europe with countries extruded

[![](https://i.imgur.com/fLgqYTa.png)](https://leafmap.org/maplibre/3d_choropleth)

## Extrude polygons for 3D indoor mapping

Create a 3D indoor map with the fill-extrude-height paint property.
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ nav:
- MapLibre:
- maplibre/overview.md
- maplibre/3d_buildings.ipynb
- maplibre/3d_choropleth.ipynb
- maplibre/3d_indoor_mapping.ipynb
- maplibre/3d_style.ipynb
- maplibre/3d_terrain.ipynb
Expand Down

0 comments on commit 2fbf0d8

Please sign in to comment.