{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\"Open\n", "\n", "**Developing interactive web apps with gradio and leafmap**\n", "\n", "Uncomment the following line to install [geemap](https://geemap.org) if needed." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# !pip install -U geemap gradio" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ee\n", "import gradio as gr\n", "import geemap.foliumap as geemap" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map(center=[21.79, 70.87], zoom=3)\n", "image = ee.Image('USGS/SRTMGL1_003')\n", "vis_params = {\n", " 'min': 0,\n", " 'max': 6000,\n", " 'palette': 'terrain',\n", "}\n", "Map.addLayer(image, vis_params, 'SRTM')\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Visualize an Earth Engine layer." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def viz_dem(vmin, vmax, palette):\n", " Map = geemap.Map()\n", " image = ee.Image('USGS/SRTMGL1_003')\n", " vis_params = {\n", " 'min': vmin,\n", " 'max': vmax,\n", " 'palette': palette,\n", " }\n", " Map.addLayer(image, vis_params, 'SRTM')\n", " return Map.to_gradio()\n", "\n", "\n", "vmin = gr.Number(value=0, label=\"Min value\")\n", "vmax = gr.Number(value=6000, label=\"Max value\")\n", "palette = gr.Textbox(value=\"terrain\", label=\"Palette\")\n", "title = 'Visualize Earth Engine Data'\n", "demo = gr.Interface(viz_dem, [vmin, vmax, palette], \"html\", title=title)\n", "demo.launch()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Visualize Earth Engine layers side by side." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def split(left, right):\n", " Map = geemap.Map(center=(40, -100), zoom=4, height=600)\n", "\n", " nlcd_left = ee.Image(f'USGS/NLCD_RELEASES/2019_REL/NLCD/{left}').select('landcover')\n", " nlcd_right = ee.Image(f'USGS/NLCD_RELEASES/2019_REL/NLCD/{right}').select(\n", " 'landcover'\n", " )\n", "\n", " left_layer = geemap.ee_tile_layer(nlcd_left, {}, f'NLCD {left}')\n", " right_layer = geemap.ee_tile_layer(nlcd_right, {}, f'NLCD {right}')\n", "\n", " Map.split_map(\n", " left_layer,\n", " right_layer,\n", " )\n", " return Map.to_gradio()\n", "\n", "\n", "left_input = gr.Textbox(value='2001', label=\"Left Layer URL\")\n", "right_input = gr.Textbox(value='2019', label=\"Right Layer URL\")\n", "\n", "title = 'Visualizing National Land Cover Database (NLCD)'\n", "demo = gr.Interface(split, [left_input, right_input], \"html\", title=title)\n", "demo.launch()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Visualize Cloud Optimized GeoTIFF (COG)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def split(left, right):\n", " Map = geemap.Map(center=[21.79, 70.87], zoom=3)\n", " Map.split_map(left, right)\n", " print(Map.options[\"layersControl\"])\n", " return Map.to_gradio()\n", "\n", "\n", "left_url = 'https://opendata.digitalglobe.com/events/california-fire-2020/pre-event/2018-02-16/pine-gulch-fire20/1030010076004E00.tif'\n", "right_url = 'https://opendata.digitalglobe.com/events/california-fire-2020/post-event/2020-08-14/pine-gulch-fire20/10300100AAC8DD00.tif'\n", "left_input = gr.Textbox(value=left_url, label=\"Left Layer URL\")\n", "right_input = gr.Textbox(value=right_url, label=\"Right Layer URL\")\n", "title = 'Visualze Cloud Optimized GeoTIFF (COG)'\n", "demo = gr.Interface(split, [left_input, right_input], \"html\", title=title)\n", "demo.launch()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 }