11 export image
Uncomment the following line to install geemap if needed.
In [1]:
                Copied!
                
                
            # !pip install geemap
# !pip install geemap
    
        In [2]:
                Copied!
                
                
            import ee
import geemap
import os
import ee
import geemap
import os
    
        In [3]:
                Copied!
                
                
            geemap.show_youtube('_6JOA-iiEGU')
geemap.show_youtube('_6JOA-iiEGU')
    
        In [4]:
                Copied!
                
                
            Map = geemap.Map()
Map
Map = geemap.Map()
Map
    
        Out[4]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Download an ee.Image¶
In [5]:
                Copied!
                
                
            image = ee.Image('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('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 [6]:
                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()
    
        --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Input In [6], in <cell line: 2>() 1 # Draw any shapes on the map using the Drawing tools before executing this code block ----> 2 feature = Map.draw_last_feature 4 if feature is None: 5 geom = ee.Geometry.Polygon( 6 [ 7 [ (...) 14 ] 15 ) AttributeError: 'Map' object has no attribute 'draw_last_feature'
In [7]:
                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 [8]:
                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
)
    
        --------------------------------------------------------------------------- NameError Traceback (most recent call last) Input In [8], in <cell line: 1>() ----> 1 image = image.clip(roi).unmask() 2 geemap.ee_export_image( 3 image, filename=filename, scale=90, region=roi, file_per_band=False 4 ) NameError: name 'roi' is not defined
Exporting each band as one image¶
In [9]:
                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
)
    
        --------------------------------------------------------------------------- NameError Traceback (most recent call last) Input In [9], in <cell line: 1>() 1 geemap.ee_export_image( ----> 2 image, filename=filename, scale=90, region=roi, file_per_band=True 3 ) NameError: name 'roi' is not defined
Export an image to Google Drive¶
In [10]:
                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
)
    
        --------------------------------------------------------------------------- NameError Traceback (most recent call last) Input In [10], in <cell line: 1>() 1 geemap.ee_export_image_to_drive( ----> 2 image, description='landsat', folder='export', region=roi, scale=30 3 ) NameError: name 'roi' is not defined
Download an ee.ImageCollection¶
In [11]:
                Copied!
                
                
            import ee
import geemap
import os
import ee
import geemap
import os
    
        In [12]:
                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 [13]:
                Copied!
                
                
            out_dir = os.path.join(os.path.expanduser('~'), 'Downloads')
out_dir = os.path.join(os.path.expanduser('~'), 'Downloads')
    
        In [14]:
                Copied!
                
                
            print(collection.aggregate_array('system:index').getInfo())
print(collection.aggregate_array('system:index').getInfo())
    
        ['m_4609915_sw_14_060_20180902_20181213', 'm_4609915_sw_14_060_20190626', 'm_4609915_sw_14_1_20090818', 'm_4609915_sw_14_1_20100629', 'm_4609915_sw_14_1_20120714', 'm_4609915_sw_14_1_20140901', 'm_4609915_sw_14_1_20150926', 'm_4609915_sw_14_h_20160704', 'm_4609915_sw_14_h_20170703']
In [15]:
                Copied!
                
                
            geemap.ee_export_image_collection(collection, out_dir=out_dir)
geemap.ee_export_image_collection(collection, out_dir=out_dir)
    
        Total number of images: 9 Exporting 1/9: m_4609915_sw_14_060_20180902_20181213.tif Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/thumbnails/12dba27394c3260fc731c0d6229e43a5-1f9a41aef58cf0e622de9d85acf9c7e6:getPixels Please wait ... Data downloaded to /home/runner/Downloads/m_4609915_sw_14_060_20180902_20181213.tif Exporting 2/9: m_4609915_sw_14_060_20190626.tif Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/thumbnails/a05dd6d80c920403e8f1f943da8c4174-eb70099d715f762a64f3e0c0c4ae41ec:getPixels Please wait ... Data downloaded to /home/runner/Downloads/m_4609915_sw_14_060_20190626.tif Exporting 3/9: m_4609915_sw_14_1_20090818.tif Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/thumbnails/e0218e3dbca864608a201086538782b5-f26f5b0822788ee35a0fd56df35354c6:getPixels Please wait ... Data downloaded to /home/runner/Downloads/m_4609915_sw_14_1_20090818.tif Exporting 4/9: m_4609915_sw_14_1_20100629.tif Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/thumbnails/e8b801d6cba914811034b6a836fa64e8-d5fc124451cd48e90f361379b4b14936:getPixels Please wait ... Data downloaded to /home/runner/Downloads/m_4609915_sw_14_1_20100629.tif Exporting 5/9: m_4609915_sw_14_1_20120714.tif Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/thumbnails/a2835ac668b547edc38f2c74320168d8-a2b1a57a78d17bc65fbd3aa801ffcd60:getPixels Please wait ... Data downloaded to /home/runner/Downloads/m_4609915_sw_14_1_20120714.tif Exporting 6/9: m_4609915_sw_14_1_20140901.tif Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/thumbnails/dfc26d0ec2aa00709a488938a348c954-e73d016056cd6871a7e8a05eddf6b15c:getPixels Please wait ... Data downloaded to /home/runner/Downloads/m_4609915_sw_14_1_20140901.tif Exporting 7/9: m_4609915_sw_14_1_20150926.tif Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/thumbnails/a3f09592597bb46998d6ca0905a1b1e2-111a580ef56e6144ab0a221a1e08115d:getPixels Please wait ... Data downloaded to /home/runner/Downloads/m_4609915_sw_14_1_20150926.tif Exporting 8/9: m_4609915_sw_14_h_20160704.tif Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/thumbnails/0df29ebae58261ebc7edbe5743f785f7-adb67269077f54cf80989d57b233edf5:getPixels Please wait ... Data downloaded to /home/runner/Downloads/m_4609915_sw_14_h_20160704.tif Exporting 9/9: m_4609915_sw_14_h_20170703.tif Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/thumbnails/b8e7221f77039b3b23cd347962c1a654-aaf9b0d060c56f5d212b028ebf6bc037:getPixels Please wait ... Data downloaded to /home/runner/Downloads/m_4609915_sw_14_h_20170703.tif
In [16]:
                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)
    
        Total number of images: 9 Exporting m_4609915_sw_14_060_20180902_20181213 ... Exporting m_4609915_sw_14_060_20190626 ... Exporting m_4609915_sw_14_1_20090818 ... Exporting m_4609915_sw_14_1_20100629 ... Exporting m_4609915_sw_14_1_20120714 ... Exporting m_4609915_sw_14_1_20140901 ... Exporting m_4609915_sw_14_1_20150926 ... Exporting m_4609915_sw_14_h_20160704 ... Exporting m_4609915_sw_14_h_20170703 ...
Extract pixels as a Numpy array¶
In [17]:
                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)
    
        (373, 531, 3)
In [18]:
                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()
    
        
  
    
      Last update:
      2022-03-14