diff --git a/docs/code/python_dataviz/10_leafmap_basics.ipynb b/docs/code/python_dataviz/10_leafmap_basics.ipynb index fca261a0..90667ead 100644 --- a/docs/code/python_dataviz/10_leafmap_basics.ipynb +++ b/docs/code/python_dataviz/10_leafmap_basics.ipynb @@ -1,392 +1,392 @@ { - "cells": [ - { - "cell_type": "markdown", - "id": "fd708770-59b8-4fb9-acce-2b2d837d88e6", - "metadata": { - "id": "fd708770-59b8-4fb9-acce-2b2d837d88e6" - }, - "source": [ - "## Overview\n", - "\n", - "[Leafmap](https://leafmap.org/) is a Python package for interactive mapping that supports a wide-variety of plotting backends. \n", - "\n", - "We will explore the capabilities of Leafmap and create a map that includes vector and raster layers. For a more comprehensive overview, check out [leafmap key Features](https://leafmap.org/notebooks/00_key_features/)." - ] + "cells": [ + { + "cell_type": "markdown", + "id": "fd708770-59b8-4fb9-acce-2b2d837d88e6", + "metadata": { + "id": "fd708770-59b8-4fb9-acce-2b2d837d88e6" + }, + "source": [ + "## Overview\n", + "\n", + "[Leafmap](https://leafmap.org/) is a Python package for interactive mapping that supports a wide-variety of plotting backends.\n", + "\n", + "We will explore the capabilities of Leafmap and create a map that includes vector and raster layers. For a more comprehensive overview, check out [leafmap key Features](https://leafmap.org/notebooks/00_key_features/)." + ] + }, + { + "cell_type": "markdown", + "id": "3LKOmTSadQCJ", + "metadata": { + "id": "3LKOmTSadQCJ" + }, + "source": [ + "## Setup and Data Download" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "QYAcw2IjHVzi", + "metadata": { + "id": "QYAcw2IjHVzi" + }, + "outputs": [], + "source": [ + "%%capture\n", + "if 'google.colab' in str(get_ipython()):\n", + " !apt install libspatialindex-dev\n", + " !pip install fiona shapely pyproj rtree mapclassify\n", + " !pip install geopandas\n", + " !pip install leafmap" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "df487246-fb38-451f-a76d-ffbb7ad95a0f", + "metadata": { + "id": "df487246-fb38-451f-a76d-ffbb7ad95a0f" + }, + "outputs": [], + "source": [ + "import os\n", + "import geopandas as gpd\n", + "import leafmap.foliumap as leafmap" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "lOLD5d1yHZIC", + "metadata": { + "id": "lOLD5d1yHZIC" + }, + "outputs": [], + "source": [ + "data_folder = 'data'\n", + "output_folder = 'output'\n", + "\n", + "if not os.path.exists(data_folder):\n", + " os.mkdir(data_folder)\n", + "if not os.path.exists(output_folder):\n", + " os.mkdir(output_folder)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1PVxJlqkHb0q", + "metadata": { + "id": "1PVxJlqkHb0q" + }, + "outputs": [], + "source": [ + "def download(url):\n", + " filename = os.path.join(data_folder, os.path.basename(url))\n", + " if not os.path.exists(filename):\n", + " from urllib.request import urlretrieve\n", + " local, _ = urlretrieve(url, filename)\n", + " print('Downloaded ' + local)\n", + "\n", + "json_file = 'bangalore_wards.json'\n", + "gpkg_file = 'bangalore_roads.gpkg'\n", + "\n", + "data_url = 'https://github.com/spatialthoughts/python-dataviz-web/raw/main/data/bangalore/'\n", + "\n", + "for f in json_file, gpkg_file:\n", + " download(data_url + f)\n" + ] + }, + { + "cell_type": "markdown", + "id": "z_PRvY7aiq6Z", + "metadata": { + "id": "z_PRvY7aiq6Z" + }, + "source": [ + "## Creating a Map" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9fEqEt0_iuYR", + "metadata": { + "id": "9fEqEt0_iuYR" + }, + "outputs": [], + "source": [ + "m = leafmap.Map(width=800, height=500)\n", + "m" + ] + }, + { + "cell_type": "markdown", + "id": "50cY2MDqf0HH", + "metadata": { + "id": "50cY2MDqf0HH" + }, + "source": [ + "You can change the basemap to a Google basemap and set the center of the map. `leafmap.Map()` supports many arguments to customize the map and available controls.\n", + "\n", + "References:\n", + "\n", + "* [`leafmap.leafmap.Map`](https://leafmap.org/leafmap/#leafmap.leafmap.Map)\n", + "* [`ipyleaflet.leaflet.Map`](https://ipyleaflet.readthedocs.io/en/latest/api_reference/index.html#ipyleaflet.leaflet.Map)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b-q1fHrTf85g", + "metadata": { + "id": "b-q1fHrTf85g" + }, + "outputs": [], + "source": [ + "m = leafmap.Map(width=800, height=500, google_map='HYBRID', center=(12.97, 77.59), zoom=10)\n", + "m" + ] + }, + { + "cell_type": "markdown", + "id": "XJD3xD3ZtXxD", + "metadata": { + "id": "XJD3xD3ZtXxD" + }, + "source": [ + "## Adding Data Layers" + ] + }, + { + "cell_type": "markdown", + "id": "8NyMffsKkN3L", + "metadata": { + "id": "8NyMffsKkN3L" + }, + "source": [ + "Leafmap's `foliummap` module supports adding a variety of data types along with helper functions such as `set_center()`. Let's add a GeoJSON file to the map using `add_geojson()`.\n", + "\n", + "Reference: [leafmap.foliumap.Map.add_geojson](https://leafmap.org/foliumap/#leafmap.foliumap.Map.add_geojson)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fjBPneGOjTWB", + "metadata": { + "id": "fjBPneGOjTWB" + }, + "outputs": [], + "source": [ + "m = leafmap.Map(width=800, height=500)\n", + "\n", + "json_filepath = os.path.join(data_folder, json_file)\n", + "\n", + "m.add_geojson(json_filepath, layer_name='City')\n", + "m.set_center(77.59, 12.97, 10)\n", + "m" + ] + }, + { + "cell_type": "markdown", + "id": "D3NQmnP3hf0v", + "metadata": { + "id": "D3NQmnP3hf0v" + }, + "source": [ + "We can also add any vector layer that can be read by GeoPandas. Here we add a line layer from a GeoPackage using the `add_gdf()` function. The styling parameters can be any folium supported styles." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "gaJ5zMffkeHP", + "metadata": { + "id": "gaJ5zMffkeHP" + }, + "outputs": [], + "source": [ + "m = leafmap.Map(width=800, height=500)\n", + "\n", + "gpkg_filepath = os.path.join(data_folder, gpkg_file)\n", + "\n", + "roads_gdf = gpd.read_file(gpkg_filepath)\n", + "\n", + "m.add_gdf(roads_gdf, layer_name='Roads', style={'color':'blue', 'weight':0.5})\n", + "m.zoom_to_gdf(roads_gdf)\n", + "m" + ] + }, + { + "cell_type": "markdown", + "id": "oazyce9GiJxn", + "metadata": { + "id": "oazyce9GiJxn" + }, + "source": [ + "A very useful feature of LeafMap is the ability to load a Cloud-Optimized GeoTIFF (COG) file directly from a URL without the need of a server. The file is streamed directly and high-resolution tiles are automatically fetched as you zoom in. We load a 8-bit RGB image hosted on GitHub using the `add_cog_layer()` function.\n", + "\n", + "Reference: [`leafmap.Map.add_cog_layer`](https://leafmap.org/leafmap/#leafmap.leafmap.Map.add_cog_layer)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "maq-ro4rl_Pj", + "metadata": { + "id": "maq-ro4rl_Pj" + }, + "outputs": [], + "source": [ + "m = leafmap.Map(width=800, height=500)\n", + "\n", + "cog_url = os.path.join(data_url, 'bangalore_lulc_rgb.tif')\n", + "bounds = leafmap.cog_bounds(cog_url)\n", + "\n", + "m.add_cog_layer(cog_url, name='Land Use Land Cover')\n", + "m.zoom_to_bounds(bounds)\n", + "m" + ] + }, + { + "cell_type": "markdown", + "id": "Z6ajwt53tfzY", + "metadata": { + "id": "Z6ajwt53tfzY" + }, + "source": [ + "Leafmap also supports adding custom legends. We define a list of color codes and labels for the land cover classes contained in the `bangalore_lulc.tif` image. We can now add a legend to the map using the `add_legend()` function.\n", + "\n", + "Reference: [leafmap.foliumap.Map.add_legend](https://leafmap.org/foliumap/#leafmap.foliumap.Map.add_legend)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "F02jMssOq2tC", + "metadata": { + "id": "F02jMssOq2tC" + }, + "outputs": [], + "source": [ + "m = leafmap.Map(width=800, height=500)\n", + "\n", + "cog_url = os.path.join(data_url, 'bangalore_lulc_rgb.tif')\n", + "bounds = leafmap.cog_bounds(cog_url)\n", + "\n", + "m.add_cog_layer(cog_url, name='Land Use Land Cover')\n", + "m.zoom_to_bounds(bounds)\n", + "\n", + "# Add a Legend\n", + "colors = ['#006400', '#ffbb22','#ffff4c','#f096ff','#fa0000',\n", + " '#b4b4b4','#f0f0f0','#0064c8','#0096a0','#00cf75','#fae6a0']\n", + "labels = [\"Trees\",\"Shrubland\",\"Grassland\",\"Cropland\",\"Built-up\",\n", + " \"Barren / sparse vegetation\",\"Snow and ice\",\"Open water\",\n", + " \"Herbaceous wetland\",\"Mangroves\",\"Moss and lichen\"]\n", + "m.add_legend(colors=colors, labels=labels)\n", + "m" + ] + }, + { + "cell_type": "markdown", + "id": "WsVirLa2d5rY", + "metadata": { + "id": "WsVirLa2d5rY" + }, + "source": [ + "We can save the resulting map to a HTML file using the `to_html()` function." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "wOkm3hN6dcQD", + "metadata": { + "id": "wOkm3hN6dcQD" + }, + "outputs": [], + "source": [ + "m = leafmap.Map(width=800, height=500)\n", + "\n", + "cog_url = os.path.join(data_url, 'bangalore_lulc_rgb.tif')\n", + "bounds = leafmap.cog_bounds(cog_url)\n", + "\n", + "m.add_cog_layer(cog_url, name='Land Use Land Cover')\n", + "m.zoom_to_bounds(bounds)\n", + "\n", + "# Add a Legend\n", + "colors = ['#006400', '#ffbb22','#ffff4c','#f096ff','#fa0000',\n", + " '#b4b4b4','#f0f0f0','#0064c8','#0096a0','#00cf75','#fae6a0']\n", + "labels = [\"Trees\",\"Shrubland\",\"Grassland\",\"Cropland\",\"Built-up\",\n", + " \"Barren / sparse vegetation\",\"Snow and ice\",\"Open water\",\n", + " \"Herbaceous wetland\",\"Mangroves\",\"Moss and lichen\"]\n", + "m.add_legend(colors=colors, labels=labels)\n", + "\n", + "output_file = 'lulc.html'\n", + "output_path = os.path.join(output_folder, output_file)\n", + "m.to_html(output_path)" + ] + }, + { + "cell_type": "markdown", + "id": "852P-W2Kc3q6", + "metadata": { + "id": "852P-W2Kc3q6" + }, + "source": [ + "## Exercise\n", + "\n", + "The code below contains a basic leafmap map. We want to a raster layers of VIIRS Nighttime Lights over India. The URL to a Cloud Optmized GeoTiff (COG) file hosted on Google Cloud Storage is given below.\n", + "\n", + "Add the data to the map and visualize it.\n", + "\n", + "Reference: [`leafmap.Map.add_cog_layer`](https://leafmap.org/leafmap/#leafmap.leafmap.Map.add_cog_layer)\n", + "\n", + "You will need to specify additional `kwargs` parameters to create a correct visualization.\n", + "\n", + "1. The GeoTIFF image is a single-band image with grayscale values of night light intensities. The range of these values are between 0-60. Use `rescale='0,60'`.\n", + "2. The image has a nodata values stored as `nan`. Use `nodata='nan'`.\n", + "3. A grayscale image can be displayed in color using a colormap. Use `colormap_name=viridis`.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "sGUkRyUqjAUT", + "metadata": { + "id": "sGUkRyUqjAUT" + }, + "outputs": [], + "source": [ + "gcs_bucket = 'https://storage.googleapis.com/spatialthoughts-public-data/ntl/viirs/'\n", + "cog_url = os.path.join(gcs_bucket, 'viirs_ntl_2021_india.tif')" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "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.6" + } }, - { - "cell_type": "markdown", - "id": "3LKOmTSadQCJ", - "metadata": { - "id": "3LKOmTSadQCJ" - }, - "source": [ - "## Setup and Data Download" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "QYAcw2IjHVzi", - "metadata": { - "id": "QYAcw2IjHVzi" - }, - "outputs": [], - "source": [ - "%%capture\n", - "if 'google.colab' in str(get_ipython()):\n", - " !apt install libspatialindex-dev\n", - " !pip install fiona shapely pyproj rtree mapclassify\n", - " !pip install geopandas\n", - " !pip install leafmap" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "df487246-fb38-451f-a76d-ffbb7ad95a0f", - "metadata": { - "id": "df487246-fb38-451f-a76d-ffbb7ad95a0f" - }, - "outputs": [], - "source": [ - "import os\n", - "import geopandas as gpd\n", - "import leafmap.foliumap as leafmap" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "lOLD5d1yHZIC", - "metadata": { - "id": "lOLD5d1yHZIC" - }, - "outputs": [], - "source": [ - "data_folder = 'data'\n", - "output_folder = 'output'\n", - "\n", - "if not os.path.exists(data_folder):\n", - " os.mkdir(data_folder)\n", - "if not os.path.exists(output_folder):\n", - " os.mkdir(output_folder)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "1PVxJlqkHb0q", - "metadata": { - "id": "1PVxJlqkHb0q" - }, - "outputs": [], - "source": [ - "def download(url):\n", - " filename = os.path.join(data_folder, os.path.basename(url))\n", - " if not os.path.exists(filename):\n", - " from urllib.request import urlretrieve\n", - " local, _ = urlretrieve(url, filename)\n", - " print('Downloaded ' + local)\n", - "\n", - "json_file = 'bangalore_wards.json'\n", - "gpkg_file = 'bangalore_roads.gpkg'\n", - "\n", - "data_url = 'https://github.com/spatialthoughts/python-dataviz-web/raw/main/data/bangalore/'\n", - "\n", - "for f in json_file, gpkg_file:\n", - " download(data_url + f)\n" - ] - }, - { - "cell_type": "markdown", - "id": "z_PRvY7aiq6Z", - "metadata": { - "id": "z_PRvY7aiq6Z" - }, - "source": [ - "## Creating a Map" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "9fEqEt0_iuYR", - "metadata": { - "id": "9fEqEt0_iuYR" - }, - "outputs": [], - "source": [ - "m = leafmap.Map(width=800, height=500)\n", - "m" - ] - }, - { - "cell_type": "markdown", - "id": "50cY2MDqf0HH", - "metadata": { - "id": "50cY2MDqf0HH" - }, - "source": [ - "You can change the basemap to a Google basemap and set the center of the map. `leafmap.Map()` supports many arguments to customize the map and available controls.\n", - "\n", - "References: \n", - "\n", - "* [`leafmap.leafmap.Map`](https://leafmap.org/leafmap/#leafmap.leafmap.Map)\n", - "* [`ipyleaflet.leaflet.Map`](https://ipyleaflet.readthedocs.io/en/latest/api_reference/index.html#ipyleaflet.leaflet.Map)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "b-q1fHrTf85g", - "metadata": { - "id": "b-q1fHrTf85g" - }, - "outputs": [], - "source": [ - "m = leafmap.Map(width=800, height=500, google_map='HYBRID', center=(12.97, 77.59), zoom=10)\n", - "m" - ] - }, - { - "cell_type": "markdown", - "id": "XJD3xD3ZtXxD", - "metadata": { - "id": "XJD3xD3ZtXxD" - }, - "source": [ - "## Adding Data Layers" - ] - }, - { - "cell_type": "markdown", - "id": "8NyMffsKkN3L", - "metadata": { - "id": "8NyMffsKkN3L" - }, - "source": [ - "Leafmap's `foliummap` module supports adding a variety of data types along with helper functions such as `set_center()`. Let's add a GeoJSON file to the map using `add_geojson()`.\n", - "\n", - "Reference: [leafmap.foliumap.Map.add_geojson](https://leafmap.org/foliumap/#leafmap.foliumap.Map.add_geojson)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "fjBPneGOjTWB", - "metadata": { - "id": "fjBPneGOjTWB" - }, - "outputs": [], - "source": [ - "m = leafmap.Map(width=800, height=500)\n", - "\n", - "json_filepath = os.path.join(data_folder, json_file)\n", - "\n", - "m.add_geojson(json_filepath, layer_name='City')\n", - "m.set_center(77.59, 12.97, 10)\n", - "m" - ] - }, - { - "cell_type": "markdown", - "id": "D3NQmnP3hf0v", - "metadata": { - "id": "D3NQmnP3hf0v" - }, - "source": [ - "We can also add any vector layer that can be read by GeoPandas. Here we add a line layer from a GeoPackage using the `add_gdf()` function. The styling parameters can be any folium supported styles." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "gaJ5zMffkeHP", - "metadata": { - "id": "gaJ5zMffkeHP" - }, - "outputs": [], - "source": [ - "m = leafmap.Map(width=800, height=500)\n", - "\n", - "gpkg_filepath = os.path.join(data_folder, gpkg_file)\n", - "\n", - "roads_gdf = gpd.read_file(gpkg_filepath)\n", - "\n", - "m.add_gdf(roads_gdf, layer_name='Roads', style={'color':'blue', 'weight':0.5})\n", - "m.zoom_to_gdf(roads_gdf)\n", - "m" - ] - }, - { - "cell_type": "markdown", - "id": "oazyce9GiJxn", - "metadata": { - "id": "oazyce9GiJxn" - }, - "source": [ - "A very useful feature of LeafMap is the ability to load a Cloud-Optimized GeoTIFF (COG) file directly from a URL without the need of a server. The file is streamed directly and high-resolution tiles are automatically fetched as you zoom in. We load a 8-bit RGB image hosted on GitHub using the `add_cog_layer()` function.\n", - "\n", - "Reference: [`leafmap.Map.add_cog_layer`](https://leafmap.org/leafmap/#leafmap.leafmap.Map.add_cog_layer)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "maq-ro4rl_Pj", - "metadata": { - "id": "maq-ro4rl_Pj" - }, - "outputs": [], - "source": [ - "m = leafmap.Map(width=800, height=500)\n", - "\n", - "cog_url = os.path.join(data_url, 'bangalore_lulc_rgb.tif')\n", - "bounds = leafmap.cog_bounds(cog_url)\n", - "\n", - "m.add_cog_layer(cog_url, name='Land Use Land Cover')\n", - "m.zoom_to_bounds(bounds)\n", - "m" - ] - }, - { - "cell_type": "markdown", - "id": "Z6ajwt53tfzY", - "metadata": { - "id": "Z6ajwt53tfzY" - }, - "source": [ - "Leafmap also supports adding custom legends. We define a list of color codes and labels for the land cover classes contained in the `bangalore_lulc.tif` image. We can now add a legend to the map using the `add_legend()` function.\n", - "\n", - "Reference: [leafmap.foliumap.Map.add_legend](https://leafmap.org/foliumap/#leafmap.foliumap.Map.add_legend)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "F02jMssOq2tC", - "metadata": { - "id": "F02jMssOq2tC" - }, - "outputs": [], - "source": [ - "m = leafmap.Map(width=800, height=500)\n", - "\n", - "cog_url = os.path.join(data_url, 'bangalore_lulc_rgb.tif')\n", - "bounds = leafmap.cog_bounds(cog_url)\n", - "\n", - "m.add_cog_layer(cog_url, name='Land Use Land Cover')\n", - "m.zoom_to_bounds(bounds)\n", - "\n", - "# Add a Legend\n", - "colors = ['#006400', '#ffbb22','#ffff4c','#f096ff','#fa0000',\n", - " '#b4b4b4','#f0f0f0','#0064c8','#0096a0','#00cf75','#fae6a0']\n", - "labels = [\"Trees\",\"Shrubland\",\"Grassland\",\"Cropland\",\"Built-up\",\n", - " \"Barren / sparse vegetation\",\"Snow and ice\",\"Open water\",\n", - " \"Herbaceous wetland\",\"Mangroves\",\"Moss and lichen\"]\n", - "m.add_legend(colors=colors, labels=labels)\n", - "m" - ] - }, - { - "cell_type": "markdown", - "id": "WsVirLa2d5rY", - "metadata": { - "id": "WsVirLa2d5rY" - }, - "source": [ - "We can save the resulting map to a HTML file using the `to_html()` function." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "wOkm3hN6dcQD", - "metadata": { - "id": "wOkm3hN6dcQD" - }, - "outputs": [], - "source": [ - "m = leafmap.Map(width=800, height=500)\n", - "\n", - "cog_url = os.path.join(data_url, 'bangalore_lulc_rgb.tif')\n", - "bounds = leafmap.cog_bounds(cog_url)\n", - "\n", - "m.add_cog_layer(cog_url, name='Land Use Land Cover')\n", - "m.zoom_to_bounds(bounds)\n", - "\n", - "# Add a Legend\n", - "colors = ['#006400', '#ffbb22','#ffff4c','#f096ff','#fa0000',\n", - " '#b4b4b4','#f0f0f0','#0064c8','#0096a0','#00cf75','#fae6a0']\n", - "labels = [\"Trees\",\"Shrubland\",\"Grassland\",\"Cropland\",\"Built-up\",\n", - " \"Barren / sparse vegetation\",\"Snow and ice\",\"Open water\",\n", - " \"Herbaceous wetland\",\"Mangroves\",\"Moss and lichen\"]\n", - "m.add_legend(colors=colors, labels=labels)\n", - "\n", - "output_file = 'lulc.html'\n", - "output_path = os.path.join(output_folder, output_file)\n", - "m.to_html(output_path)" - ] - }, - { - "cell_type": "markdown", - "id": "852P-W2Kc3q6", - "metadata": { - "id": "852P-W2Kc3q6" - }, - "source": [ - "## Exercise\n", - "\n", - "The code below contains a basic leafmap map. We want to a raster layers of VIIRS Nighttime Lights over India. The URL to a Cloud Optmized GeoTiff (COG) file hosted on Google Cloud Storage is given below.\n", - "\n", - "Add the data to the map and visualize it.\n", - "\n", - "Reference: [`leafmap.Map.add_cog_layer`](https://leafmap.org/leafmap/#leafmap.leafmap.Map.add_cog_layer)\n", - "\n", - "You will need to specify additional `kwargs` parameters to create a correct visualization.\n", - "\n", - "1. The GeoTIFF image is a single-band image with grayscale values of night light intensities. The range of these values are between 0-60. Use `rescale='0,60'`.\n", - "2. The image has a nodata values stored as `nan`. Use `nodata='nan'`.\n", - "3. A grayscale image can be displayed in color using a colormap. Use `colormap_name=viridis`.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "sGUkRyUqjAUT", - "metadata": { - "id": "sGUkRyUqjAUT" - }, - "outputs": [], - "source": [ - "gcs_bucket = 'https://storage.googleapis.com/spatialthoughts-public-data/'\n", - "cog_url = os.path.join(gcs_bucket, 'viirs_ntl_2021_india.tif')" - ] - } - ], - "metadata": { - "colab": { - "provenance": [] - }, - "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.6" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} + "nbformat": 4, + "nbformat_minor": 5 +} \ No newline at end of file diff --git a/docs/python-dataviz-output/10_leafmap_basics.md b/docs/python-dataviz-output/10_leafmap_basics.md index b6eae242..63488525 100644 --- a/docs/python-dataviz-output/10_leafmap_basics.md +++ b/docs/python-dataviz-output/10_leafmap_basics.md @@ -1,6 +1,6 @@ ## Overview -[Leafmap](https://leafmap.org/) is a Python package for interactive mapping that supports a wide-variety of plotting backends. +[Leafmap](https://leafmap.org/) is a Python package for interactive mapping that supports a wide-variety of plotting backends. We will explore the capabilities of Leafmap and create a map that includes vector and raster layers. For a more comprehensive overview, check out [leafmap key Features](https://leafmap.org/notebooks/00_key_features/). @@ -63,7 +63,7 @@ m You can change the basemap to a Google basemap and set the center of the map. `leafmap.Map()` supports many arguments to customize the map and available controls. -References: +References: * [`leafmap.leafmap.Map`](https://leafmap.org/leafmap/#leafmap.leafmap.Map) * [`ipyleaflet.leaflet.Map`](https://ipyleaflet.readthedocs.io/en/latest/api_reference/index.html#ipyleaflet.leaflet.Map) @@ -188,6 +188,6 @@ You will need to specify additional `kwargs` parameters to create a correct visu ```python -gcs_bucket = 'https://storage.googleapis.com/spatialthoughts-public-data/' +gcs_bucket = 'https://storage.googleapis.com/spatialthoughts-public-data/ntl/viirs/' cog_url = os.path.join(gcs_bucket, 'viirs_ntl_2021_india.tif') ``` diff --git a/docs/python-dataviz.html b/docs/python-dataviz.html index 70d0b5c7..78e59023 100644 --- a/docs/python-dataviz.html +++ b/docs/python-dataviz.html @@ -2577,7 +2577,7 @@

Exercise

colormap_name=viridis.
gcs_bucket = 'https://storage.googleapis.com/spatialthoughts-public-data/'
+class="sourceCode python">gcs_bucket = 'https://storage.googleapis.com/spatialthoughts-public-data/ntl/viirs/'
 cog_url = os.path.join(gcs_bucket, 'viirs_ntl_2021_india.tif')
diff --git a/python-dataviz-output/10_leafmap_basics.md b/python-dataviz-output/10_leafmap_basics.md index b6eae242..63488525 100644 --- a/python-dataviz-output/10_leafmap_basics.md +++ b/python-dataviz-output/10_leafmap_basics.md @@ -1,6 +1,6 @@ ## Overview -[Leafmap](https://leafmap.org/) is a Python package for interactive mapping that supports a wide-variety of plotting backends. +[Leafmap](https://leafmap.org/) is a Python package for interactive mapping that supports a wide-variety of plotting backends. We will explore the capabilities of Leafmap and create a map that includes vector and raster layers. For a more comprehensive overview, check out [leafmap key Features](https://leafmap.org/notebooks/00_key_features/). @@ -63,7 +63,7 @@ m You can change the basemap to a Google basemap and set the center of the map. `leafmap.Map()` supports many arguments to customize the map and available controls. -References: +References: * [`leafmap.leafmap.Map`](https://leafmap.org/leafmap/#leafmap.leafmap.Map) * [`ipyleaflet.leaflet.Map`](https://ipyleaflet.readthedocs.io/en/latest/api_reference/index.html#ipyleaflet.leaflet.Map) @@ -188,6 +188,6 @@ You will need to specify additional `kwargs` parameters to create a correct visu ```python -gcs_bucket = 'https://storage.googleapis.com/spatialthoughts-public-data/' +gcs_bucket = 'https://storage.googleapis.com/spatialthoughts-public-data/ntl/viirs/' cog_url = os.path.join(gcs_bucket, 'viirs_ntl_2021_india.tif') ```