Uncomment the following line to install geemap if needed.
In [ ]:
Copied!
# !pip install geemap
# !pip install geemap
Google Earth Engine Python Tutorials¶
- GitHub: https://github.com/gee-community/geemap
- Notebook examples: https://github.com/gee-community/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 [ ]:
Copied!
import ee
import geemap
import ee
import geemap
Video tutorial on YouTube¶
In [ ]:
Copied!
geemap.show_youtube('h0pz3S6Tvx0')
geemap.show_youtube('h0pz3S6Tvx0')
In [ ]:
Copied!
# geemap.update_package()
# geemap.update_package()
Create an interactive map¶
In [ ]:
Copied!
Map = geemap.Map(toolbar_ctrl=True, layer_ctrl=True)
Map
Map = geemap.Map(toolbar_ctrl=True, layer_ctrl=True)
Map
In [ ]:
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('LANDSAT/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('LANDSAT/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 [ ]:
Copied!
import os
import os
In [ ]:
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 [ ]:
Copied!
Map.to_html(filename=html_file, title='My Map', width='100%', height='880px')
Map.to_html(filename=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 [ ]:
Copied!
png_file = os.path.join(download_dir, 'my_map.png')
png_file = os.path.join(download_dir, 'my_map.png')
In [ ]:
Copied!
Map.to_image(filename=png_file, monitor=1)
Map.to_image(filename=png_file, monitor=1)
In [ ]:
Copied!
jpg_file = os.path.join(download_dir, 'my_map.jpg')
jpg_file = os.path.join(download_dir, 'my_map.jpg')
In [ ]:
Copied!
Map.to_image(filename=jpg_file, monitor=1)
Map.to_image(filename=jpg_file, monitor=1)