F60c Checkpoint
Import libraries¶
In [ ]:
Copied!
import ee
import geemap
import ee
import geemap
Create an interactive map¶
In [ ]:
Copied!
Map = geemap.Map(center=[40, -100], zoom=4)
Map = geemap.Map(center=[40, -100], zoom=4)
Add Earth Engine Python script¶
In [ ]:
Copied!
# Add Earth Engine dataset
image = ee.Image("USGS/SRTMGL1_003")
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Chapter: F6.0 Advanced Raster Visualization
# Checkpoint: F60c
# Authors: Gennadii Donchyts, Fedor Baart
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Advanced remapping using NLCD.
# Import NLCD.
nlcd = ee.ImageCollection("USGS/NLCD_RELEASES/2016_REL")
# Use Filter to select the 2016 dataset.
nlcd2016 = nlcd.filter(ee.Filter.eq("system:index", "2016")).first()
# Select the land cover band.
landcover = nlcd2016.select("landcover")
# Map the NLCD land cover.
Map.addLayer(landcover, None, "NLCD Landcover")
# Now suppose we want to change the color palette.
newPalette = [
"466b9f",
"d1def8",
"dec5c5",
"ab0000",
"ab0000",
"ab0000",
"b3ac9f",
"68ab5f",
"1c5f2c",
"b5c58f",
"af963c",
"ccb879",
"dfdfc2",
"d1d182",
"a3cc51",
"82ba9e",
"dcd939",
"ab6c28",
"b8d9eb",
"6c9fb8",
]
# Try mapping with the new color palette.
Map.addLayer(landcover, {"palette": newPalette}, "NLCD New Palette")
# Extract the class values and save them as a list.
values = ee.List(landcover.get("landcover_class_values"))
# Print the class values to console.
print("raw class values", values)
# Determine the maximum index value
maxIndex = values.size().subtract(1)
# Create a new index for the remap
indexes = ee.List.sequence(0, maxIndex)
# Print the updated class values to console.
print("updated class values", indexes)
# Remap NLCD and display it in the map.
colorized = landcover.remap(values, indexes).visualize(
**{"min": 0, "max": maxIndex, "palette": newPalette}
)
Map.addLayer(colorized, {}, "NLCD Remapped Colors")
# -----------------------------------------------------------------------
# CHECKPOINT
# -----------------------------------------------------------------------
# Add Earth Engine dataset
image = ee.Image("USGS/SRTMGL1_003")
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Chapter: F6.0 Advanced Raster Visualization
# Checkpoint: F60c
# Authors: Gennadii Donchyts, Fedor Baart
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Advanced remapping using NLCD.
# Import NLCD.
nlcd = ee.ImageCollection("USGS/NLCD_RELEASES/2016_REL")
# Use Filter to select the 2016 dataset.
nlcd2016 = nlcd.filter(ee.Filter.eq("system:index", "2016")).first()
# Select the land cover band.
landcover = nlcd2016.select("landcover")
# Map the NLCD land cover.
Map.addLayer(landcover, None, "NLCD Landcover")
# Now suppose we want to change the color palette.
newPalette = [
"466b9f",
"d1def8",
"dec5c5",
"ab0000",
"ab0000",
"ab0000",
"b3ac9f",
"68ab5f",
"1c5f2c",
"b5c58f",
"af963c",
"ccb879",
"dfdfc2",
"d1d182",
"a3cc51",
"82ba9e",
"dcd939",
"ab6c28",
"b8d9eb",
"6c9fb8",
]
# Try mapping with the new color palette.
Map.addLayer(landcover, {"palette": newPalette}, "NLCD New Palette")
# Extract the class values and save them as a list.
values = ee.List(landcover.get("landcover_class_values"))
# Print the class values to console.
print("raw class values", values)
# Determine the maximum index value
maxIndex = values.size().subtract(1)
# Create a new index for the remap
indexes = ee.List.sequence(0, maxIndex)
# Print the updated class values to console.
print("updated class values", indexes)
# Remap NLCD and display it in the map.
colorized = landcover.remap(values, indexes).visualize(
**{"min": 0, "max": maxIndex, "palette": newPalette}
)
Map.addLayer(colorized, {}, "NLCD Remapped Colors")
# -----------------------------------------------------------------------
# CHECKPOINT
# -----------------------------------------------------------------------
Display the interactive map¶
In [ ]:
Copied!
Map
Map