Skip to content

Commit aabb752

Browse files
authored
Add image service layers to address #932 (#933)
* Adding image service layers to address #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
1 parent 7b71f20 commit aabb752

File tree

10 files changed

+837
-48
lines changed

10 files changed

+837
-48
lines changed

docs/source/layers/image_service.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Image Service
2+
=============
3+
4+
Example
5+
-------
6+
7+
.. jupyter-execute::
8+
9+
from ipyleaflet import Map, ImageService, basemaps
10+
11+
im = ImageService(
12+
url='https://landsat.arcgis.com/arcgis/rest/services/Landsat/PS/ImageServer',
13+
rendering_rule={"rasterFunction":"Pansharpened Enhanced with DRA"},
14+
format='jpgpng',
15+
attribution='United States Geological Survey (USGS), National Aeronautics and Space Administration (NASA)'
16+
)
17+
18+
m = Map(basemap=basemaps.Esri.WorldTopoMap, center=(47.655548, -122.303200), zoom=12)
19+
20+
m.add(im)
21+
22+
m
23+
24+
Usage
25+
-----
26+
27+
By default, options like ``format``, ``band_ids``, ``time``, ``rendering_rule`` are appended to the request URL when making the image service layer request.
28+
29+
Attributes
30+
----------
31+
32+
.. autoclass:: ipyleaflet.leaflet.ImageService
33+
:members:

docs/source/layers/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Layers
1414
popup
1515
wms_layer
1616
image_video_overlay
17+
image_service
1718
antpath
1819
polyline
1920
polygon

examples/CustomProjections.ipynb

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
"source": [
77
"## New Built-In Projections\n",
88
"\n",
9-
"ipyleaflet now supports custom map projections and includes 2 base layers for polar projections:\n",
10-
"NASA's Next GenerationBlue Marble 500m for the Arctic and Antarctic regions."
9+
"ipyleaflet now supports custom map projections and includes base layers for polar projections:\n",
10+
"- NASA's Next Generation Blue Marble 500m for the Arctic and Antarctic regions\n",
11+
"- Esri Arctic Ocean Basemap and Antarctic Basemap"
1112
]
1213
},
1314
{
@@ -51,17 +52,62 @@
5152
"dc = DrawControl(marker={\"shapeOptions\": {\"color\": \"#0000FF\"}})\n",
5253
"dc.on_draw(handle_draw)\n",
5354
"\n",
54-
"# note that we need to use the same projection for the our layer and the map.\n",
55+
"# note that we need to use the same projection for the layer and the map.\n",
5556
"m1 = Map(\n",
5657
" center=(90, 0),\n",
5758
" zoom=0,\n",
5859
" basemap=basemaps.NASAGIBS.BlueMarble3413,\n",
59-
" crs=projections.EPSG3413,\n",
60+
" crs=projections.EPSG3413.NASAGIBS,\n",
6061
")\n",
6162
"m1.add(dc)\n",
6263
"m1"
6364
]
6465
},
66+
{
67+
"cell_type": "code",
68+
"execution_count": null,
69+
"metadata": {},
70+
"outputs": [],
71+
"source": [
72+
"# note that we need to use the same projection for the layer and the map.\n",
73+
"m2 = Map(\n",
74+
" center=(-90, 0),\n",
75+
" zoom=0,\n",
76+
" basemap=basemaps.Esri.AntarcticBasemap,\n",
77+
" crs=projections.EPSG3031.ESRIBasemap,\n",
78+
")\n",
79+
"\n",
80+
"# add draw control on Antarctic map\n",
81+
"dc2 = DrawControl(marker={\"shapeOptions\": {\"color\": \"#0000FF\"}})\n",
82+
"dc2.on_draw(handle_draw)\n",
83+
"m2.add(dc2)\n",
84+
" \n",
85+
"# MODIS Mosaic of Antarctica (MOA)\n",
86+
"MOA3031 = dict(\n",
87+
" name='EPSG:3031',\n",
88+
" custom=True,\n",
89+
" proj4def=\"\"\"+proj=stere +lat_0=-90 +lat_ts=-71 +lon_0=0 +k=1\n",
90+
" +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs\"\"\",\n",
91+
" bounds=[[-3174450,-2816050],[2867175,2406325]]\n",
92+
")\n",
93+
"\n",
94+
"MOA = WMSLayer(\n",
95+
" attribution=\"\"\"\n",
96+
" U.S. Geological Survey (USGS), British Antarctic Survey (BAS),\n",
97+
" National Aeronautics and Space Administration (NASA)\n",
98+
" \"\"\",\n",
99+
" layers=\"MOA_125_HP1_090_230\",\n",
100+
" format='image/png',\n",
101+
" transparent=False,\n",
102+
" opacity=0.5,\n",
103+
" url='https://nimbus.cr.usgs.gov/arcgis/services/Antarctica/USGS_EROS_Antarctica_Reference/MapServer/WmsServer',\n",
104+
" crs=MOA3031\n",
105+
")\n",
106+
"m2.add(MOA)\n",
107+
"\n",
108+
"m2"
109+
]
110+
},
65111
{
66112
"cell_type": "markdown",
67113
"metadata": {},
@@ -100,15 +146,15 @@
100146
" crs=my_projection, # I'm asking this WMS service to reproject the tile layer using EPSG:2163\n",
101147
")\n",
102148
"\n",
103-
"m2 = Map(center=(40, -104), zoom=0, layers=(wms,), crs=my_projection)\n",
149+
"m3 = Map(center=(40, -104), zoom=0, layers=(wms,), crs=my_projection)\n",
104150
"\n",
105151
"\n",
106-
"dc2 = DrawControl(marker={\"shapeOptions\": {\"color\": \"#0000FF\"}})\n",
107-
"dc2.on_draw(handle_draw)\n",
152+
"dc3 = DrawControl(marker={\"shapeOptions\": {\"color\": \"#0000FF\"}})\n",
153+
"dc3.on_draw(handle_draw)\n",
108154
"\n",
109-
"m2.add(dc2)\n",
155+
"m3.add(dc3)\n",
110156
"\n",
111-
"m2"
157+
"m3"
112158
]
113159
}
114160
],
@@ -128,7 +174,7 @@
128174
"name": "python",
129175
"nbconvert_exporter": "python",
130176
"pygments_lexer": "ipython3",
131-
"version": "3.10.5"
177+
"version": "3.10.4"
132178
}
133179
},
134180
"nbformat": 4,

examples/ImageService.ipynb

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
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

Comments
 (0)