8000 Added extract values tutorial · giswqs/gee-tutorials@62affe3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 62affe3

Browse files
committed
Added extract values tutorial
1 parent 110cf58 commit 62affe3

File tree

3 files changed

+719
-0
lines changed

3 files changed

+719
-0
lines changed
Lines changed: 359 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,359 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"<a href=\"https://githubtocolab.com/giswqs/geemap/blob/master/examples/notebooks/extract_values.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open in Colab\"/></a>\n",
8+
"\n",
9+
"Uncomment the following line to install [geemap](https://geemap.org) if needed."
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": null,
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"# !pip install geemap"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": null,
24+
"metadata": {},
25+
"outputs": [],
26+
"source": [
27+
"# import geemap\n",
28+
"# geemap.update_package()"
29+
]
30+
},
31+
{
32+
"cell_type": "markdown",
33+
"metadata": {},
34+
"source": [
35+
"# Interactive extraction of pixel values and interactive region reduction"
36+
]
37+
},
38+
{
39+
"cell_type": "markdown",
40+
"metadata": {},
41+
"source": [
42+
"## Interactive extraction of pixel values"
43+
]
44+
},
45+
{
46+
"cell_type": "markdown",
47+
"metadata": {},
48+
"source": [
49+
"### Import libraries"
50+
]
51+
},
52+
{
53+
"cell_type": "code",
54+
"execution_count": null,
55+
"metadata": {},
56+
"outputs": [],
57+
"source": [
58+
"import os\n",
59+
"import ee\n",
60+
"import geemap"
61+
]
62+
},
63+
{
64+
"cell_type": "markdown",
65+
"metadata": {},
66+
"source": [
67+
"### Create an interactive map"
68+
]
69+
},
70+
{
71+
"cell_type": "code",
72+
"execution_count": null,
73+
"metadata": {},
74+
"outputs": [],
75+
"source": [
76+
"Map = geemap.Map()\n",
77+
"Map"
78+
]
79+
},
80+
{
81+
"cell_type": "markdown",
82+
"metadata": {},
83+
"source": [
84+
"### Add data to the map"
85+
]
86+
},
87+
{
88+
"cell_type": "code",
89+
"execution_count": null,
90+
"metadata": {},
91+
"outputs": [],
92+
"source": [
93+
"landsat7 = ee.Image('LE7_TOA_5YEAR/1999_2003') \\\n",
94+
" .select([0, 1, 2, 3, 4, 6])\n",
95+
"landsat_vis = {\n",
96+
" 'bands': ['B4', 'B3', 'B2'], \n",
97+
" 'gamma': 1.7\n",
98+
"}\n",
99+
"Map.addLayer(landsat7, landsat_vis, \"LE7_TOA_5YEAR/1999_2003\")\n",
100+
"\n",
101+
"Map.set_plot_options(add_marker_cluster=True)"
102+
]
103+
},
104+
{
105+
"cell_type": "markdown",
106+
"metadata": {},
107+
"source": [
108+
"### Activate the plotting tool\n",
109+
"\n",
110+
"Tick the `Plotting` checkbox and click the mouse on the map to start displaying charts."
111+
]
112+
},
113+
{
114+
"cell_type": "markdown",
115+
"metadata": {},
116+
"source": [
117+
"### Export pixel values to shapefile/csv"
118+
]
119+
},
120+
{
121+
"cell_type": "code",
122+
"execution_count": null,
123+
"metadata": {},
124+
"outputs": [],
125+
"source": [
126+
"out_dir = os.path.expanduser('~/Downloads')\n",
127+
"# out_csv = os.path.join(out_dir, 'points.csv')\n",
128+
"out_shp = os.path.join(out_dir, 'points.shp')"
129+
]
130+
},
131+
{
132+
"cell_type": "code",
133+
"execution_count": null,
134+
"metadata": {},
135+
"outputs": [],
136+
"source": [
137+
"Map.extract_values_to_points(out_shp)"
138+
]
139+
},
140+
{
141+
"cell_type": "markdown",
142+
"metadata": {},
143+
"source": [
144+
"## Interactive Region Reduction"
145+
]
146+
},
147+
{
148+
"cell_type": "markdown",
149+
"metadata": {},
150+
"source": [
151+
"### Import libraries"
152+
]
153+
},
154+
{
155+
"cell_type": "code",
156+
"execution_count": null,
157+
"metadata": {},
158+
"outputs": [],
159+
"source": [
160+
"import geemap.colormaps as cm"
161+
]
162+
},
163+
{
164+
"cell_type": "markdown",
165+
"metadata": {},
166+
"source": [
167+
"### Create an interactive map"
168+
]
169+
},
170+
{
171+
"cell_type": "code",
172+
"execution_count": null,
173+
"metadata": {},
174+
"outputs": [],
175+
"sour B94A ce": [
176+
"m = geemap.Map()"
177+
]
178+
},
179+
{
180+
"cell_type": "markdown",
181+
"metadata": {},
182+
"source": [
183+
"### Add add to the map"
184+
]
185+
},
186+
{
187+
"cell_type": "code",
188+
"execution_count": null,
189+
"metadata": {},
190+
"outputs": [],
191+
"source": [
192+
"collection = ee.ImageCollection('MODIS/006/MOD13A2') \\\n",
193+
" .filterDate('2015-01-01', '2019-12-31') \\\n",
194+
" .select('NDVI')\n",
195+
"\n",
196+
"# Convert the image collection to an image.\n",
197+
"image = collection.toBands()\n",
198+
"\n",
199+
"palette = cm.palettes.ndvi\n",
200+
"\n",
201+
"ndvi_vis = {\n",
202+
" 'min': 0.0,\n",
203+
" 'max': 9000.0,\n",
204+
" 'palette': palette\n",
205+
"}\n",
206+
"\n",
207+
"m.addLayer(image, {}, 'MODIS NDVI Time-series')\n",
208+
"m.addLayer(image.select(0), ndvi_vis, 'MODIS NDVI VIS')\n",
209+
"\n",
210+
"m"
211+
]
212+
},
213+
{
214+
"cell_type": "markdown",
215+
"metadata": {},
216+
"source": [
217+
"### Set reducer"
218+
]
219+
},
220+
{
221+
"cell_type": "code",
222+
"execution_count": null,
223+
"metadata": {},
224+
"outputs": [],
225+
"source": [
226+
"m.set_plot_options(add_marker_cluster=True, marker=None)\n",
227+
"m.roi_reducer = ee.Reducer.mean()"
228+
]
229+
},
230+
{
231+
"cell_type": "markdown",
232+
"metadata": {},
233+
"source": [
234+
"### Export data"
235+
]
236+
},
237+
{
238+
"cell_type": "code",
239+
"execution_count": null,
240+
"metadata": {},
241+
"outputs": [],
242+
"source": [
243+
"out_dir = os.path.expanduser('~/Downloads')\n",
244+
"# out_csv = os.path.join(out_dir, 'points.csv')\n",
245+
"out_shp = os.path.join(out_dir, 'ndvi.shp')\n",
246+
"m.extract_values_to_points(out_shp)"
247+
]
248+
},
249+
{
250+
"cell_type": "markdown",
251+
"metadata": {},
252+
"source": [
253+
"## Creating training samples"
254+
]
255+
},
256+
{
257+
"cell_type": "code",
258+
"execution_count": null,
259+
"metadata": {},
260+
"outputs": [],
261+
"source": [
262+
"import geemap"
263+
]
264+
},
265+
{
266+
"cell_type": "code",
267+
"execution_count": null,
268+
"metadata": {},
269+
"outputs": [],
270+
"source": [
271+
"geemap.show_youtube(\"https://youtu.be/VWh5PxXPZw0\")"
272+
]
273+
},
274+
{
275+
"cell_type": "code",
276+
"execution_count": null,
277+
"metadata": {},
278+
"outputs": [],
279+
"source": [
280+
"Map = geemap.Map()\n",
281+
"Map"
282+
]
283+
}
284+
],
285+
"metadata": {
286+
"_draft": {
287+
"nbviewer_url": "https://gist.github.com/3ebde541f34a1757035a67dee34939d0"
288+
},
289+
"gist": {
290+
"data": {
291+
"description": "extract values to points",
292+
"public": true
293+
},
294+
"id": "3ebde541f34a1757035a67dee34939d0"
295+
},
296+
"hide_input": false,
297+
"kernelspec": {
298+
"display_name": "Python 3",
299+
"language": "python",
300+
"name": "python3"
301+
},
302+
"language_info": {
303+
"codemirror_mode": {
304+
"name": "ipython",
305+
"version": 3
306+
},
307+
"file_extension": ".py",
308+
"mimetype": "text/x-python",
309+
"name": "python",
310+
"nbconvert_exporter": "python",
311+
"pygments_lexer": "ipython3",
312+
"version": "3.8.5"
313+
},
314+
"toc": {
315+
"base_numbering": 1,
316+
"nav_menu": {},
317+
"number_sections": true,
318+
"sideBar": true,
319+
"skip_h1_title": true,
320+
"title_cell": "Table of Contents",
321+
"title_sidebar": "Table of Contents",
322+
"toc_cell": false,
323+
"toc_position": {},
324+
"toc_section_display": true,
325+
"toc_window_display": false
326+
},
327+
"varInspector": {
328+
"cols": {
329+
"lenName": 16,
330+
"lenType": 16,
331+
"lenVar": 40
332+
},
333+
"kernels_config": {
334+
"python": {
335+
"delete_cmd_postfix": "",
336+
"delete_cmd_prefix": "del ",
337+
"library": "var_list.py",
338+
"varRefreshCmd": "print(var_dic_list())"
339+
},
340+
"r": {
341+
"delete_cmd_postfix": ") ",
342+
"delete_cmd_prefix": "rm(",
343+
"library": "var_list.r",
344+
"varRefreshCmd": "cat(var_dic_list()) "
345+
}
346+
},
347+
"types_to_exclude": [
348+
"module",
349+
"function",
350+
"builtin_function_or_method",
351+
"instance",
352+
"_Feature"
353+
],
354+
"window_display": false
355+
}
356+
},
357+
"nbformat": 4,
358+
"nbformat_minor": 4
359+
}

0 commit comments

Comments
 (0)
0