Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add add_data method to maplibre #1001

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
237 changes: 237 additions & 0 deletions docs/maplibre/choropleth.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "0",
"metadata": {},
"source": [
"[![image](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://demo.leafmap.org/lab/index.html?path=maplibre/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/choropleth.ipynb)\n",
"[![image](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/opengeos/leafmap/HEAD)\n",
"\n",
"**Creating choropleth maps with a variety of classification schemes**\n",
"\n",
"Uncomment the following line to install [leafmap](https://leafmap.org) if needed."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1",
"metadata": {},
"outputs": [],
"source": [
"# %pip install \"leafmap[maplibre]\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2",
"metadata": {},
"outputs": [],
"source": [
"import leafmap.maplibregl as leafmap"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3",
"metadata": {},
"outputs": [],
"source": [
"data = \"https://github.com/opengeos/datasets/releases/download/vector/countries.geojson\""
]
},
{
"cell_type": "markdown",
"id": "4",
"metadata": {},
"source": [
"Available classification schemes: \n",
"* BoxPlot\n",
"* EqualInterval\n",
"* FisherJenks\n",
"* FisherJenksSampled\n",
"* HeadTailBreaks\n",
"* JenksCaspall\n",
"* JenksCaspallForced\n",
"* JenksCaspallSampled\n",
"* MaxP\n",
"* MaximumBreaks\n",
"* NaturalBreaks\n",
"* Quantiles\n",
"* Percentiles\n",
"* StdMean\n",
"* UserDefined"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5",
"metadata": {},
"outputs": [],
"source": [
"m = leafmap.Map(style=\"liberty\")\n",
"first_symbol_id = m.find_first_symbol_layer()[\"id\"]\n",
"m.add_data(\n",
" data,\n",
" column=\"POP_EST\",\n",
" scheme=\"Quantiles\",\n",
" cmap=\"Blues\",\n",
" legend_title=\"Population\",\n",
" name=\"Population\",\n",
" before_id=first_symbol_id,\n",
" extrude=True,\n",
" scale_factor=1000,\n",
")\n",
"m.add_layer_control()\n",
"m"
]
},
{
"cell_type": "markdown",
"id": "6",
"metadata": {},
"source": [
"![image](https://github.com/user-attachments/assets/35ca3e17-956e-4d88-9e24-7e94c9e322f8)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7",
"metadata": {},
"outputs": [],
"source": [
"m = leafmap.Map(style=\"liberty\")\n",
"m.add_data(\n",
" data,\n",
" column=\"POP_EST\",\n",
" scheme=\"Quantiles\",\n",
" cmap=\"Blues\",\n",
" legend_title=\"Population\",\n",
" name=\"Population\",\n",
" before_id=first_symbol_id,\n",
")\n",
"m.add_layer_control()\n",
"m"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "9",
"metadata": {},
"outputs": [],
"source": [
"m = leafmap.Map(style=\"liberty\")\n",
"m.add_data(\n",
" data,\n",
" column=\"POP_EST\",\n",
" scheme=\"EqualInterval\",\n",
" cmap=\"Blues\",\n",
" legend_title=\"Population\",\n",
" name=\"Population\",\n",
" before_id=first_symbol_id,\n",
")\n",
"m.add_layer_control()\n",
"m"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "10",
"metadata": {},
"outputs": [],
"source": [
"m = leafmap.Map(style=\"liberty\")\n",
"m.add_data(\n",
" data,\n",
" column=\"POP_EST\",\n",
" scheme=\"FisherJenks\",\n",
" cmap=\"Blues\",\n",
" legend_title=\"Population\",\n",
" name=\"Population\",\n",
" before_id=first_symbol_id,\n",
")\n",
"m.add_layer_control()\n",
"m"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "11",
"metadata": {},
"outputs": [],
"source": [
"m = leafmap.Map(style=\"liberty\")\n",
"m.add_data(\n",
" data,\n",
" column=\"POP_EST\",\n",
" scheme=\"FisherJenks\",\n",
" cmap=\"Blues\",\n",
" legend_title=\"Population\",\n",
" name=\"Population\",\n",
" before_id=first_symbol_id,\n",
")\n",
"m.add_layer_control()\n",
"m"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "12",
"metadata": {},
"outputs": [],
"source": [
"m = leafmap.Map(style=\"liberty\")\n",
"m.add_data(\n",
" data,\n",
" column=\"POP_EST\",\n",
" scheme=\"JenksCaspall\",\n",
" cmap=\"Blues\",\n",
" legend_title=\"Population\",\n",
" name=\"Population\",\n",
" before_id=first_symbol_id,\n",
")\n",
"m.add_layer_control()\n",
"m"
]
}
],
"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": 5
}
6 changes: 6 additions & 0 deletions docs/maplibre/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ Use the upcase and downcase expressions to change the case of labels.

[![](https://i.imgur.com/FzGOovv.png)](https://leafmap.org/maplibre/change_case_of_labels)

## Create choropleth maps

Create choropleth maps with a variety of classification schemes.

[![](https://github.com/user-attachments/assets/35ca3e17-956e-4d88-9e24-7e94c9e322f8)](https://leafmap.org/maplibre/change_case_of_labels)

## Cloud Optimized GeoTIFF (COG)

Visualize Cloud Optimized GeoTIFF (COG) files with TiTiler.
Expand Down
Loading