Skip to content

Commit

Permalink
Layers as xarray.DataArray in split_map (ipyleaflet Map) (#681)
Browse files Browse the repository at this point in the history
* Get crs and transform from rio accessor

* Updated notebook (xarray section)

* Layers as xarray in leafmap.Map.split_map

* Updated notebook

* Updated notebooks (docs)

* Added array support for folium split_map

* Updated notebook

* Ignore notebook 83 execution

* Enable split map dragging

* Add error handling for compute_view

---------

Co-authored-by: Qiusheng Wu <[email protected]>
  • Loading branch information
lopezvoliver and giswqs authored Feb 14, 2024
1 parent 2442b1f commit 6370630
Show file tree
Hide file tree
Showing 7 changed files with 513 additions and 304 deletions.
83 changes: 83 additions & 0 deletions docs/notebooks/49_split_control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"outputs": [],
"source": [
"import folium\n",
"import rioxarray\n",
"import xarray as xr\n",
"import leafmap.foliumap as leafmap"
]
},
Expand Down Expand Up @@ -130,13 +132,94 @@
"m.split_map(left_layer, right_layer)\n",
"m"
]
},
{
"cell_type": "markdown",
"id": "30e269ce",
"metadata": {},
"source": [
"**Using xarrays**"
]
},
{
"cell_type": "markdown",
"id": "5d01d145",
"metadata": {},
"source": [
"Download a sample dataset."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "11de8d33",
"metadata": {},
"outputs": [],
"source": [
"url = \"https://open.gishub.org/data/raster/srtm90.tif\"\n",
"dem = leafmap.download_file(url, \"srtm90.tif\")"
]
},
{
"cell_type": "markdown",
"id": "c95ed0f5",
"metadata": {},
"source": [
"Use rioxarray to read the raster as a xarray DataArray and then classify the DEM into 2 elevation classes. "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f0022a80",
"metadata": {},
"outputs": [],
"source": [
"dem_ds = rioxarray.open_rasterio(dem)\n",
"dem_class = xr.where(dem_ds<2000, 0, 1)"
]
},
{
"cell_type": "markdown",
"id": "4718a9f1",
"metadata": {},
"source": [
"Visualize the DEM and the elevation class image as a split map."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "40018a15",
"metadata": {},
"outputs": [],
"source": [
"m = leafmap.Map(center=[37.6,-119], zoom=9)\n",
"m.split_map(dem_ds, dem_class,\n",
" left_args={\"layer_name\":\"DEM\", \"colormap\": \"terrain\"},\n",
" right_args={\"layer_name\":\"Classified DEM\",\"colormap\": \"coolwarm\"}\n",
" )\n",
"m"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.11.7"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 6370630

Please sign in to comment.