{ "cells": [ { "cell_type": "markdown", "metadata": { "papermill": { "duration": 0.01471, "end_time": "2021-08-13T16:31:33.332090", "exception": false, "start_time": "2021-08-13T16:31:33.317380", "status": "completed" }, "tags": [] }, "source": [ "## Configuring basemap tiles in [Lets-Plot](https://lets-plot.org)\n", "\n", "\n", "### Configuring globally\n", "\n", "You can configure global Lets-Plot options using the `LestPlot.set(dictionary)` method.\n", "\n", "Where the `dictionary` can contain all sorts of Lets-Plot options, including basemap tiles configuration options.\n", "\n", "Lets-Plot provides a variety of constantas and functions which make configuring of basemap tiles simple:\n", "\n", "```\n", "from lets_plot import tilesets\n", "\n", "LetsPlot.set(tilesets.LETS_PLOT_DARK)\n", "```\n", "\n", "### Configuring for a single plot\n", "\n", "Use `tiles` parameter in the `geom_livemap()` function:\n", "```\n", "from lets_plot import tilesets\n", "\n", "ggplot() + geom_livemap(tiles=tilesets.LETS_PLOT_DARK)\n", "```\n", "\n", "\n", "In this demo we will be using the `tiles` parameter because each plot here is using different map-tile service.\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2024-04-26T11:56:59.362933Z", "iopub.status.busy": "2024-04-26T11:56:59.362933Z", "iopub.status.idle": "2024-04-26T11:57:00.259994Z", "shell.execute_reply": "2024-04-26T11:57:00.259994Z" }, "papermill": { "duration": 0.151002, "end_time": "2021-08-13T16:31:46.140392", "exception": false, "start_time": "2021-08-13T16:31:45.989390", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from lets_plot import *\n", "from lets_plot import tilesets\n", "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2024-04-26T11:57:00.291843Z", "iopub.status.busy": "2024-04-26T11:57:00.291843Z", "iopub.status.idle": "2024-04-26T11:57:00.308504Z", "shell.execute_reply": "2024-04-26T11:57:00.307609Z" }, "papermill": { "duration": 0.031894, "end_time": "2021-08-13T16:31:46.193221", "exception": false, "start_time": "2021-08-13T16:31:46.161327", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "def show_map(text, tiles=None):\n", " (ggplot() + geom_livemap(location=[13.3, 37.6], zoom=3, tiles=tiles) + \n", " ggsize(500, 450) + \n", " ggtitle(text)).show()" ] }, { "cell_type": "markdown", "metadata": { "papermill": { "duration": 0.020359, "end_time": "2021-08-13T16:31:46.234328", "exception": false, "start_time": "2021-08-13T16:31:46.213969", "status": "completed" }, "tags": [] }, "source": [ "### Lets-Plot vector tiles\n", "\n", "Lets-Plot provides its own vector basemap tiles available in four variants:\n", "\n", "- color\n", "- dark\n", "- light\n", "- bw\n", "\n", "By default Lets-Plot uses its \"color\" tiles." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2024-04-26T11:57:00.309580Z", "iopub.status.busy": "2024-04-26T11:57:00.309580Z", "iopub.status.idle": "2024-04-26T11:57:00.418729Z", "shell.execute_reply": "2024-04-26T11:57:00.418729Z" }, "papermill": { "duration": 0.921285, "end_time": "2021-08-13T16:31:47.176828", "exception": false, "start_time": "2021-08-13T16:31:46.255543", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "show_map(\"Lets-Plot vector tiles (default).\")\n", "show_map(\"Lets-Plot vector tiles (dark).\", tilesets.LETS_PLOT_DARK)\n", "show_map(\"Lets-Plot vector tiles (light).\", tilesets.LETS_PLOT_LIGHT)\n", "show_map(\"Lets-Plot vector tiles (bw).\", tilesets.LETS_PLOT_BW)" ] }, { "cell_type": "markdown", "metadata": { "papermill": { "duration": 0.021944, "end_time": "2021-08-13T16:31:47.221336", "exception": false, "start_time": "2021-08-13T16:31:47.199392", "status": "completed" }, "tags": [] }, "source": [ "## Raster tiles\n", "\n", "You can use `ZXY` raster tiles provided by 3rd party maptile services.\n", "\n", "Some services provide free of charge raster tilesets. \n", "\n", "The `tilesets` module in Lets-Plot contains many such tilesets pre-cofigured." ] }, { "cell_type": "markdown", "metadata": { "papermill": { "duration": 0.021865, "end_time": "2021-08-13T16:31:47.265452", "exception": false, "start_time": "2021-08-13T16:31:47.243587", "status": "completed" }, "tags": [] }, "source": [ "### OpenStreetMap\n", "\n", "[© OpenStreetMap contributors](https://www.openstreetmap.org/copyright)\n", "\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2024-04-26T11:57:00.419909Z", "iopub.status.busy": "2024-04-26T11:57:00.419909Z", "iopub.status.idle": "2024-04-26T11:57:00.434443Z", "shell.execute_reply": "2024-04-26T11:57:00.434443Z" }, "papermill": { "duration": 0.035795, "end_time": "2021-08-13T16:31:47.323441", "exception": false, "start_time": "2021-08-13T16:31:47.287646", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "show_map(\"OpenStreetMap's Standard tile layer\", tilesets.OSM)" ] }, { "cell_type": "markdown", "metadata": { "papermill": { "duration": 0.022436, "end_time": "2021-08-13T16:31:47.368614", "exception": false, "start_time": "2021-08-13T16:31:47.346178", "status": "completed" }, "tags": [] }, "source": [ "### OpenTopoMap\n", "\n", "Map data: [© OpenStreetMap contributors](https://www.openstreetmap.org/copyright), [SRTM](http://viewfinderpanoramas.org/) | map style: [© OpenTopoMap](https://opentopomap.org/) ([CC-BY-SA](https://creativecommons.org/licenses/by-sa/3.0/))\n", "\n" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2024-04-26T11:57:00.434443Z", "iopub.status.busy": "2024-04-26T11:57:00.434443Z", "iopub.status.idle": "2024-04-26T11:57:00.450276Z", "shell.execute_reply": "2024-04-26T11:57:00.449626Z" }, "papermill": { "duration": 0.03807, "end_time": "2021-08-13T16:31:47.429501", "exception": false, "start_time": "2021-08-13T16:31:47.391431", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "show_map(\"OpenTopoMap\", tilesets.OPEN_TOPO_MAP)" ] }, { "cell_type": "markdown", "metadata": { "papermill": { "duration": 0.025762, "end_time": "2021-08-13T16:31:47.612664", "exception": false, "start_time": "2021-08-13T16:31:47.586902", "status": "completed" }, "tags": [] }, "source": [ "### CARTO\n", "\n", "[© OpenStreetMap contributors](https://www.openstreetmap.org/copyright) [© CARTO](https://carto.com/attributions#basemaps), [© CARTO](https://carto.com/attributions)\n", "\n", "Free for none-commercial services only (see [Limitations](https://github.com/CartoDB/basemap-styles#1-web-raster-basemaps), [License](https://github.com/CartoDB/basemap-styles/blob/master/LICENSE.md)).\n", "\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2024-04-26T11:57:00.450276Z", "iopub.status.busy": "2024-04-26T11:57:00.450276Z", "iopub.status.idle": "2024-04-26T11:57:00.482053Z", "shell.execute_reply": "2024-04-26T11:57:00.481085Z" }, "papermill": { "duration": 0.070642, "end_time": "2021-08-13T16:31:47.710849", "exception": false, "start_time": "2021-08-13T16:31:47.640207", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "show_map(\"CARTO Positron\", tilesets.CARTO_POSITRON_HIRES)\n", "show_map(\"CARTO Positron (no labels)\", tilesets.CARTO_POSITRON_NO_LABELS_HIRES)\n", "show_map(\"CARTO Dark Matter (no labels)\", tilesets.CARTO_DARK_MATTER_NO_LABELS_HIRES)\n", "show_map(\"CARTO Voyager\", tilesets.CARTO_VOYAGER_HIRES)\n", "show_map(\"CARTO Flat Blue\", tilesets.CARTO_FLAT_BLUE)\n", "show_map(\"CARTO Midnight commander\", tilesets.CARTO_MIDNIGHT_COMMANDER)\n", "show_map(\"CARTO Antique\", tilesets.CARTO_ANTIQUE_HIRES)" ] }, { "cell_type": "markdown", "metadata": { "papermill": { "duration": 0.028926, "end_time": "2021-08-13T16:31:47.769614", "exception": false, "start_time": "2021-08-13T16:31:47.740688", "status": "completed" }, "tags": [] }, "source": [ "### NASA's Global Imagery Browse Services (GIBS)\n", "\n", "Imagery provided by services from NASA's Global Imagery Browse Services ([GIBS](https://earthdata.nasa.gov/eosdis/science-system-description/eosdis-components/gibs)), part of NASA's Earth Observing System Data and Information System ([EOSDIS](https://earthdata.nasa.gov)).\n", "\n", "[NASA's Global Imagery Browse Services (GIBS)](https://earthdata.nasa.gov/eosdis/science-system-description/eosdis-components/gibs).\n", "\n", "Global Imagery Browse Services (GIBS) - [API for Developers](https://wiki.earthdata.nasa.gov/display/GIBS/GIBS+API+for+Developers).\n", "\n", "Global Imagery Browse Services (GIBS) API - [Generic XYZ Tile Access](https://wiki.earthdata.nasa.gov/display/GIBS/GIBS+API+for+Developers#GIBSAPIforDevelopers-GenericXYZTileAccess).\n", "\n", "[GIBS Available Imagery Products](https://wiki.earthdata.nasa.gov/display/GIBS/GIBS+Available+Imagery+Products).\n" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2024-04-26T11:57:00.482053Z", "iopub.status.busy": "2024-04-26T11:57:00.482053Z", "iopub.status.idle": "2024-04-26T11:57:00.512835Z", "shell.execute_reply": "2024-04-26T11:57:00.512835Z" }, "papermill": { "duration": 0.059658, "end_time": "2021-08-13T16:31:47.858339", "exception": false, "start_time": "2021-08-13T16:31:47.798681", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "show_map(\"NASA GIBS: CityLights 2012\", tilesets.NASA_CITYLIGHTS_2012)\n", "show_map(\"NASA GIBS: Greyscale Shaded Relief (30m)\", tilesets.NASA_GREYSCALE_SHADED_RELIEF_30M)\n", "show_map(\"NASA GIBS: Color Shaded Relief (30m)\", tilesets.NASA_COLOR_SHADED_RELIEF_30M)\n", "show_map(\"NASA GIBS: Terra TrueColor\", tilesets.NASA_TERRA_TRUECOLOR)" ] }, { "cell_type": "markdown", "metadata": { "papermill": { "duration": 0.031329, "end_time": "2021-08-13T16:31:47.922582", "exception": false, "start_time": "2021-08-13T16:31:47.891253", "status": "completed" }, "tags": [] }, "source": [ "## Configuring raster tiles manually\n", "\n", "In addition to pre-configured tilesets you can configure and use almost any other raster tilesets provided in `ZXY` format.\n", "\n", "You can do it with the help of the `LetsPlot.maptiles_zxy()` function.\n", "\n", "The following code will configure 'NASA, CityLights 2012' tiles:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "execution": { "iopub.execute_input": "2024-04-26T11:57:00.512835Z", "iopub.status.busy": "2024-04-26T11:57:00.512835Z", "iopub.status.idle": "2024-04-26T11:57:00.528347Z", "shell.execute_reply": "2024-04-26T11:57:00.528347Z" }, "papermill": { "duration": 0.043719, "end_time": "2021-08-13T16:31:47.998362", "exception": false, "start_time": "2021-08-13T16:31:47.954643", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "settings = dict(\n", " url = \"https://gibs.earthdata.nasa.gov/wmts/epsg3857/best/VIIRS_CityLights_2012/default/GoogleMapsCompatible_Level8/{z}/{y}/{x}.jpg\",\n", " attribution = '© NASA Global Imagery Browse Services (GIBS)',\n", " max_zoom=8\n", ")\n", "\n", "show_map(\"NASA, CityLights 2012\", maptiles_zxy(**settings))" ] } ], "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.10.13" }, "papermill": { "duration": 19.868762, "end_time": "2021-08-13T16:31:48.138583", "environment_variables": {}, "exception": null, "input_path": "__notebook__.ipynb", "output_path": "__notebook__.ipynb", "parameters": {}, "start_time": "2021-08-13T16:31:28.269821", "version": "2.1.0" } }, "nbformat": 4, "nbformat_minor": 4 }