import ee
import geemap
geemap.set_proxy(port=10809)
geemap.show_youtube('NwnW_qOkNRw')
Available builtin legends
legends = geemap.builtin_legends
for legend in legends:
print(legend)
# NLCD
# NWI
# MODIS/051/MCD12Q1
# GLOBCOVER
# JAXA/PALSAR
# MODIS/006/MCD12Q1
# Oxford
# AAFC/ACI
# COPERNICUS/CORINE/V20/100m
# COPERNICUS/Landcover/100m/Proba-V/Global
# USDA/NASS/CDL
Available Land Cover Datasets in Earth Engine
National Land Cover Database(NLCD)
Map = geemap.Map()
Map.add_basemap('HYBRID')
landcover = ee.Image('USGS/NLCD/NLCD2016').select('landcover')
Map.addLayer(landcover,{},'NLCD Land Cover')
Map.add_legend(builtin_legend ='NWI')
Map
MODIS Land Cover Type Yearly Global 500m
Map = geemap.Map()
Map.add_basemap('HYBRID')
landcover1 = ee.Image('MODIS/006/MCD12Q1/2019_01_01').select('LC_Type1')
Map.setCenter(6.746, 46.529, 2)
Map.addLayer(landcover1, {}, 'MODIS Land Cover')
Map.add_legend(builtin_legend='MODIS/006/MCD12Q1')
Map
Add customized legends for Earth Engine data
- define legend keys and colors
- Define legend dictionary
- Convert Earth Engine class table to legend dictionary
define legend keys and colors
# define legend keys and colors
Map = geemap.Map()
legend_keys = ['One', 'Two', 'Three', 'Four', 'ect']
# Colors can 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(legend_keys = legend_keys, legend_colors = legend_colors, position = 'bottomright')
Map
define a legend dictionary
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(legend_title="NLCD Land Cover Classification", legend_dict=legend_dict)
Map
Convert an Earth Engine class table to legend
for example: MCD12Q1.006 Land Cover Type Yearly Global 500m
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/006/MCD12Q1/2019_01_01') \
.select('LC_Type1')
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(legend_title = "MODIS Global Land Cover", legend_dict = legend_dict)
Map
ps: 关于MODIS的有些问题