{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Region Selection and Map Preview with Ipyleaflet" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2023-08-02T15:51:17.932498228Z", "start_time": "2023-08-02T15:51:17.930490681Z" }, "execution": { "iopub.execute_input": "2024-10-16T17:31:56.485185Z", "iopub.status.busy": "2024-10-16T17:31:56.484527Z", "iopub.status.idle": "2024-10-16T17:31:57.170246Z", "shell.execute_reply": "2024-10-16T17:31:57.169505Z" } }, "outputs": [], "source": [ "# Import the necessary libraries to format, send, and parse our returned results\n", "import os\n", "\n", "import birdy\n", "import geopandas as gpd\n", "import ipyleaflet\n", "import ipywidgets" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If your `notebook` is version prior to `5.3`, you might need to run this command `jupyter nbextension enable --py --sys-prefix ipyleaflet`. For more information see https://ipyleaflet.readthedocs.io/en/latest/installation.html." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2023-08-02T15:51:18.340139930Z", "start_time": "2023-08-02T15:51:17.930716737Z" }, "execution": { "iopub.execute_input": "2024-10-16T17:31:57.172718Z", "iopub.status.busy": "2024-10-16T17:31:57.172260Z", "iopub.status.idle": "2024-10-16T17:31:57.478210Z", "shell.execute_reply": "2024-10-16T17:31:57.477670Z" } }, "outputs": [], "source": [ "# Create WPS instances\n", "# Set environment variable WPS_URL to \"http://localhost:9099\" to run on the default local server\n", "pavics_url = \"https://pavics.ouranos.ca\"\n", "raven_url = os.environ.get(\"WPS_URL\", f\"{pavics_url}/twitcher/ows/proxy/raven/wps\")\n", "\n", "raven = birdy.WPSClient(raven_url)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2023-08-02T15:51:18.387787911Z", "start_time": "2023-08-02T15:51:18.353245743Z" }, "execution": { "iopub.execute_input": "2024-10-16T17:31:57.480573Z", "iopub.status.busy": "2024-10-16T17:31:57.480342Z", "iopub.status.idle": "2024-10-16T17:31:57.491842Z", "shell.execute_reply": "2024-10-16T17:31:57.491263Z" } }, "outputs": [], "source": [ "# Build an interactive map with ipyleaflet\n", "\n", "initial_lat_lon = (48.63, -74.71)\n", "\n", "leaflet_map = ipyleaflet.Map(\n", " center=initial_lat_lon,\n", " basemap=ipyleaflet.basemaps.OpenTopoMap,\n", ")\n", "\n", "# Add a custom zoom slider\n", "zoom_slider = ipywidgets.IntSlider(description=\"Zoom level:\", min=1, max=10, value=6)\n", "ipywidgets.jslink((zoom_slider, \"value\"), (leaflet_map, \"zoom\"))\n", "widget_control1 = ipyleaflet.WidgetControl(widget=zoom_slider, position=\"topright\")\n", "leaflet_map.add_control(widget_control1)\n", "\n", "# Add a marker to the map\n", "marker = ipyleaflet.Marker(location=initial_lat_lon, draggable=True)\n", "leaflet_map.add_layer(marker)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2024-10-16T17:31:57.497744Z", "iopub.status.busy": "2024-10-16T17:31:57.497237Z", "iopub.status.idle": "2024-10-16T17:31:57.504395Z", "shell.execute_reply": "2024-10-16T17:31:57.503870Z" } }, "outputs": [], "source": [ "# Add an overlay widget\n", "\n", "html = ipywidgets.HTML(\"\"\"Hover over a feature!\"\"\")\n", "html.layout.margin = \"0px 10px 10px 10px\"\n", "\n", "control = ipyleaflet.WidgetControl(widget=html, position=\"bottomleft\")\n", "leaflet_map.add_control(control)\n", "\n", "\n", "def update_html(feature, **kwargs):\n", " html.value = \"\"\"\n", "
| \n", " | id | \n", "HYBAS_ID | \n", "NEXT_DOWN | \n", "NEXT_SINK | \n", "DIST_SINK | \n", "DIST_MAIN | \n", "SUB_AREA | \n", "UP_AREA | \n", "PFAF_ID | \n", "SIDE | \n", "LAKE | \n", "ENDO | \n", "COAST | \n", "ORDER | \n", "SORT | \n", "geometry | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "USGS_HydroBASINS_lake_na_lev12.99410 | \n", "7129001061 | \n", "7120323452 | \n", "7120034520 | \n", "517.6 | \n", "517.6 | \n", "8470.5 | \n", "8773.1 | \n", "725209301000 | \n", "L | \n", "56 | \n", "0 | \n", "0 | \n", "2 | \n", "99410 | \n", "POLYGON ((-75.1899 47.9954, -75.1819 47.9946, ... | \n", "