{ "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": "markdown", "metadata": {}, "source": [ "# Interactive extraction of pixel values and interactive region reduction" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Interactive extraction of pixel values" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Import libraries" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "import ee\n", "import geemap" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Create an interactive map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Add data to the map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "landsat7 = ee.Image('LANDSAT/LE7_TOA_5YEAR/1999_2003').select([0, 1, 2, 3, 4, 6])\n", "landsat_vis = {'bands': ['B4', 'B3', 'B2'], 'gamma': 1.4}\n", "Map.addLayer(landsat7, landsat_vis, \"LE7_TOA_5YEAR/1999_2003\")\n", "\n", "Map.set_plot_options(add_marker_cluster=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Activate the plotting tool\n", "\n", "Tick the `Plotting` checkbox and click the mouse on the map to start displaying charts." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Export pixel values to shapefile/csv" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "out_dir = os.path.join(os.path.expanduser('~'), 'Downloads')\n", "# out_csv = os.path.join(out_dir, 'points.csv')\n", "out_shp = os.path.join(out_dir, 'points.shp')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.extract_values_to_points(out_shp)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Interactive Region Reduction" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Import libraries" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "import ee\n", "import geemap" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Create an interactive map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Add add to the map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "collection = (\n", " ee.ImageCollection('MODIS/006/MOD13A2')\n", " .filterDate('2015-01-01', '2019-12-31')\n", " .select('NDVI')\n", ")\n", "\n", "# Convert the image collection to an image.\n", "image = collection.toBands()\n", "\n", "ndvi_vis = {\n", " 'min': 0.0,\n", " 'max': 9000.0,\n", " 'palette': [\n", " 'FFFFFF',\n", " 'CE7E45',\n", " 'DF923D',\n", " 'F1B555',\n", " 'FCD163',\n", " '99B718',\n", " '74A901',\n", " '66A000',\n", " '529400',\n", " '3E8601',\n", " '207401',\n", " '056201',\n", " '004C00',\n", " '023B01',\n", " '012E01',\n", " '011D01',\n", " '011301',\n", " ],\n", "}\n", "\n", "m.addLayer(image, {}, 'MODIS NDVI Time-series')\n", "m.addLayer(image.select(0), ndvi_vis, 'MODIS NDVI VIS')\n", "\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Set reducer" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m.set_plot_options(add_marker_cluster=True, marker=None)\n", "m.roi_reducer = ee.Reducer.mean()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Export data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "out_dir = os.path.join(os.path.expanduser('~'), 'Downloads')\n", "# out_csv = os.path.join(out_dir, 'points.csv')\n", "out_shp = os.path.join(out_dir, 'ndvi.shp')\n", "m.extract_values_to_points(out_shp)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 }