Skip to content

Commit

Permalink
Add interactive region reduction tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed Aug 16, 2020
1 parent c4f966b commit 436be2f
Show file tree
Hide file tree
Showing 3 changed files with 319 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ Below is a partial list of features available for the geemap package. Please che
* Importing Earth Engine assets from personal account.
* Publishing interactive GEE maps directly within Jupyter notebook.
* Adding local raster datasets (e.g., GeoTIFF) to the map.
* Performing image classification and accuracy assessment.
* Extracting pixel values interactively.


Installation
Expand Down Expand Up @@ -458,6 +460,20 @@ To get image descriptive statistics:
geemap.image_stats(image, region, scale)
To remove all user-drawn geometries:

.. code:: python
geemap.remove_drawn_features()
To extract pixel values based on user-drawn geometries:

.. code:: python
geemap.extract_values_to_points(out_shp)
Examples
--------

Expand Down
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ More video tutorials for geemap and Earth Engine are available on my [YouTube ch
31. [Machine Learning with Earth Engine - Unsupervised Classification](https://i.imgur.com/uNQfrFx.gif) ([video](https://youtu.be/k9MEy2awVJQ) | [gif](https://i.imgur.com/uNQfrFx.gif) | [notebook](https://github.com/giswqs/geemap/blob/master/examples/notebooks/31_unsupervised_classification.ipynb))
32. [Machine Learning with Earth Engine - Supervised Classification](https://i.imgur.com/jJ2Xiu6.gif) ([video](https://youtu.be/qWaEfgWi21o) | [gif](https://i.imgur.com/jJ2Xiu6.gif) | [notebook](https://github.com/giswqs/geemap/blob/master/examples/notebooks/32_supervised_classification.ipynb))
33. [Machine Learning with Earth Engine - Performing Accuracy Assessment for Image Classification](https://i.imgur.com/1JkIrF3.gif) ([video](https://youtu.be/JYptiw-I8dc) | [gif](https://i.imgur.com/1JkIrF3.gif) | [notebook](https://github.com/giswqs/geemap/blob/master/examples/notebooks/33_accuracy_assessment.ipynb))
34. [Interactive extraction of pixel values and interactive region reduction](https://i.imgur.com/aZa42GV.gif) (video | [gif](https://i.imgur.com/aZa42GV.gif) | [notebook](https://github.com/giswqs/geemap/blob/master/examples/notebooks/34_extract_values.ipynb))


### 1. Introducing the geemap Python package for interactive mapping with Google Earth Engine
Expand Down
302 changes: 302 additions & 0 deletions examples/notebooks/34_extract_values.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,302 @@
{
"cells": [
{
"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": {
"scrolled": false
},
"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.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": 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
}

0 comments on commit 436be2f

Please sign in to comment.