Skip to content

Commit 61543e5

Browse files
committed
Updated notebooks (docs)
1 parent e23c3ef commit 61543e5

File tree

2 files changed

+354
-285
lines changed

2 files changed

+354
-285
lines changed

docs/notebooks/49_split_control.ipynb

+85
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,98 @@
130130
"m.split_map(left_layer, right_layer)\n",
131131
"m"
132132
]
133+
},
134+
{
135+
"cell_type": "markdown",
136+
"id": "30e269ce",
137+
"metadata": {},
138+
"source": [
139+
"**Using xarrays**"
140+
]
141+
},
142+
{
143+
"cell_type": "markdown",
144+
"id": "5d01d145",
145+
"metadata": {},
146+
"source": [
147+
"Download a sample dataset."
148+
]
149+
},
150+
{
151+
"cell_type": "code",
152+
"execution_count": null,
153+
"id": "11de8d33",
154+
"metadata": {},
155+
"outputs": [],
156+
"source": [
157+
"import leafmap\n",
158+
"url = \"https://open.gishub.org/data/raster/srtm90.tif\"\n",
159+
"dem = leafmap.download_file(url, \"srtm90.tif\")"
160+
]
161+
},
162+
{
163+
"cell_type": "markdown",
164+
"id": "c95ed0f5",
165+
"metadata": {},
166+
"source": [
167+
"Use rioxarray to read the raster as a xarray DataArray and then classify the DEM into 2 elevation classes. "
168+
]
169+
},
170+
{
171+
"cell_type": "code",
172+
"execution_count": null,
173+
"id": "f0022a80",
174+
"metadata": {},
175+
"outputs": [],
176+
"source": [
177+
"import rioxarray\n",
178+
"import xarray as xr\n",
179+
"dem_ds = rioxarray.open_rasterio(dem)\n",
180+
"dem_class = xr.where(dem_ds<2000, 0, 1)"
181+
]
182+
},
183+
{
184+
"cell_type": "markdown",
185+
"id": "4718a9f1",
186+
"metadata": {},
187+
"source": [
188+
"Visualize the DEM and the elevation class image as a split map."
189+
]
190+
},
191+
{
192+
"cell_type": "code",
193+
"execution_count": null,
194+
"id": "40018a15",
195+
"metadata": {},
196+
"outputs": [],
197+
"source": [
198+
"import leafmap # ipyleaflet \n",
199+
"m = leafmap.Map(center=[37.6,-119], zoom=9)\n",
200+
"m.split_map(dem_ds, dem_class,\n",
201+
" left_args={\"layer_name\":\"DEM\", \"colormap\": \"terrain\"},\n",
202+
" right_args={\"layer_name\":\"Classified DEM\",\"colormap\": \"coolwarm\"}\n",
203+
" )\n",
204+
"m"
205+
]
133206
}
134207
],
135208
"metadata": {
136209
"kernelspec": {
137210
"display_name": "Python 3",
138211
"language": "python",
139212
"name": "python3"
213+
},
214+
"language_info": {
215+
"codemirror_mode": {
216+
"name": "ipython",
217+
"version": 3
218+
},
219+
"file_extension": ".py",
220+
"mimetype": "text/x-python",
221+
"name": "python",
222+
"nbconvert_exporter": "python",
223+
"pygments_lexer": "ipython3",
224+
"version": "3.11.7"
140225
}
141226
},
142227
"nbformat": 4,

0 commit comments

Comments
 (0)