{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/gee-community/geemap/blob/master/examples/notebooks/92_plotly.ipynb)\n", "[![image](https://mybinder.org/badge_logo.svg)](https://gishub.org/geemap-binder)\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": [ "import ee\n", "import geemap.plotlymap as geemap" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you are using a recently implemented geema feature that has not yet been released to PyPI or conda-forge, you can uncomment the following line to install the development version from GitHub." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# geemap.update_package()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you run into an error saying \"FigureWidget - 'mapbox._derived' Value Error\" ([source](https://github.com/plotly/plotly.py/issues/2570#issuecomment-738735816)), uncomment the following line and run it." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# geemap.fix_widget_error()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create an interactive map using default settings." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Change default setting when creating a map. \n", "\n", " Can be one of string from \"open-street-map\", \"carto-positron\", \"carto-darkmatter\", \"stamen-terrain\", \"stamen-toner\" or \"stamen-watercolor\" ." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(center=(40, -100), zoom=3, basemap=\"stamen-terrain\", height=500)\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Set map center and zoom level." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(basemap=\"stamen-watercolor\")\n", "m.set_center(lat=20, lon=0, zoom=2)\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Print out available basemaps." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.basemaps.keys()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add a basemap." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m.add_basemap(\"OpenTopoMap\")\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add XYZ tile layer." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "tile_url = \"https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}\"\n", "m.add_tile_layer(tile_url, name=\"Google Satellite\", attribution=\"Google\", opacity=1.0)\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add a mapbox tile layer. You will need a mapbox token. The map style can be Can be \"basic\", \"streets\", \"outdoors\", \"light\", \"dark\", \"satellite\", or \"satellite-streets\"." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# os.environ[\"MAPBOX_TOKEN\"] = \"your-mapbox-token\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m.add_mapbox_layer(style=\"streets\")\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Remove the modebar in the upper-right corner." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(basemap=\"stamen-toner\")\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m.clear_controls()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add more buttons to the modebar." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(basemap=\"carto-positron\")\n", "controls = [\n", " 'drawline',\n", " 'drawopenpath',\n", " 'drawclosedpath',\n", " 'drawcircle',\n", " 'drawrect',\n", " 'eraseshape',\n", "]\n", "m.add_controls(controls)\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add Cloud Optimized GeoTIFF." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "url = 'https://opendata.digitalglobe.com/events/california-fire-2020/pre-event/2018-02-16/pine-gulch-fire20/1030010076004E00.tif'\n", "m.add_cog_layer(url, name=\"Fire (pre-event)\")\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add a STAC item via HTTP URL." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "url = 'https://canada-spot-ortho.s3.amazonaws.com/canada_spot_orthoimages/canada_spot5_orthoimages/S5_2007/S5_11055_6057_20070622/S5_11055_6057_20070622.json'\n", "m.add_stac_layer(url, bands=['B3', 'B2', 'B1'], name='False color')\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add a STAC item from Microsoft Planetary Computer." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "collection = \"landsat-8-c2-l2\"\n", "item = \"LC08_L2SP_047027_20201204_02_T1\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m.add_stac_layer(\n", " collection=collection,\n", " item=item,\n", " bands=[\"SR_B7\", \"SR_B5\", \"SR_B4\"],\n", " titiler_endpoint=\"pc\",\n", ")\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add a heat map." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "url = 'https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv'" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(basemap=\"stamen-terrain\")\n", "m.add_heatmap(\n", " url, latitude=\"Latitude\", longitude=\"Longitude\", z=\"Magnitude\", name=\"Earthquake\"\n", ")\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add a choropleth map." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "url = \"https://raw.githubusercontent.com/gee-community/geemap/master/examples/data/countries.geojson\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(basemap=\"stamen-terrain\")\n", "m.add_choropleth_map(url, name=\"Pop\", z=\"POP_EST\", colorscale=\"Viridis\")\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add Earth Engine layers." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m.add_basemap(\"HYBRID\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Add Earth Engine dataset\n", "dem = ee.Image('USGS/SRTMGL1_003')\n", "landsat7 = ee.Image('LANDSAT/LE7_TOA_5YEAR/1999_2003').select(\n", " ['B1', 'B2', 'B3', 'B4', 'B5', 'B7']\n", ")\n", "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", "\n", "# Set visualization parameters.\n", "vis_params = {\n", " 'min': 0,\n", " 'max': 4000,\n", " 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5'],\n", "}\n", "\n", "# Add Earth Engine layers to Map\n", "m.addLayer(dem, vis_params, 'SRTM DEM', True, 0.5)\n", "m.addLayer(\n", " landsat7,\n", " {'bands': ['B4', 'B3', 'B2'], 'min': 20, 'max': 200, 'gamma': 2.0},\n", " 'Landsat 7',\n", ")\n", "m.addLayer(states, {}, \"US States\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](https://i.imgur.com/KH8jGFF.gif)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 }