11 export image
Uncomment the following line to install geemap if needed.
In [ ]:
Copied!
# !pip install geemap
# !pip install geemap
In [ ]:
Copied!
import ee
import geemap
import os
import ee
import geemap
import os
In [ ]:
Copied!
geemap.show_youtube("_6JOA-iiEGU")
geemap.show_youtube("_6JOA-iiEGU")
In [ ]:
Copied!
Map = geemap.Map()
Map
Map = geemap.Map()
Map
Download an ee.Image¶
In [ ]:
Copied!
image = ee.Image("LANDSAT/LE7_TOA_5YEAR/1999_2003")
landsat_vis = {"bands": ["B4", "B3", "B2"], "gamma": 1.4}
Map.addLayer(image, landsat_vis, "LE7_TOA_5YEAR/1999_2003", True, 0.7)
image = ee.Image("LANDSAT/LE7_TOA_5YEAR/1999_2003")
landsat_vis = {"bands": ["B4", "B3", "B2"], "gamma": 1.4}
Map.addLayer(image, landsat_vis, "LE7_TOA_5YEAR/1999_2003", True, 0.7)
In [ ]:
Copied!
# Draw any shapes on the map using the Drawing tools before executing this code block
feature = Map.draw_last_feature
if feature is None:
geom = ee.Geometry.Polygon(
[
[
[-115.413031, 35.889467],
[-115.413031, 36.543157],
[-114.034328, 36.543157],
[-114.034328, 35.889467],
[-115.413031, 35.889467],
]
]
)
feature = ee.Feature(geom, {})
roi = feature.geometry()
# Draw any shapes on the map using the Drawing tools before executing this code block
feature = Map.draw_last_feature
if feature is None:
geom = ee.Geometry.Polygon(
[
[
[-115.413031, 35.889467],
[-115.413031, 36.543157],
[-114.034328, 36.543157],
[-114.034328, 35.889467],
[-115.413031, 35.889467],
]
]
)
feature = ee.Feature(geom, {})
roi = feature.geometry()
In [ ]:
Copied!
out_dir = os.path.join(os.path.expanduser("~"), "Downloads")
filename = os.path.join(out_dir, "landsat.tif")
out_dir = os.path.join(os.path.expanduser("~"), "Downloads")
filename = os.path.join(out_dir, "landsat.tif")
Exporting all bands as one single image¶
In [ ]:
Copied!
image = image.clip(roi).unmask()
geemap.ee_export_image(
image, filename=filename, scale=90, region=roi, file_per_band=False
)
image = image.clip(roi).unmask()
geemap.ee_export_image(
image, filename=filename, scale=90, region=roi, file_per_band=False
)
Exporting each band as one image¶
In [ ]:
Copied!
geemap.ee_export_image(
image, filename=filename, scale=90, region=roi, file_per_band=True
)
geemap.ee_export_image(
image, filename=filename, scale=90, region=roi, file_per_band=True
)
Export an image to Google Drive¶
In [ ]:
Copied!
geemap.ee_export_image_to_drive(
image, description="landsat", folder="export", region=roi, scale=30
)
geemap.ee_export_image_to_drive(
image, description="landsat", folder="export", region=roi, scale=30
)
Download an ee.ImageCollection¶
In [ ]:
Copied!
import ee
import geemap
import os
import ee
import geemap
import os
In [ ]:
Copied!
loc = ee.Geometry.Point(-99.2222, 46.7816)
collection = (
ee.ImageCollection("USDA/NAIP/DOQQ")
.filterBounds(loc)
.filterDate("2008-01-01", "2020-01-01")
.filter(ee.Filter.listContains("system:band_names", "N"))
)
loc = ee.Geometry.Point(-99.2222, 46.7816)
collection = (
ee.ImageCollection("USDA/NAIP/DOQQ")
.filterBounds(loc)
.filterDate("2008-01-01", "2020-01-01")
.filter(ee.Filter.listContains("system:band_names", "N"))
)
In [ ]:
Copied!
out_dir = os.path.join(os.path.expanduser("~"), "Downloads")
out_dir = os.path.join(os.path.expanduser("~"), "Downloads")
In [ ]:
Copied!
print(collection.aggregate_array("system:index").getInfo())
print(collection.aggregate_array("system:index").getInfo())
In [ ]:
Copied!
geemap.ee_export_image_collection(collection, out_dir=out_dir)
geemap.ee_export_image_collection(collection, out_dir=out_dir)
In [ ]:
Copied!
geemap.ee_export_image_collection_to_drive(collection, folder="export", scale=10)
geemap.ee_export_image_collection_to_drive(collection, folder="export", scale=10)
Extract pixels as a Numpy array¶
In [ ]:
Copied!
import ee
import geemap
import numpy as np
import matplotlib.pyplot as plt
img = ee.Image("LANDSAT/LC08/C01/T1_SR/LC08_038029_20180810").select(["B4", "B5", "B6"])
aoi = ee.Geometry.Polygon(
[[[-110.8, 44.7], [-110.8, 44.6], [-110.6, 44.6], [-110.6, 44.7]]], None, False
)
rgb_img = geemap.ee_to_numpy(img, region=aoi)
print(rgb_img.shape)
import ee
import geemap
import numpy as np
import matplotlib.pyplot as plt
img = ee.Image("LANDSAT/LC08/C01/T1_SR/LC08_038029_20180810").select(["B4", "B5", "B6"])
aoi = ee.Geometry.Polygon(
[[[-110.8, 44.7], [-110.8, 44.6], [-110.6, 44.6], [-110.6, 44.7]]], None, False
)
rgb_img = geemap.ee_to_numpy(img, region=aoi)
print(rgb_img.shape)
In [ ]:
Copied!
# Scale the data to [0, 255] to show as an RGB image.
# Adapted from https://bit.ly/2XlmQY8. Credits to Justin Braaten
rgb_img_test = (255 * ((rgb_img[:, :, 0:3] - 100) / 3500)).astype("uint8")
plt.imshow(rgb_img_test)
plt.show()
# Scale the data to [0, 255] to show as an RGB image.
# Adapted from https://bit.ly/2XlmQY8. Credits to Justin Braaten
rgb_img_test = (255 * ((rgb_img[:, :, 0:3] - 100) / 3500)).astype("uint8")
plt.imshow(rgb_img_test)
plt.show()