Uncomment the following line to install geemap if needed.
In [ ]:
Copied!
# !pip install geemap
# !pip install geemap
Interactive extraction of pixel values and interactive region reduction¶
Interactive extraction of pixel values¶
Import libraries¶
In [ ]:
Copied!
import os
import ee
import geemap
import os
import ee
import geemap
Create an interactive map¶
In [ ]:
Copied!
Map = geemap.Map()
Map
Map = geemap.Map()
Map
Add data to the map¶
In [ ]:
Copied!
landsat7 = ee.Image("LANDSAT/LE7_TOA_5YEAR/1999_2003").select([0, 1, 2, 3, 4, 6])
landsat_vis = {"bands": ["B4", "B3", "B2"], "gamma": 1.4}
Map.addLayer(landsat7, landsat_vis, "LE7_TOA_5YEAR/1999_2003")
Map.set_plot_options(add_marker_cluster=True)
landsat7 = ee.Image("LANDSAT/LE7_TOA_5YEAR/1999_2003").select([0, 1, 2, 3, 4, 6])
landsat_vis = {"bands": ["B4", "B3", "B2"], "gamma": 1.4}
Map.addLayer(landsat7, landsat_vis, "LE7_TOA_5YEAR/1999_2003")
Map.set_plot_options(add_marker_cluster=True)
Activate the plotting tool¶
Tick the Plotting
checkbox and click the mouse on the map to start displaying charts.
Export pixel values to shapefile/csv¶
In [ ]:
Copied!
out_dir = os.path.join(os.path.expanduser("~"), "Downloads")
# out_csv = os.path.join(out_dir, 'points.csv')
out_shp = os.path.join(out_dir, "points.shp")
out_dir = os.path.join(os.path.expanduser("~"), "Downloads")
# out_csv = os.path.join(out_dir, 'points.csv')
out_shp = os.path.join(out_dir, "points.shp")
In [ ]:
Copied!
Map.extract_values_to_points(out_shp)
Map.extract_values_to_points(out_shp)
Interactive Region Reduction¶
Import libraries¶
In [ ]:
Copied!
import os
import ee
import geemap
import os
import ee
import geemap
Create an interactive map¶
In [ ]:
Copied!
m = geemap.Map()
m = geemap.Map()
Add add to the map¶
In [ ]:
Copied!
collection = (
ee.ImageCollection("MODIS/006/MOD13A2")
.filterDate("2015-01-01", "2019-12-31")
.select("NDVI")
)
# Convert the image collection to an image.
image = collection.toBands()
ndvi_vis = {
"min": 0.0,
"max": 9000.0,
"palette": [
"FFFFFF",
"CE7E45",
"DF923D",
"F1B555",
"FCD163",
"99B718",
"74A901",
"66A000",
"529400",
"3E8601",
"207401",
"056201",
"004C00",
"023B01",
"012E01",
"011D01",
"011301",
],
}
m.addLayer(image, {}, "MODIS NDVI Time-series")
m.addLayer(image.select(0), ndvi_vis, "MODIS NDVI VIS")
m
collection = (
ee.ImageCollection("MODIS/006/MOD13A2")
.filterDate("2015-01-01", "2019-12-31")
.select("NDVI")
)
# Convert the image collection to an image.
image = collection.toBands()
ndvi_vis = {
"min": 0.0,
"max": 9000.0,
"palette": [
"FFFFFF",
"CE7E45",
"DF923D",
"F1B555",
"FCD163",
"99B718",
"74A901",
"66A000",
"529400",
"3E8601",
"207401",
"056201",
"004C00",
"023B01",
"012E01",
"011D01",
"011301",
],
}
m.addLayer(image, {}, "MODIS NDVI Time-series")
m.addLayer(image.select(0), ndvi_vis, "MODIS NDVI VIS")
m
Set reducer¶
In [ ]:
Copied!
m.set_plot_options(add_marker_cluster=True, marker=None)
m.roi_reducer = ee.Reducer.mean()
m.set_plot_options(add_marker_cluster=True, marker=None)
m.roi_reducer = ee.Reducer.mean()
Export data¶
In [ ]:
Copied!
out_dir = os.path.join(os.path.expanduser("~"), "Downloads")
# out_csv = os.path.join(out_dir, 'points.csv')
out_shp = os.path.join(out_dir, "ndvi.shp")
m.extract_values_to_points(out_shp)
out_dir = os.path.join(os.path.expanduser("~"), "Downloads")
# out_csv = os.path.join(out_dir, 'points.csv')
out_shp = os.path.join(out_dir, "ndvi.shp")
m.extract_values_to_points(out_shp)