{ "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/91_planetary_computer.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 geemap" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you are using a recently implemented geemap 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": [ "Add a STAC item via an HTTP URL" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "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'" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.stac_assets(url)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.stac_bounds(url)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.stac_center(url)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# geemap.stac_info(url)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# geemap.stac_stats(url)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m.add_stac_layer(url, bands=[\"B3\", \"B2\", \"B1\"])\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add a Microsoft Planetry Computer STAC item. The titiler endpoint can set in one of the ways below:\n", "\n", "```\n", "os.environ[\"TITILER_ENDPOINT\"] = \"planetary-computer\"\n", "titiler_endpoint=\"pc\"\n", "titiler_endpoint=\"planetary-computer\"\n", "```" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# import os\n", "# os.environ[\"TITILER_ENDPOINT\"] = \"planetary-computer\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "collection = \"landsat-8-c2-l2\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "items = \"LC08_L2SP_047027_20201204_02_T1\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.stac_assets(collection=collection, items=items, titiler_endpoint=\"pc\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.stac_bounds(collection=collection, items=items)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.stac_info(collection=collection, items=items, assets=\"SR_B7\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.stac_stats(collection=collection, items=items, assets=\"SR_B7\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Color infrared composite." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m.add_stac_layer(\n", " collection=collection,\n", " items=items,\n", " assets=\"SR_B5,SR_B4,SR_B3\",\n", " name=\"Color infrared\",\n", ")\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "False color composite." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m.add_stac_layer(\n", " collection=collection, items=items, assets=\"SR_B7,SR_B5,SR_B4\", name=\"False color\"\n", ")\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Calculate NDVI." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.stac_stats(\n", " collection=collection,\n", " items=items,\n", " expression=\"(SR_B5-SR_B4)/(SR_B5+SR_B4)\",\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m.add_stac_layer(\n", " collection=collection,\n", " items=items,\n", " expression=\"(SR_B5-SR_B4)/(SR_B5+SR_B4)\",\n", " name=\"NDVI\",\n", ")\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Calculate NDVI and add a colormap. See available colormaps at https://planetarycomputer.microsoft.com/docs/reference/data/" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m.add_stac_layer(\n", " collection=collection,\n", " items=items,\n", " assets=\"SR_B5,SR_B4,SR_B3\",\n", " name=\"Color infrared\",\n", ")\n", "m.add_stac_layer(\n", " collection=collection,\n", " items=items,\n", " expression=\"(SR_B5-SR_B4)/(SR_B5+SR_B4)\",\n", " colormap_name=\"greens\",\n", " name=\"NDVI Green\",\n", ")\n", "m" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 }