|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "## Using an Image Service\n", |
| 8 | + "\n", |
| 9 | + "This notebook shows how you can overlay images from an ESRI Image Server on a Leaflet map" |
| 10 | + ] |
| 11 | + }, |
| 12 | + { |
| 13 | + "cell_type": "code", |
| 14 | + "execution_count": null, |
| 15 | + "metadata": {}, |
| 16 | + "outputs": [], |
| 17 | + "source": [ |
| 18 | + "from ipywidgets import Dropdown\n", |
| 19 | + "from ipyleaflet import (\n", |
| 20 | + " Map,\n", |
| 21 | + " basemaps,\n", |
| 22 | + " basemap_to_tiles,\n", |
| 23 | + " ImageService,\n", |
| 24 | + " projections,\n", |
| 25 | + " WidgetControl\n", |
| 26 | + ")" |
| 27 | + ] |
| 28 | + }, |
| 29 | + { |
| 30 | + "cell_type": "code", |
| 31 | + "execution_count": null, |
| 32 | + "metadata": {}, |
| 33 | + "outputs": [], |
| 34 | + "source": [ |
| 35 | + "# ArcticDEM\n", |
| 36 | + "# note that we need to use the same projection for the image service layer and the map.\n", |
| 37 | + "m1 = Map(\n", |
| 38 | + " center=(90, 0),\n", |
| 39 | + " zoom=4,\n", |
| 40 | + " basemap=basemaps.Esri.ArcticOceanBase,\n", |
| 41 | + " crs=projections.EPSG5936.ESRIBasemap,\n", |
| 42 | + ")\n", |
| 43 | + "# add arctic ocean reference basemap\n", |
| 44 | + "tl1 = basemap_to_tiles(basemaps.Esri.ArcticOceanReference)\n", |
| 45 | + "m1.add(tl1)\n", |
| 46 | + "\n", |
| 47 | + "# create a widget control for the raster function\n", |
| 48 | + "raster_functions = [\n", |
| 49 | + " \"Aspect Map\",\n", |
| 50 | + " \"Contour 25\",\n", |
| 51 | + " \"Hillshade Elevation Tinted\",\n", |
| 52 | + " \"Hillshade Gray\",\n", |
| 53 | + " \"Height Ellipsoidal\",\n", |
| 54 | + " \"Height Orthometric\",\n", |
| 55 | + " \"Slope Map\"]\n", |
| 56 | + "raster_dropdown1 = Dropdown(\n", |
| 57 | + " value=raster_functions[3],\n", |
| 58 | + " options=raster_functions,\n", |
| 59 | + " description=\"Raster:\",\n", |
| 60 | + ")\n", |
| 61 | + "\n", |
| 62 | + "# add image service layer with ArcticDEM\n", |
| 63 | + "url = 'https://elevation2.arcgis.com/arcgis/rest/services/Polar/ArcticDEM/ImageServer'\n", |
| 64 | + "rendering_rule = {\"rasterFunction\": raster_dropdown1.value}\n", |
| 65 | + "im1 = ImageService(url=url,\n", |
| 66 | + " format='jpgpng', rendering_rule=rendering_rule,\n", |
| 67 | + " attribution='Esri, PGC, UMN, NSF, NGA, DigitalGlobe',\n", |
| 68 | + " crs=projections.EPSG5936.ESRIBasemap)\n", |
| 69 | + "m1.add(im1) \n", |
| 70 | + "\n", |
| 71 | + "# add control for raster function\n", |
| 72 | + "widget_control1 = WidgetControl(widget=raster_dropdown1, position=\"topright\")\n", |
| 73 | + "m1.add(widget_control1)\n", |
| 74 | + "\n", |
| 75 | + "# set the rendering rule\n", |
| 76 | + "def set_raster_function1(sender):\n", |
| 77 | + " im1.rendering_rule = {\"rasterFunction\": raster_dropdown1.value}\n", |
| 78 | + " # force redrawing of map by removing and adding layer\n", |
| 79 | + " m1.remove(im1)\n", |
| 80 | + " m1.add(im1)\n", |
| 81 | + "\n", |
| 82 | + "# watch raster function widget for changes\n", |
| 83 | + "raster_dropdown1.observe(set_raster_function1)\n", |
| 84 | + "m1" |
| 85 | + ] |
| 86 | + }, |
| 87 | + { |
| 88 | + "cell_type": "code", |
| 89 | + "execution_count": null, |
| 90 | + "metadata": {}, |
| 91 | + "outputs": [], |
| 92 | + "source": [ |
| 93 | + "# Reference Elevation Model of Antarctica (REMA)\n", |
| 94 | + "# note that we need to use the same projection for the image service layer and the map.\n", |
| 95 | + "m2 = Map(\n", |
| 96 | + " center=(-90, 0),\n", |
| 97 | + " zoom=3,\n", |
| 98 | + " basemap=basemaps.Esri.AntarcticBasemap,\n", |
| 99 | + " crs=projections.EPSG3031.ESRIBasemap,\n", |
| 100 | + ")\n", |
| 101 | + "\n", |
| 102 | + "# create a widget control for the raster function\n", |
| 103 | + "raster_functions = [\n", |
| 104 | + " \"Aspect Map\",\n", |
| 105 | + " \"Contour 25\",\n", |
| 106 | + " \"Hillshade Elevation Tinted\",\n", |
| 107 | + " \"Hillshade Gray\",\n", |
| 108 | + " \"Height Orthometric\",\n", |
| 109 | + " \"Slope Degrees Map\"]\n", |
| 110 | + "raster_dropdown2 = Dropdown(\n", |
| 111 | + " value=raster_functions[3],\n", |
| 112 | + " options=raster_functions,\n", |
| 113 | + " description=\"Raster:\",\n", |
| 114 | + ")\n", |
| 115 | + "\n", |
| 116 | + "# add image service layer with REMA imagery\n", |
| 117 | + "url = 'https://elevation2.arcgis.com/arcgis/rest/services/Polar/AntarcticDEM/ImageServer'\n", |
| 118 | + "rendering_rule = {\"rasterFunction\": raster_dropdown2.value}\n", |
| 119 | + "im2 = ImageService(url=url,\n", |
| 120 | + " format='jpgpng', rendering_rule=rendering_rule,\n", |
| 121 | + " attribution='Esri, PGC, UMN, NSF, NGA, DigitalGlobe',\n", |
| 122 | + " crs=projections.EPSG3031.ESRIBasemap)\n", |
| 123 | + "m2.add(im2)\n", |
| 124 | + "\n", |
| 125 | + "# add control for raster function\n", |
| 126 | + "widget_control2 = WidgetControl(widget=raster_dropdown2, position=\"topright\")\n", |
| 127 | + "m2.add(widget_control2)\n", |
| 128 | + "\n", |
| 129 | + "# set the rendering rule\n", |
| 130 | + "def set_raster_function2(sender):\n", |
| 131 | + " im2.rendering_rule = {\"rasterFunction\": raster_dropdown2.value}\n", |
| 132 | + " # force redrawing of map by removing and adding layer\n", |
| 133 | + " m2.remove(im2)\n", |
| 134 | + " m2.add(im2)\n", |
| 135 | + "\n", |
| 136 | + "# watch raster function widget for changes\n", |
| 137 | + "raster_dropdown2.observe(set_raster_function2)\n", |
| 138 | + "m2" |
| 139 | + ] |
| 140 | + }, |
| 141 | + { |
| 142 | + "cell_type": "code", |
| 143 | + "execution_count": null, |
| 144 | + "metadata": {}, |
| 145 | + "outputs": [], |
| 146 | + "source": [] |
| 147 | + } |
| 148 | + ], |
| 149 | + "metadata": { |
| 150 | + "kernelspec": { |
| 151 | + "display_name": "Python 3 (ipykernel)", |
| 152 | + "language": "python", |
| 153 | + "name": "python3" |
| 154 | + }, |
| 155 | + "language_info": { |
| 156 | + "codemirror_mode": { |
| 157 | + "name": "ipython", |
| 158 | + "version": 3 |
| 159 | + }, |
| 160 | + "file_extension": ".py", |
| 161 | + "mimetype": "text/x-python", |
| 162 | + "name": "python", |
| 163 | + "nbconvert_exporter": "python", |
| 164 | + "pygments_lexer": "ipython3", |
| 165 | + "version": "3.10.4" |
| 166 | + } |
| 167 | + }, |
| 168 | + "nbformat": 4, |
| 169 | + "nbformat_minor": 4 |
| 170 | +} |
0 commit comments