{ "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('LE7_TOA_5YEAR/1999_2003') \\\n", " .select([0, 1, 2, 3, 4, 6])\n", "landsat_vis = {\n", " 'bands': ['B4', 'B3', 'B2'], \n", " 'gamma': 1.4\n", "}\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 = ee.ImageCollection('MODIS/006/MOD13A2') \\\n", " .filterDate('2015-01-01', '2019-12-31') \\\n", " .select('NDVI')\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', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',\n", " '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',\n", " '012E01', '011D01', '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": { "_draft": { "nbviewer_url": "https://gist.github.com/3ebde541f34a1757035a67dee34939d0" }, "gist": { "data": { "description": "extract values to points", "public": true }, "id": "3ebde541f34a1757035a67dee34939d0" }, "hide_input": false, "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.5" }, "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": false }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }