{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\"Open\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 geemap" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Installs geemap package\n", "import subprocess\n", "\n", "try:\n", " import geemap\n", "except ImportError:\n", " print('geemap package not installed. Installing ...')\n", " subprocess.check_call([\"python\", '-m', 'pip', 'install', 'geemap'])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ee" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import geemap\n", "from ipyleaflet import *\n", "from ipywidgets import *\n", "from geemap.utils import *\n", "\n", "Map = geemap.Map(center=(-100, 40), zoom=4)\n", "Map.default_style = {'cursor': 'pointer'}\n", "Map\n", "\n", "Map.setOptions('ROADMAP')\n", "# Load National Hydrography Dataset (NHD)\n", "HUC10 = ee.FeatureCollection('USGS/WBD/2017/HUC10')\n", "# 18,487 HUC10 watersheds in the U.S.\n", "\n", "# Add HUC layer to the map\n", "Map.setCenter(-99.00, 47.01, 8)\n", "Map.addLayer(\n", " ee.Image().paint(HUC10, 0, 1), {}, 'HUC-10 Watershed'\n", ") # HUC10 for the entire U.S.\n", "\n", "label = Label(\"Click on the map to select a watershed\")\n", "widget_control = WidgetControl(widget=label, position='bottomright')\n", "Map.add_control(widget_control)\n", "\n", "layer = None\n", "\n", "\n", "def handle_interaction(**kwargs):\n", " latlon = kwargs.get('coordinates')\n", " if kwargs.get('type') == 'click':\n", " Map.default_style = {'cursor': 'wait'}\n", " xy = ee.Geometry.Point(latlon[::-1])\n", " watershed = HUC10.filterBounds(xy)\n", " huc10_id = watershed.first().get('huc10').getInfo()\n", " Map.layers = Map.layers[:3]\n", " Map.addLayer(\n", " ee.Image().paint(watershed, 0, 2), {'palette': 'red'}, 'HUC ID: ' + huc10_id\n", " )\n", "\n", " NAIP_images = find_NAIP(watershed)\n", " first_image = ee.Image(NAIP_images.toList(5).get(0))\n", " Map.addLayer(first_image, {'bands': ['N', 'R', 'G']}, 'first image')\n", " count = NAIP_images.size().getInfo()\n", " for i in range(0, count):\n", " image = ee.Image(NAIP_images.toList(count).get(i))\n", " Map.addLayer(image, {'bands': ['N', 'R', 'G']}, str(i))\n", "\n", " Map.default_style = {'cursor': 'pointer'}\n", "\n", "\n", "Map.on_interaction(handle_interaction)\n", "\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.layers" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 }