{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Using an Image Service\n", "\n", "This notebook shows how you can overlay images from an ESRI Image Server on a Leaflet map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from ipywidgets import Dropdown\n", "from ipyleaflet import (\n", " Map,\n", " basemaps,\n", " basemap_to_tiles,\n", " ImageService,\n", " projections,\n", " WidgetControl,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# ArcticDEM\n", "# note that we need to use the same projection for the image service layer and the map.\n", "m1 = Map(\n", " center=(90, 0),\n", " zoom=4,\n", " basemap=basemaps.Esri.ArcticOceanBase,\n", " crs=projections.EPSG5936.ESRIBasemap,\n", ")\n", "# add arctic ocean reference basemap\n", "tl1 = basemap_to_tiles(basemaps.Esri.ArcticOceanReference)\n", "m1.add(tl1)\n", "\n", "# create a widget control for the raster function\n", "raster_functions = [\n", " \"Aspect Map\",\n", " \"Contour 25\",\n", " \"Hillshade Elevation Tinted\",\n", " \"Hillshade Gray\",\n", " \"Height Ellipsoidal\",\n", " \"Height Orthometric\",\n", " \"Slope Map\",\n", "]\n", "raster_dropdown1 = Dropdown(\n", " value=raster_functions[3],\n", " options=raster_functions,\n", " description=\"Raster:\",\n", ")\n", "\n", "# add image service layer with ArcticDEM\n", "url = \"https://elevation2.arcgis.com/arcgis/rest/services/Polar/ArcticDEM/ImageServer\"\n", "rendering_rule = {\"rasterFunction\": raster_dropdown1.value}\n", "im1 = ImageService(\n", " url=url,\n", " format=\"jpgpng\",\n", " rendering_rule=rendering_rule,\n", " attribution=\"Esri, PGC, UMN, NSF, NGA, DigitalGlobe\",\n", " crs=projections.EPSG5936.ESRIBasemap,\n", ")\n", "m1.add(im1)\n", "\n", "# add control for raster function\n", "widget_control1 = WidgetControl(widget=raster_dropdown1, position=\"topright\")\n", "m1.add(widget_control1)\n", "\n", "\n", "# set the rendering rule\n", "def set_raster_function1(sender):\n", " im1.rendering_rule = {\"rasterFunction\": raster_dropdown1.value}\n", " # force redrawing of map by removing and adding layer\n", " m1.remove(im1)\n", " m1.add(im1)\n", "\n", "\n", "# watch raster function widget for changes\n", "raster_dropdown1.observe(set_raster_function1)\n", "m1" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Reference Elevation Model of Antarctica (REMA)\n", "# note that we need to use the same projection for the image service layer and the map.\n", "m2 = Map(\n", " center=(-90, 0),\n", " zoom=3,\n", " basemap=basemaps.Esri.AntarcticBasemap,\n", " crs=projections.EPSG3031.ESRIBasemap,\n", ")\n", "\n", "# create a widget control for the raster function\n", "raster_functions = [\n", " \"Aspect Map\",\n", " \"Contour 25\",\n", " \"Hillshade Elevation Tinted\",\n", " \"Hillshade Gray\",\n", " \"Height Orthometric\",\n", " \"Slope Degrees Map\",\n", "]\n", "raster_dropdown2 = Dropdown(\n", " value=raster_functions[3],\n", " options=raster_functions,\n", " description=\"Raster:\",\n", ")\n", "\n", "# add image service layer with REMA imagery\n", "url = (\n", " \"https://elevation2.arcgis.com/arcgis/rest/services/Polar/AntarcticDEM/ImageServer\"\n", ")\n", "rendering_rule = {\"rasterFunction\": raster_dropdown2.value}\n", "im2 = ImageService(\n", " url=url,\n", " format=\"jpgpng\",\n", " rendering_rule=rendering_rule,\n", " attribution=\"Esri, PGC, UMN, NSF, NGA, DigitalGlobe\",\n", " crs=projections.EPSG3031.ESRIBasemap,\n", ")\n", "m2.add(im2)\n", "\n", "# add control for raster function\n", "widget_control2 = WidgetControl(widget=raster_dropdown2, position=\"topright\")\n", "m2.add(widget_control2)\n", "\n", "\n", "# set the rendering rule\n", "def set_raster_function2(sender):\n", " im2.rendering_rule = {\"rasterFunction\": raster_dropdown2.value}\n", " # force redrawing of map by removing and adding layer\n", " m2.remove(im2)\n", " m2.add(im2)\n", "\n", "\n", "# watch raster function widget for changes\n", "raster_dropdown2.observe(set_raster_function2)\n", "m2" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.4" } }, "nbformat": 4, "nbformat_minor": 4 }