diff --git a/examples/explore.ipynb b/examples/explore.ipynb new file mode 100644 index 00000000..53f61ab9 --- /dev/null +++ b/examples/explore.ipynb @@ -0,0 +1,3743 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "a76948e2-eda2-4c6f-8fe2-341b67ac5531", + "metadata": {}, + "outputs": [], + "source": [ + "%load_ext autoreload\n", + "%autoreload 2\n", + "\n", + "from warnings import warn\n", + "\n", + "import geodatasets\n", + "import geopandas as gpd\n", + "import numpy as np\n", + "from mapclassify import classify\n", + "import lonboard.geopandas" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "1e09eb28-7b9a-4dd6-a11a-f9d26bd5e793", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Author: eli knaap\n", + "\n", + "lonboard : 0.10.3\n", + "geodatasets: 2024.8.0\n", + "mapclassify: 2.8.2.dev2+ga421b4b.d20250107\n", + "numpy : 1.26.4\n", + "geopandas : 1.0.1\n", + "\n" + ] + } + ], + "source": [ + "%load_ext watermark\n", + "%watermark -a 'eli knaap' -iv" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "3902a38a-84c2-492a-b8b8-fad2b4afef72", + "metadata": {}, + "outputs": [], + "source": [ + "gdf = gpd.read_file(geodatasets.get_path(\"geoda.milwaukee1\"))" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "9b0db679-e16b-4111-b24f-19de0c544fc5", + "metadata": {}, + "outputs": [], + "source": [ + "gdf = gdf.to_crs(gdf.estimate_utm_crs())" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "0e071041-a9a6-4d9a-9c3f-e8b252bda744", + "metadata": {}, + "outputs": [], + "source": [ + "gdf = gdf[[\"HH_INC\", \"geometry\"]]" + ] + }, + { + "cell_type": "markdown", + "id": "d3b67d78-8ddc-4691-9f09-3fbb81a65cd0", + "metadata": {}, + "source": [ + "## Simple Map" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "11c477e4-b3c0-489c-a85c-2a9ac9e48d8c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "gdf.explore()" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "22485cad-e47b-409a-accf-0da27419db7b", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/knaaptime/Dropbox/projects/lonboard/lonboard/_geoarrow/ops/reproject.py:107: UserWarning: Input being reprojected to EPSG:4326 CRS.\n", + "Lonboard is only able to render data in EPSG:4326 projection.\n", + " warnings.warn(\n" + ] + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "fd08e0f286884efdb34c25dd57e92182", + "version_major": 2, + "version_minor": 1 + }, + "text/plain": [ + "Map(basemap_style=, cu…" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from lonboard import basemap\n", + "\n", + "gdf.lb.explore(\n", + " tiles=\"CartoDB Positron\",\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "93da152a-6409-4764-ab24-f773e3d09fb9", + "metadata": {}, + "source": [ + "## boorish (unclassed :P) choropleth" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "487cafd3-4735-4c2c-b19f-6ff6dcdfe93c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "gdf.explore(\"HH_INC\", tiles=\"CartoDB Darkmatter\")" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "f044e655-32be-4ce1-b015-223ed9c71de1", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/knaaptime/Dropbox/projects/lonboard/lonboard/_geoarrow/ops/reproject.py:107: UserWarning: Input being reprojected to EPSG:4326 CRS.\n", + "Lonboard is only able to render data in EPSG:4326 projection.\n", + " warnings.warn(\n" + ] + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "2aa890576f174cbdbec9d6fbcb2f86e6", + "version_major": 2, + "version_minor": 1 + }, + "text/plain": [ + "Map(basemap_style=
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "gdf.explore(\n", + " \"HH_INC\",\n", + " scheme=\"quantiles\",\n", + " k=6,\n", + " cmap=\"YlOrBr\",\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "e70b95c3-09b2-40be-8f5e-fd1482388be2", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/knaaptime/Dropbox/projects/lonboard/lonboard/_geoarrow/ops/reproject.py:107: UserWarning: Input being reprojected to EPSG:4326 CRS.\n", + "Lonboard is only able to render data in EPSG:4326 projection.\n", + " warnings.warn(\n" + ] + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "789f4c5c78524a1a8bf361fea2058545", + "version_major": 2, + "version_minor": 1 + }, + "text/plain": [ + "Map(basemap_style=
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "classify_kwds = dict(bins=[20000, 40000, 800000, 2000000])\n", + "\n", + "gdf.explore(\n", + " \"HH_INC\",\n", + " cmap=\"YlOrBr\",\n", + " scheme=\"user_defined\",\n", + " classification_kwds=classify_kwds,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "ad5c4e9f-7dcc-4144-b5ba-77987cea0def", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/knaaptime/Dropbox/projects/lonboard/lonboard/_geoarrow/ops/reproject.py:107: UserWarning: Input being reprojected to EPSG:4326 CRS.\n", + "Lonboard is only able to render data in EPSG:4326 projection.\n", + " warnings.warn(\n" + ] + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "5b8507ba5e874d639bc0f9893203c01c", + "version_major": 2, + "version_minor": 1 + }, + "text/plain": [ + "Map(basemap_style=
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "m = linedf.explore(\n", + " \"len\", cmap=\"viridis_r\", scheme=\"quantiles\", k=10, tiles=\"CartoDB Darkmatter\"\n", + ")\n", + "gdf.set_geometry(gdf.centroid).explore(color=\"magenta\", m=m)\n", + "m" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "54df1700-2971-4813-9842-aa0116b46e20", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/knaaptime/Dropbox/projects/lonboard/lonboard/_geoarrow/ops/reproject.py:107: UserWarning: Input being reprojected to EPSG:4326 CRS.\n", + "Lonboard is only able to render data in EPSG:4326 projection.\n", + " warnings.warn(\n", + "/Users/knaaptime/Dropbox/projects/lonboard/lonboard/_geoarrow/ops/reproject.py:107: UserWarning: Input being reprojected to EPSG:4326 CRS.\n", + "Lonboard is only able to render data in EPSG:4326 projection.\n", + " warnings.warn(\n" + ] + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "7c38fe7515d742dfa2fdc261502b6bac", + "version_major": 2, + "version_minor": 1 + }, + "text/plain": [ + "Map(basemap_style=
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "gdf.explore(\n", + " \"i\",\n", + " categorical=True,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "a7f86337-b4ed-4ac6-929c-13d053f21767", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/knaaptime/Dropbox/projects/lonboard/lonboard/_geoarrow/ops/reproject.py:107: UserWarning: Input being reprojected to EPSG:4326 CRS.\n", + "Lonboard is only able to render data in EPSG:4326 projection.\n", + " warnings.warn(\n" + ] + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "73e88f7390e944d88a97459915536701", + "version_major": 2, + "version_minor": 1 + }, + "text/plain": [ + "Map(basemap_style=
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "gdf.explore(\"q5\", categorical=True, cmap=\"tab20b\", tiles=\"CartoDB Positron\")" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "9bd34a9c-6a45-4f53-a9ca-19324e6aa32d", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/knaaptime/Dropbox/projects/lonboard/lonboard/_geoarrow/ops/reproject.py:107: UserWarning: Input being reprojected to EPSG:4326 CRS.\n", + "Lonboard is only able to render data in EPSG:4326 projection.\n", + " warnings.warn(\n" + ] + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "877851f50c184d369abad1aa991c8834", + "version_major": 2, + "version_minor": 1 + }, + "text/plain": [ + "Map(basemap_style=, cu…" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "m = gdf.lb.explore(\n", + " \"q5\",\n", + " categorical=True,\n", + " cmap=\"tab20b\",\n", + " nan_color=[0, 0, 0, 0],\n", + " tiles=\"CartoDB Positron\",\n", + ")\n", + "m" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4e926525-d0a8-40dd-a195-89a774bbe8a4", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "c54f7abe-ca10-467a-baf0-ff6c499ea4e8", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/knaaptime/Dropbox/projects/lonboard/lonboard/_geoarrow/ops/reproject.py:107: UserWarning: Input being reprojected to EPSG:4326 CRS.\n", + "Lonboard is only able to render data in EPSG:4326 projection.\n", + " warnings.warn(\n" + ] + } + ], + "source": [ + "m = gdf.lb.explore(\"q5\", categorical=True, cmap=\"RdBu\", alpha=0.5)" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "433064c8-6f54-43fe-9e73-1754100a6d50", + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "7b81b4e4bbdd4b088a8b01a5bb698af7", + "version_major": 2, + "version_minor": 1 + }, + "text/plain": [ + "Map(basemap_style=" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from ipywidgets import interact, fixed\n", + "interact(choro, vals=fixed(gdf.HH_INC), classifier=list(_classifiers.keys()), k=range(3,10), cmap=list(colormaps.keys()), layer=fixed(m.layers[0]))" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "73c7a823-c3fd-4ade-aa73-5709b0ee29d7", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/knaaptime/Dropbox/projects/lonboard/lonboard/_geoarrow/ops/reproject.py:107: UserWarning: Input being reprojected to EPSG:4326 CRS.\n", + "Lonboard is only able to render data in EPSG:4326 projection.\n", + " warnings.warn(\n" + ] + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "2898a0fbaf824841b555db54af1fbfec", + "version_major": 2, + "version_minor": 1 + }, + "text/plain": [ + "Map(basemap_style==0.3.0", "geodatasets>=2024.8.0", "jupyterlab>=4.3.3", + "mapclassify>=2.8.1", "matplotlib>=3.7.5", "movingpandas>=0.20.0", "palettable>=3.3.3",