14 legends
Uncomment the following line to install geemap if needed.
In [ ]:
Copied!
# !pip install geemap
# !pip install geemap
In [ ]:
Copied!
import ee
import geemap
import ee
import geemap
Add builtin legends from geemap Python package¶
https://github.com/gee-community/geemap/blob/master/geemap/legends.py
Available builtin legends:¶
In [ ]:
Copied!
legends = geemap.builtin_legends
for legend in legends:
print(legend)
legends = geemap.builtin_legends
for legend in legends:
print(legend)
Available Land Cover Datasets in Earth Engine¶
https://developers.google.com/earth-engine/datasets/tags/landcover
National Land Cover Database (NLCD)¶
https://developers.google.com/earth-engine/datasets/catalog/USGS_NLCD_RELEASES_2019_REL_NLCD
In [ ]:
Copied!
Map = geemap.Map()
Map.add_basemap("HYBRID")
landcover = ee.Image("USGS/NLCD_RELEASES/2019_REL/NLCD/2019").select("landcover")
Map.addLayer(landcover, {}, "NLCD Land Cover")
Map.add_legend(builtin_legend="NLCD", title="NLCD Land Cover")
Map
Map = geemap.Map()
Map.add_basemap("HYBRID")
landcover = ee.Image("USGS/NLCD_RELEASES/2019_REL/NLCD/2019").select("landcover")
Map.addLayer(landcover, {}, "NLCD Land Cover")
Map.add_legend(builtin_legend="NLCD", title="NLCD Land Cover")
Map
National Wetlands Inventory (NWI)¶
https://www.fws.gov/program/national-wetlands-inventory/wetlands-mapper
In [ ]:
Copied!
Map = geemap.Map()
Map.add_basemap("HYBRID")
Map.add_basemap("FWS NWI Wetlands")
Map.add_legend(builtin_legend="NWI")
Map
Map = geemap.Map()
Map.add_basemap("HYBRID")
Map.add_basemap("FWS NWI Wetlands")
Map.add_legend(builtin_legend="NWI")
Map
MODIS Land Cover Type Yearly Global 500m¶
https://developers.google.com/earth-engine/datasets/catalog/MODIS_051_MCD12Q1
In [ ]:
Copied!
Map = geemap.Map()
Map.add_basemap("HYBRID")
landcover = ee.Image("MODIS/051/MCD12Q1/2013_01_01").select("Land_Cover_Type_1")
Map.setCenter(6.746, 46.529, 2)
Map.addLayer(landcover, {}, "MODIS Land Cover")
Map.add_legend(builtin_legend="MODIS/051/MCD12Q1")
Map
Map = geemap.Map()
Map.add_basemap("HYBRID")
landcover = ee.Image("MODIS/051/MCD12Q1/2013_01_01").select("Land_Cover_Type_1")
Map.setCenter(6.746, 46.529, 2)
Map.addLayer(landcover, {}, "MODIS Land Cover")
Map.add_legend(builtin_legend="MODIS/051/MCD12Q1")
Map
In [ ]:
Copied!
Map = geemap.Map()
legend_keys = ["One", "Two", "Three", "Four", "etc"]
# colorS can be defined using either hex code or RGB (0-255, 0-255, 0-255)
legend_colors = ["#8DD3C7", "#FFFFB3", "#BEBADA", "#FB8072", "#80B1D3"]
# legend_colors = [(255, 0, 0), (127, 255, 0), (127, 18, 25), (36, 70, 180), (96, 68 123)]
Map.add_legend(keys=legend_keys, colors=legend_colors, position="bottomleft")
Map
Map = geemap.Map()
legend_keys = ["One", "Two", "Three", "Four", "etc"]
# colorS can be defined using either hex code or RGB (0-255, 0-255, 0-255)
legend_colors = ["#8DD3C7", "#FFFFB3", "#BEBADA", "#FB8072", "#80B1D3"]
# legend_colors = [(255, 0, 0), (127, 255, 0), (127, 18, 25), (36, 70, 180), (96, 68 123)]
Map.add_legend(keys=legend_keys, colors=legend_colors, position="bottomleft")
Map
Define a legend dictionary¶
In [ ]:
Copied!
Map = geemap.Map()
legend_dict = {
"11 Open Water": "466b9f",
"12 Perennial Ice/Snow": "d1def8",
"21 Developed, Open Space": "dec5c5",
"22 Developed, Low Intensity": "d99282",
"23 Developed, Medium Intensity": "eb0000",
"24 Developed High Intensity": "ab0000",
"31 Barren Land (Rock/Sand/Clay)": "b3ac9f",
"41 Deciduous Forest": "68ab5f",
"42 Evergreen Forest": "1c5f2c",
"43 Mixed Forest": "b5c58f",
"51 Dwarf Scrub": "af963c",
"52 Shrub/Scrub": "ccb879",
"71 Grassland/Herbaceous": "dfdfc2",
"72 Sedge/Herbaceous": "d1d182",
"73 Lichens": "a3cc51",
"74 Moss": "82ba9e",
"81 Pasture/Hay": "dcd939",
"82 Cultivated Crops": "ab6c28",
"90 Woody Wetlands": "b8d9eb",
"95 Emergent Herbaceous Wetlands": "6c9fb8",
}
landcover = ee.Image("USGS/NLCD/NLCD2016").select("landcover")
Map.addLayer(landcover, {}, "NLCD Land Cover")
Map.add_legend(title="NLCD Land Cover Classification", legend_dict=legend_dict)
Map
Map = geemap.Map()
legend_dict = {
"11 Open Water": "466b9f",
"12 Perennial Ice/Snow": "d1def8",
"21 Developed, Open Space": "dec5c5",
"22 Developed, Low Intensity": "d99282",
"23 Developed, Medium Intensity": "eb0000",
"24 Developed High Intensity": "ab0000",
"31 Barren Land (Rock/Sand/Clay)": "b3ac9f",
"41 Deciduous Forest": "68ab5f",
"42 Evergreen Forest": "1c5f2c",
"43 Mixed Forest": "b5c58f",
"51 Dwarf Scrub": "af963c",
"52 Shrub/Scrub": "ccb879",
"71 Grassland/Herbaceous": "dfdfc2",
"72 Sedge/Herbaceous": "d1d182",
"73 Lichens": "a3cc51",
"74 Moss": "82ba9e",
"81 Pasture/Hay": "dcd939",
"82 Cultivated Crops": "ab6c28",
"90 Woody Wetlands": "b8d9eb",
"95 Emergent Herbaceous Wetlands": "6c9fb8",
}
landcover = ee.Image("USGS/NLCD/NLCD2016").select("landcover")
Map.addLayer(landcover, {}, "NLCD Land Cover")
Map.add_legend(title="NLCD Land Cover Classification", legend_dict=legend_dict)
Map
Convert an Earth Engine class table to legend¶
For example: MCD12Q1.051 Land Cover Type Yearly Global 500m
https://developers.google.com/earth-engine/datasets/catalog/MODIS_051_MCD12Q1
In [ ]:
Copied!
Map = geemap.Map()
ee_class_table = """
Value Color Description
0 1c0dff Water
1 05450a Evergreen needleleaf forest
2 086a10 Evergreen broadleaf forest
3 54a708 Deciduous needleleaf forest
4 78d203 Deciduous broadleaf forest
5 009900 Mixed forest
6 c6b044 Closed shrublands
7 dcd159 Open shrublands
8 dade48 Woody savannas
9 fbff13 Savannas
10 b6ff05 Grasslands
11 27ff87 Permanent wetlands
12 c24f44 Croplands
13 a5a5a5 Urban and built-up
14 ff6d4c Cropland/natural vegetation mosaic
15 69fff8 Snow and ice
16 f9ffa4 Barren or sparsely vegetated
254 ffffff Unclassified
"""
landcover = ee.Image("MODIS/051/MCD12Q1/2013_01_01").select("Land_Cover_Type_1")
Map.setCenter(6.746, 46.529, 2)
Map.addLayer(landcover, {}, "MODIS Land Cover")
legend_dict = geemap.legend_from_ee(ee_class_table)
Map.add_legend(title="MODIS Global Land Cover", legend_dict=legend_dict)
Map
Map = geemap.Map()
ee_class_table = """
Value Color Description
0 1c0dff Water
1 05450a Evergreen needleleaf forest
2 086a10 Evergreen broadleaf forest
3 54a708 Deciduous needleleaf forest
4 78d203 Deciduous broadleaf forest
5 009900 Mixed forest
6 c6b044 Closed shrublands
7 dcd159 Open shrublands
8 dade48 Woody savannas
9 fbff13 Savannas
10 b6ff05 Grasslands
11 27ff87 Permanent wetlands
12 c24f44 Croplands
13 a5a5a5 Urban and built-up
14 ff6d4c Cropland/natural vegetation mosaic
15 69fff8 Snow and ice
16 f9ffa4 Barren or sparsely vegetated
254 ffffff Unclassified
"""
landcover = ee.Image("MODIS/051/MCD12Q1/2013_01_01").select("Land_Cover_Type_1")
Map.setCenter(6.746, 46.529, 2)
Map.addLayer(landcover, {}, "MODIS Land Cover")
legend_dict = geemap.legend_from_ee(ee_class_table)
Map.add_legend(title="MODIS Global Land Cover", legend_dict=legend_dict)
Map