12 data export
In [1]:
Copied!
# !pip install geemap
# !pip install geemap
In [2]:
Copied!
import os
import ee
import geemap
import os
import ee
import geemap
In [3]:
Copied!
Map = geemap.Map()
Map = geemap.Map()
Exporting an ee.FeatureCollection¶
Add sample data to the map
In [4]:
Copied!
fc = ee.FeatureCollection('users/giswqs/public/countries')
fc = ee.FeatureCollection('users/giswqs/public/countries')
In [5]:
Copied!
Map.addLayer(fc, {}, "Countries")
Map.centerObject(fc)
Map
Map.addLayer(fc, {}, "Countries")
Map.centerObject(fc)
Map
Out[5]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Export data to a local computer.
In [6]:
Copied!
out_shp = "countries.shp"
geemap.ee_export_vector(fc, out_shp, verbose=True)
out_shp = "countries.shp"
geemap.ee_export_vector(fc, out_shp, verbose=True)
Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/tables/af2cd31629bab2fcc5007bd374c36321-8049ee6287656f4e191785facb8a3e7e:getFeatures Please wait ... Data downloaded to /home/runner/work/GEE-Courses/GEE-Courses/docs/geemap_intro/countries.shp
Export data to Google Drive
In [7]:
Copied!
geemap.ee_export_vector_to_drive(fc, description="countries", folder="export")
geemap.ee_export_vector_to_drive(fc, description="countries", folder="export")
Exporting countries...
Exporting an ee.Image¶
In [8]:
Copied!
image = ee.Image('LE7_TOA_5YEAR/1999_2003')
landsat_vis = {'bands': ['B4', 'B3', 'B2'], 'gamma': 1.7}
Map.addLayer(image, landsat_vis, "LE7_TOA_5YEAR/1999_2003", True, 1)
Map
image = ee.Image('LE7_TOA_5YEAR/1999_2003')
landsat_vis = {'bands': ['B4', 'B3', 'B2'], 'gamma': 1.7}
Map.addLayer(image, landsat_vis, "LE7_TOA_5YEAR/1999_2003", True, 1)
Map
Out[8]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [9]:
Copied!
filename = 'landsat.tif'
filename = 'landsat.tif'
Exporting all bands as one single image¶
In [10]:
Copied!
# set a default ROI
roi = ee.Geometry.Polygon(
[
[
[-482.643127, 37.547027],
[-482.643127, 37.996433],
[-481.908417, 37.996433],
[-481.908417, 37.547027],
[-482.643127, 37.547027],
]
]
)
# set a default ROI
roi = ee.Geometry.Polygon(
[
[
[-482.643127, 37.547027],
[-482.643127, 37.996433],
[-481.908417, 37.996433],
[-481.908417, 37.547027],
[-482.643127, 37.547027],
]
]
)
In [11]:
Copied!
# Draw any shapes on the map using the Drawing tools before executing this code block
if Map.user_roi is not None:
roi = Map.user_roi
# Draw any shapes on the map using the Drawing tools before executing this code block
if Map.user_roi is not None:
roi = Map.user_roi
In [12]:
Copied!
roi.getInfo()
roi.getInfo()
Out[12]:
{'type': 'Polygon', 'coordinates': [[[-482.643127, 37.547027], [-481.908417, 37.547027], [-481.908417, 37.996433], [-482.643127, 37.996433], [-482.643127, 37.547027]]]}
In [13]:
Copied!
image_clip = image.clip(roi)
image_clip = image.clip(roi)
In [14]:
Copied!
Map.addLayer(image_clip, landsat_vis, "image")
Map.addLayer(image_clip, landsat_vis, "image")
In [15]:
Copied!
geemap.ee_export_image(
image_clip, filename=filename, scale=90, region=roi, file_per_band=False
)
geemap.ee_export_image(
image_clip, filename=filename, scale=90, region=roi, file_per_band=False
)
Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/thumbnails/83a4ec0d21102c6b0b0fc3fcd9ab8d86-669afbc0de13a84124f92b49d5b4ad2f:getPixels Please wait ... Data downloaded to /home/runner/work/GEE-Courses/GEE-Courses/docs/geemap_intro/landsat.tif
Exporting each band as one image¶
In [16]:
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
)
Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/thumbnails/a39da6f090dceafbb1b3469419e5eee0-9eeaf59d55054118cc571d1de87892e6:getPixels Please wait ... Data downloaded to /home/runner/work/GEE-Courses/GEE-Courses/docs/geemap_intro
Export an image to Google Drive¶
In [17]:
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
)
Exporting landsat ...
Downloading an ee.ImageCollection¶
In [18]:
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 [19]:
Copied!
out_dir = os.getcwd()
out_dir = os.getcwd()
In [20]:
Copied!
collection.aggregate_array('system:index').getInfo()
collection.aggregate_array('system:index').getInfo()
Out[20]:
['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 [21]:
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-07c16b21398fca461324efb76b681fe8:getPixels Please wait ... Data downloaded to /home/runner/work/GEE-Courses/GEE-Courses/docs/geemap_intro/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-349231caf91a793ff8e9afe8ea858dc7:getPixels Please wait ... Data downloaded to /home/runner/work/GEE-Courses/GEE-Courses/docs/geemap_intro/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-2b7a46fb1a18b660851526db4a9d2a3c:getPixels Please wait ... Data downloaded to /home/runner/work/GEE-Courses/GEE-Courses/docs/geemap_intro/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-bd0ae83a4fdce8803457da47c390baf1:getPixels Please wait ... Data downloaded to /home/runner/work/GEE-Courses/GEE-Courses/docs/geemap_intro/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-06f8e51ed090c31bb70e0c794818fbb5:getPixels Please wait ... Data downloaded to /home/runner/work/GEE-Courses/GEE-Courses/docs/geemap_intro/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-61ecec1d693332306bfb29cf692509e8:getPixels Please wait ... Data downloaded to /home/runner/work/GEE-Courses/GEE-Courses/docs/geemap_intro/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-a1ffb4e1ef4b892f7ea6d5614a2ac73f:getPixels Please wait ... Data downloaded to /home/runner/work/GEE-Courses/GEE-Courses/docs/geemap_intro/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-50540b614a60057bbc22a8fda1375cd2:getPixels Please wait ... Data downloaded to /home/runner/work/GEE-Courses/GEE-Courses/docs/geemap_intro/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-be8e33aa6680eac105650335f2043629:getPixels Please wait ... Data downloaded to /home/runner/work/GEE-Courses/GEE-Courses/docs/geemap_intro/m_4609915_sw_14_h_20170703.tif
In [22]:
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
Extract pixels as a Numpy array¶
In [23]:
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 [24]:
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-25