Skip to content

Commit

Permalink
Add image service layers to address jupyter-widgets#932 (jupyter-widg…
Browse files Browse the repository at this point in the history
…ets#933)

* Adding image service layers to address jupyter-widgets#932

* drop comments on imageservice options

* review updates

docs: add options to `format`, `pixel_type`, `no_data_interpretation` and `endpoint`
feat: add function for handling mouse clicks
refactor: remove columbia glacier example
remove transparency option (defunct)

* add whitespace to fix linting error

* update projection names following Beto's review

proj changes in notebook

* Fix proj for image service example

* JS lint fixes

* docstring edits for review comments
  • Loading branch information
tsutterley authored Oct 27, 2022
1 parent 7b71f20 commit aabb752
Show file tree
Hide file tree
Showing 10 changed files with 837 additions and 48 deletions.
33 changes: 33 additions & 0 deletions docs/source/layers/image_service.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Image Service
=============

Example
-------

.. jupyter-execute::

from ipyleaflet import Map, ImageService, basemaps

im = ImageService(
url='https://landsat.arcgis.com/arcgis/rest/services/Landsat/PS/ImageServer',
rendering_rule={"rasterFunction":"Pansharpened Enhanced with DRA"},
format='jpgpng',
attribution='United States Geological Survey (USGS), National Aeronautics and Space Administration (NASA)'
)

m = Map(basemap=basemaps.Esri.WorldTopoMap, center=(47.655548, -122.303200), zoom=12)

m.add(im)

m

Usage
-----

By default, options like ``format``, ``band_ids``, ``time``, ``rendering_rule`` are appended to the request URL when making the image service layer request.

Attributes
----------

.. autoclass:: ipyleaflet.leaflet.ImageService
:members:
1 change: 1 addition & 0 deletions docs/source/layers/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Layers
popup
wms_layer
image_video_overlay
image_service
antpath
polyline
polygon
Expand Down
66 changes: 56 additions & 10 deletions examples/CustomProjections.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
"source": [
"## New Built-In Projections\n",
"\n",
"ipyleaflet now supports custom map projections and includes 2 base layers for polar projections:\n",
"NASA's Next GenerationBlue Marble 500m for the Arctic and Antarctic regions."
"ipyleaflet now supports custom map projections and includes base layers for polar projections:\n",
"- NASA's Next Generation Blue Marble 500m for the Arctic and Antarctic regions\n",
"- Esri Arctic Ocean Basemap and Antarctic Basemap"
]
},
{
Expand Down Expand Up @@ -51,17 +52,62 @@
"dc = DrawControl(marker={\"shapeOptions\": {\"color\": \"#0000FF\"}})\n",
"dc.on_draw(handle_draw)\n",
"\n",
"# note that we need to use the same projection for the our layer and the map.\n",
"# note that we need to use the same projection for the layer and the map.\n",
"m1 = Map(\n",
" center=(90, 0),\n",
" zoom=0,\n",
" basemap=basemaps.NASAGIBS.BlueMarble3413,\n",
" crs=projections.EPSG3413,\n",
" crs=projections.EPSG3413.NASAGIBS,\n",
")\n",
"m1.add(dc)\n",
"m1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# note that we need to use the same projection for the layer and the map.\n",
"m2 = Map(\n",
" center=(-90, 0),\n",
" zoom=0,\n",
" basemap=basemaps.Esri.AntarcticBasemap,\n",
" crs=projections.EPSG3031.ESRIBasemap,\n",
")\n",
"\n",
"# add draw control on Antarctic map\n",
"dc2 = DrawControl(marker={\"shapeOptions\": {\"color\": \"#0000FF\"}})\n",
"dc2.on_draw(handle_draw)\n",
"m2.add(dc2)\n",
" \n",
"# MODIS Mosaic of Antarctica (MOA)\n",
"MOA3031 = dict(\n",
" name='EPSG:3031',\n",
" custom=True,\n",
" proj4def=\"\"\"+proj=stere +lat_0=-90 +lat_ts=-71 +lon_0=0 +k=1\n",
" +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs\"\"\",\n",
" bounds=[[-3174450,-2816050],[2867175,2406325]]\n",
")\n",
"\n",
"MOA = WMSLayer(\n",
" attribution=\"\"\"\n",
" U.S. Geological Survey (USGS), British Antarctic Survey (BAS),\n",
" National Aeronautics and Space Administration (NASA)\n",
" \"\"\",\n",
" layers=\"MOA_125_HP1_090_230\",\n",
" format='image/png',\n",
" transparent=False,\n",
" opacity=0.5,\n",
" url='https://nimbus.cr.usgs.gov/arcgis/services/Antarctica/USGS_EROS_Antarctica_Reference/MapServer/WmsServer',\n",
" crs=MOA3031\n",
")\n",
"m2.add(MOA)\n",
"\n",
"m2"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -100,15 +146,15 @@
" crs=my_projection, # I'm asking this WMS service to reproject the tile layer using EPSG:2163\n",
")\n",
"\n",
"m2 = Map(center=(40, -104), zoom=0, layers=(wms,), crs=my_projection)\n",
"m3 = Map(center=(40, -104), zoom=0, layers=(wms,), crs=my_projection)\n",
"\n",
"\n",
"dc2 = DrawControl(marker={\"shapeOptions\": {\"color\": \"#0000FF\"}})\n",
"dc2.on_draw(handle_draw)\n",
"dc3 = DrawControl(marker={\"shapeOptions\": {\"color\": \"#0000FF\"}})\n",
"dc3.on_draw(handle_draw)\n",
"\n",
"m2.add(dc2)\n",
"m3.add(dc3)\n",
"\n",
"m2"
"m3"
]
}
],
Expand All @@ -128,7 +174,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
"version": "3.10.4"
}
},
"nbformat": 4,
Expand Down
170 changes: 170 additions & 0 deletions examples/ImageService.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
{
"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",
"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(url=url,\n",
" format='jpgpng', rendering_rule=rendering_rule,\n",
" attribution='Esri, PGC, UMN, NSF, NGA, DigitalGlobe',\n",
" crs=projections.EPSG5936.ESRIBasemap)\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",
"# 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",
"# 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",
"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 = 'https://elevation2.arcgis.com/arcgis/rest/services/Polar/AntarcticDEM/ImageServer'\n",
"rendering_rule = {\"rasterFunction\": raster_dropdown2.value}\n",
"im2 = ImageService(url=url,\n",
" format='jpgpng', rendering_rule=rendering_rule,\n",
" attribution='Esri, PGC, UMN, NSF, NGA, DigitalGlobe',\n",
" crs=projections.EPSG3031.ESRIBasemap)\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",
"# 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",
"# 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
}
Loading

0 comments on commit aabb752

Please sign in to comment.