{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", " \n", " \n", " \n", "
View source on GitHubNotebook Viewer Run in Google Colab
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Install Earth Engine API and geemap\n", "Install the [Earth Engine Python API](https://developers.google.com/earth-engine/python_install) and [geemap](https://github.com/giswqs/geemap). The **geemap** Python package is built upon the [ipyleaflet](https://github.com/jupyter-widgets/ipyleaflet) and [folium](https://github.com/python-visualization/folium) packages and implements several methods for interacting with Earth Engine data layers, such as `Map.addLayer()`, `Map.setCenter()`, and `Map.centerObject()`. The following script checks if the geemap package has been installed. If not, it will install geemap, which automatically installs its [dependencies](https://github.com/giswqs/geemap#dependencies), including earthengine-api, folium, and ipyleaflet." ] }, { "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\n", "import geemap" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create an interactive map \n", "The default basemap is `Google Satellite`. [Additional basemaps](https://github.com/giswqs/geemap/blob/master/geemap/basemaps.py) can be added using the `Map.add_basemap()` function. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map(center=[40,-100], zoom=4)\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Add Earth Engine Python script " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Add Earth Engine dataset\n", "image = ee.Image('USGS/SRTMGL1_003')\n", "\n", "# Set visualization parameters.\n", "vis_params = {\n", " 'min': 0,\n", " 'max': 4000,\n", " 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']}\n", "\n", "# Print the elevation of Mount Everest.\n", "xy = ee.Geometry.Point([86.9250, 27.9881])\n", "elev = image.sample(xy, 30).first().get('elevation').getInfo()\n", "print('Mount Everest elevation (m):', elev)\n", "\n", "# Add Earth Engine layers to Map\n", "Map.addLayer(image, vis_params, 'DEM')\n", "Map.addLayer(xy, {'color': 'red'}, 'Mount Everest')\n", "\n", "# Center the map based on an Earth Engine object or coordinates (longitude, latitude)\n", "# Map.centerObject(xy, 4)\n", "Map.setCenter(86.9250, 27.9881, 4)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Display Earth Engine data layers " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.addLayerControl() # This line is not needed for ipyleaflet-based Map.\n", "Map" ] } ], "metadata": { "anaconda-cloud": {}, "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.8.2" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": true, "title_cell": "Table of Contents", "title_sidebar": "Table of Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": true } }, "nbformat": 4, "nbformat_minor": 1 }