# Import libraries
import ee
import geemap
# Create an interactive map by specifying the center (lat, lon) and zoom level (1-18).
Map = geemap.Map(center=[40, -100], zoom=4)
Map
# Import the NLCD collection.
dataset = ee.ImageCollection('USGS/NLCD_RELEASES/2019_REL/NLCD')
# Filter the collection to the 2016 product.
nlcd2016 = dataset.filter(ee.Filter.eq('system:index', '2019')).first()
# Select the land cover band.
landcover = nlcd2016.select('landcover')
# Display land cover on the map.
Map.addLayer(landcover, {}, 'NLCD 2019')
# Add the NLCD legend to the map.
Map.add_legend(title='NLCD Land Cover Classification', builtin_legend='NLCD')
# # To add a custom legend to the map, uncomment the following code and modify the legend dictionary.
# 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'
# }
# Map.add_legend(title="NLCD Land Cover Classification", legend_dict=legend_dict)
# Print the list of system ids of all available NLCD images.
dataset.aggregate_array("system:id").getInfo()
# Select the seven NLCD epoches after 2000.
years = ['2001', '2004', '2006', '2008', '2011', '2013', '2016', '2019']
# Get an NLCD image by year.
def getNLCD(year):
# Import the NLCD collection.
dataset = ee.ImageCollection('USGS/NLCD_RELEASES/2019_REL/NLCD')
# Filter the collection by year.
nlcd = dataset.filter(ee.Filter.eq('system:index', year)).first()
# Select the land cover band.
landcover = nlcd.select('landcover')
return landcover
## Create an NLCD image collection for the selected years.
collection = ee.ImageCollection(ee.List(years).map(lambda year: getNLCD(year)))
# Print the list of system ids of selected NLCD images.
collection.aggregate_array('system:id').getInfo()
# Create a list of labels to populate the dropdown list.
labels = [f'NLCD {year}' for year in years]
labels
# Add a split-panel map for visualizing NLCD land cover change.
Map.ts_inspector(
left_ts=collection, right_ts=collection, left_names=labels, right_names=labels
)
Map