Uncomment the following line to install geemap if needed.
In [1]:
Copied!
# !pip install geemap
# !pip install geemap
Google Earth Engine Python Tutorials¶
- GitHub: https://github.com/giswqs/geemap
- Notebook examples: https://github.com/giswqs/geemap/blob/master/examples/README.md#tutorials
- Video tutorials: https://www.youtube.com/playlist?list=PLAxJ4-o7ZoPccOFv1dCwvGI6TYnirRTg3
Tutorial 21 - How to export Earth Engine maps as HTML and images
Import libraries¶
In [2]:
Copied!
import ee
import geemap
import ee
import geemap
Video tutorial on YouTube¶
In [3]:
Copied!
geemap.show_youtube('h0pz3S6Tvx0')
geemap.show_youtube('h0pz3S6Tvx0')
In [4]:
Copied!
# geemap.update_package()
# geemap.update_package()
Create an interactive map¶
In [5]:
Copied!
Map = geemap.Map(toolbar_ctrl=True, layer_ctrl=True)
Map
Map = geemap.Map(toolbar_ctrl=True, layer_ctrl=True)
Map
Out[5]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [6]:
Copied!
# Add Earth Engine dataset
dem = ee.Image('USGS/SRTMGL1_003')
landcover = ee.Image("ESA/GLOBCOVER_L4_200901_200912_V2_3").select('landcover')
landsat7 = ee.Image('LE7_TOA_5YEAR/1999_2003')
states = ee.FeatureCollection("TIGER/2018/States")
# Set visualization parameters.
vis_params = {
'min': 0,
'max': 4000,
'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5'],
}
# Add Earth Engine layers to Map
Map.addLayer(dem, vis_params, 'SRTM DEM', True, 0.5)
Map.addLayer(landcover, {}, 'Land cover')
Map.addLayer(
landsat7,
{'bands': ['B4', 'B3', 'B2'], 'min': 20, 'max': 200, 'gamma': 1.5},
'Landsat 7',
)
Map.addLayer(states, {}, "US States")
# Add Earth Engine dataset
dem = ee.Image('USGS/SRTMGL1_003')
landcover = ee.Image("ESA/GLOBCOVER_L4_200901_200912_V2_3").select('landcover')
landsat7 = ee.Image('LE7_TOA_5YEAR/1999_2003')
states = ee.FeatureCollection("TIGER/2018/States")
# Set visualization parameters.
vis_params = {
'min': 0,
'max': 4000,
'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5'],
}
# Add Earth Engine layers to Map
Map.addLayer(dem, vis_params, 'SRTM DEM', True, 0.5)
Map.addLayer(landcover, {}, 'Land cover')
Map.addLayer(
landsat7,
{'bands': ['B4', 'B3', 'B2'], 'min': 20, 'max': 200, 'gamma': 1.5},
'Landsat 7',
)
Map.addLayer(states, {}, "US States")
Exporting maps as HTML¶
You can either click the camera icon on toolbar to export maps or use the following script.
In [7]:
Copied!
import os
import os
In [8]:
Copied!
download_dir = os.path.join(os.path.expanduser('~'), 'Downloads')
if not os.path.exists(download_dir):
os.makedirs(download_dir)
html_file = os.path.join(download_dir, 'my_map.html')
download_dir = os.path.join(os.path.expanduser('~'), 'Downloads')
if not os.path.exists(download_dir):
os.makedirs(download_dir)
html_file = os.path.join(download_dir, 'my_map.html')
In [9]:
Copied!
Map.to_html(outfile=html_file, title='My Map', width='100%', height='880px')
Map.to_html(outfile=html_file, title='My Map', width='100%', height='880px')
Exporting maps as PNG/JPG¶
Make sure you click the fullscreen button on the map to maximum the map.
In [10]:
Copied!
png_file = os.path.join(download_dir, 'my_map.png')
png_file = os.path.join(download_dir, 'my_map.png')
In [11]:
Copied!
Map.to_image(outfile=png_file, monitor=1)
Map.to_image(outfile=png_file, monitor=1)
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Input In [11], in <cell line: 1>() ----> 1 Map.to_image(outfile=png_file, monitor=1) AttributeError: 'Map' object has no attribute 'to_image'
In [12]:
Copied!
jpg_file = os.path.join(download_dir, 'my_map.jpg')
jpg_file = os.path.join(download_dir, 'my_map.jpg')
In [13]:
Copied!
Map.to_image(outfile=jpg_file, monitor=1)
Map.to_image(outfile=jpg_file, monitor=1)
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Input In [13], in <cell line: 1>() ----> 1 Map.to_image(outfile=jpg_file, monitor=1) AttributeError: 'Map' object has no attribute 'to_image'
Last update:
2022-03-14