Introduction to Earth Engine and Geemap
A workshop at Nagoya University, Japan.
Useful links
Press Ctrl + / to uncomment the following line to install geemap. Restart the kernel/runtime after installation.
# pip install geemap
import ee
ee.Authenticate()
import geemap
Map = geemap.Map()
Map
Map = geemap.Map(center=[40, -100], zoom=4, height=600)
Map
Map = geemap.Map(data_ctrl=False, toolbar_ctrl=False, draw_ctrl=False)
Map
Map = geemap.Map(lite_mode=True)
Map
Map.save("ipyleaflet.html")
import geemap
Map = geemap.Map(basemap="HYBRID")
Map
Map.add_basemap("OpenTopoMap")
for basemap in geemap.basemaps.keys():
print(basemap)
len(geemap.basemaps)
Map = geemap.Map()
Map
image = ee.Image("USGS/SRTMGL1_003")
Map = geemap.Map(center=[21.79, 70.87], zoom=3)
image = ee.Image("USGS/SRTMGL1_003")
vis_params = {
"min": 0,
"max": 6000,
"palette": ["006633", "E5FFCC", "662A00", "D8D8D8", "F5F5F5"],
}
Map.addLayer(image, vis_params, "SRTM")
Map
collection = ee.ImageCollection("COPERNICUS/S2_SR")
Map = geemap.Map()
collection = ee.ImageCollection("COPERNICUS/S2_SR")
image = collection.median()
vis = {
"min": 0.0,
"max": 3000,
"bands": ["B4", "B3", "B2"],
}
Map.setCenter(83.277, 17.7009, 12)
Map.addLayer(image, vis, "Sentinel-2")
Map
Map = geemap.Map()
collection = (
ee.ImageCollection("COPERNICUS/S2_SR")
.filterDate("2021-01-01", "2022-01-01")
.filter(ee.Filter.lt("CLOUDY_PIXEL_PERCENTAGE", 5))
)
image = collection.median()
vis = {
"min": 0.0,
"max": 3000,
"bands": ["B4", "B3", "B2"],
}
Map.setCenter(83.277, 17.7009, 12)
Map.addLayer(image, vis, "Sentinel-2")
Map
Map = geemap.Map()
point = ee.Geometry.Point([1.5, 1.5])
lineString = ee.Geometry.LineString([[-35, -10], [35, -10], [35, 10], [-35, 10]])
linearRing = ee.Geometry.LinearRing(
[[-35, -10], [35, -10], [35, 10], [-35, 10], [-35, -10]]
)
rectangle = ee.Geometry.Rectangle([-40, -20, 40, 20])
polygon = ee.Geometry.Polygon([[[-5, 40], [65, 40], [65, 60], [-5, 60], [-5, 60]]])
Map.addLayer(point, {}, "Point")
Map.addLayer(lineString, {}, "LineString")
Map.addLayer(linearRing, {}, "LinearRing")
Map.addLayer(rectangle, {}, "Rectangle")
Map.addLayer(polygon, {}, "Polygon")
Map
Map = geemap.Map()
point = ee.Geometry.Point([1.5, 1.5])
lineString = ee.Geometry.LineString(
[[-35, -10], [35, -10], [35, 10], [-35, 10]], None, False
)
linearRing = ee.Geometry.LinearRing(
[[-35, -10], [35, -10], [35, 10], [-35, 10], [-35, -10]], None, False
)
rectangle = ee.Geometry.Rectangle([-40, -20, 40, 20], None, False)
polygon = ee.Geometry.Polygon(
[[[-5, 40], [65, 40], [65, 60], [-5, 60], [-5, 60]]], None, False
)
Map.addLayer(point, {}, "Point")
Map.addLayer(lineString, {}, "LineString")
Map.addLayer(linearRing, {}, "LinearRing")
Map.addLayer(rectangle, {}, "Rectangle")
Map.addLayer(polygon, {}, "Polygon")
Map
if Map.user_roi is not None:
print(Map.user_roi.getInfo())
# Create an ee.Geometry.
polygon = ee.Geometry.Polygon(
[[[-35, -10], [35, -10], [35, 10], [-35, 10], [-35, -10]]], None, False
)
# Create a Feature from the Geometry.
polyFeature = ee.Feature(polygon, {"foo": 42, "bar": "tart"})
polyFeature.getInfo()
Map = geemap.Map()
Map.addLayer(polyFeature, {}, "feature")
Map
# Create a dictionary of properties, some of which may be computed values.
props = {"foo": ee.Number(8).add(88), "bar": "nihao"}
# Create a None geometry feature with the dictionary of properties.
nowhereFeature = ee.Feature(None, props)
nowhereFeature.getInfo()
# Make a feature and set some properties.
feature = (
ee.Feature(ee.Geometry.Point([-122.22599, 37.17605]))
.set("genus", "Sequoia")
.set("species", "sempervirens")
)
# Overwrite the old properties with a new dictionary.
newDict = {"genus": "Brachyramphus", "presence": 1, "species": "marmoratus"}
feature = feature.set(newDict)
# Check the result.
feature.getInfo()
prop = feature.get("species")
prop.getInfo()
props = feature.toDictionary()
props.getInfo()
Map = geemap.Map()
fc = ee.FeatureCollection("TIGER/2016/Roads")
Map.setCenter(-73.9596, 40.7688, 12)
Map.addLayer(fc, {}, "Census roads")
Map
# Make a list of Features.
features = [
ee.Feature(ee.Geometry.Rectangle(30.01, 59.80, 30.59, 60.15), {"name": "Voronoi"}),
ee.Feature(ee.Geometry.Point(-73.96, 40.781), {"name": "Thiessen"}),
ee.Feature(ee.Geometry.Point(6.4806, 50.8012), {"name": "Dirichlet"}),
]
# Create a FeatureCollection from the list and print it.
fromList = ee.FeatureCollection(features)
fromList.getInfo()
Map = geemap.Map()
states = ee.FeatureCollection("TIGER/2018/States")
feat = states.filter(ee.Filter.eq("NAME", "Texas"))
Map.addLayer(feat, {}, "Texas")
Map.centerObject(feat)
Map
texas = feat.first()
texas.toDictionary().getInfo()
Map = geemap.Map()
states = ee.FeatureCollection("TIGER/2018/States")
fc = states.filter(ee.Filter.inList("NAME", ["California", "Oregon", "Washington"]))
Map.addLayer(fc, {}, "West Coast")
Map.centerObject(fc)
Map
region = Map.user_roi
if region is None:
region = ee.Geometry.BBox(-88.40, 29.88, -77.90, 35.39)
fc = ee.FeatureCollection("TIGER/2018/States").filterBounds(region)
Map.addLayer(fc, {}, "Southeastern U.S.")
Map.centerObject(fc)
Map = geemap.Map(center=[40, -100], zoom=4)
states = ee.FeatureCollection("TIGER/2018/States")
Map.addLayer(states, {}, "US States")
Map
Map = geemap.Map(center=[40, -100], zoom=4)
states = ee.FeatureCollection("TIGER/2018/States")
image = ee.Image().paint(states, 0, 3)
Map.addLayer(image, {"palette": "red"}, "US States")
Map
Map = geemap.Map(center=[40, -100], zoom=4)
states = ee.FeatureCollection("TIGER/2018/States")
style = {"color": "0000ffff", "width": 2, "lineType": "solid", "fillColor": "FF000080"}
Map.addLayer(states.style(**style), {}, "US States")
Map
Map = geemap.Map(center=[40, -100], zoom=4)
states = ee.FeatureCollection("TIGER/2018/States")
vis_params = {
"color": "000000",
"colorOpacity": 1,
"pointSize": 3,
"pointShape": "circle",
"width": 2,
"lineType": "solid",
"fillColorOpacity": 0.66,
}
palette = ["006633", "E5FFCC", "662A00", "D8D8D8", "F5F5F5"]
Map.add_styled_vector(
states, column="NAME", palette=palette, layer_name="Styled vector", **vis_params
)
Map
Map = geemap.Map(center=[28.00142, -81.7424], zoom=13)
Map.add_basemap("HYBRID")
types = [
"Freshwater Forested/Shrub Wetland",
"Freshwater Emergent Wetland",
"Freshwater Pond",
"Estuarine and Marine Wetland",
"Riverine",
"Lake",
"Estuarine and Marine Deepwater",
"Other",
]
colors = [
"#008837",
"#7FC31C",
"#688CC0",
"#66C2A5",
"#0190BF",
"#13007C",
"#007C88",
"#B28653",
]
fillColor = [c + "A8" for c in colors]
fc = ee.FeatureCollection("projects/sat-io/open-datasets/NWI/wetlands/FL_Wetlands")
styled_fc = geemap.ee_vector_style(
fc, column="WETLAND_TY", labels=types, fillColor=fillColor, color="00000000"
)
Map.addLayer(styled_fc, {}, "NWI")
Map.add_legend(title="Wetland Type", labels=types, colors=colors)
Map
fuels = [
"Coal",
"Oil",
"Gas",
"Hydro",
"Nuclear",
"Solar",
"Waste",
"Wind",
"Geothermal",
"Biomass",
]
colors = [
"000000",
"593704",
"BC80BD",
"0565A6",
"E31A1C",
"FF7F00",
"6A3D9A",
"5CA2D1",
"FDBF6F",
"229A00",
]
fc = ee.FeatureCollection("WRI/GPPD/power_plants").filter(
ee.Filter.inList("fuel1", fuels)
)
styled_fc = geemap.ee_vector_style(fc, column="fuel1", labels=fuels, color=colors)
Map = geemap.Map(center=[40, -100], zoom=4)
Map.addLayer(styled_fc, {}, "Power Plants")
Map.add_legend(title="Power Plant Fuel Type", labels=fuels, colors=colors)
Map
types = ["I", "U", "S", "M", "C", "O"]
labels = ["Interstate", "U.S.", "State recognized", "Common Name", "County", "Other"]
colors = ["E31A1C", "FF7F00", "6A3D9A", "000000", "FDBF6F", "229A00"]
width = [8, 5, 4, 2, 1, 1]
fc = ee.FeatureCollection("TIGER/2016/Roads")
styled_fc = geemap.ee_vector_style(
fc, column="rttyp", labels=types, color=colors, width=width
)
Map = geemap.Map(center=[40.7424, -73.9724], zoom=13)
Map.addLayer(styled_fc, {}, "Census Roads")
Map.add_legend(title="Route Type", labels=labels, colors=colors)
Map
dataset_xyz = ee.Image("USGS/SRTMGL1_003")
Map.addLayer(dataset_xyz, {}, "USGS/SRTMGL1_003")
Map = geemap.Map()
dem = ee.Image("USGS/SRTMGL1_003")
vis_params = {
"min": 0,
"max": 4000,
"palette": ["006633", "E5FFCC", "662A00", "D8D8D8", "F5F5F5"],
}
Map.addLayer(dem, vis_params, "SRTM DEM")
Map
from geemap.datasets import DATA
Map = geemap.Map(center=[40, -100], zoom=4)
dataset = ee.Image(DATA.USGS_GAP_CONUS_2011)
Map.addLayer(dataset, {}, "GAP CONUS")
Map
from geemap.datasets import get_metadata
get_metadata(DATA.USGS_GAP_CONUS_2011)
image = ee.Image("LANDSAT/LC09/C02/T1_L2/LC09_044034_20220503")
image.bandNames().getInfo()
image.select("SR_B1").projection().getInfo()
image.select("SR_B1").projection().nominalScale().getInfo()
image.propertyNames().getInfo()
image.get("CLOUD_COVER").getInfo()
image.get("DATE_ACQUIRED").getInfo()
image.get("system:time_start").getInfo()
date = ee.Date(image.get("system:time_start"))
date.format("YYYY-MM-dd").getInfo()
image.toDictionary().getInfo()
props = geemap.image_props(image)
props.getInfo()
image = ee.Image("LANDSAT/LC09/C02/T1_L2/LC09_044034_20220503")
geemap.image_min_value(image).getInfo()
geemap.image_max_value(image).getInfo()
geemap.image_mean_value(image).getInfo()
geemap.image_stats(image).getInfo()
# Create an interactive map
Map = geemap.Map(center=(40, -100), zoom=4)
# Add Earth Engine datasets
dem = ee.Image("USGS/SRTMGL1_003")
landsat7 = ee.Image("LANDSAT/LE7_TOA_5YEAR/1999_2003").select(
["B1", "B2", "B3", "B4", "B5", "B7"]
)
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 the map
Map.addLayer(dem, vis_params, "SRTM DEM")
Map.addLayer(
landsat7,
{"bands": ["B4", "B3", "B2"], "min": 20, "max": 200, "gamma": 2.0},
"Landsat 7",
)
Map.addLayer(states, {}, "US States")
# Display the map
Map
Map = geemap.Map(center=[40, -100], zoom=4)
landsat7 = ee.Image("LANDSAT/LE7_TOA_5YEAR/1999_2003").select(
["B1", "B2", "B3", "B4", "B5", "B7"]
)
landsat_vis = {"bands": ["B4", "B3", "B2"], "gamma": 1.4}
Map.addLayer(landsat7, landsat_vis, "Landsat")
hyperion = ee.ImageCollection("EO1/HYPERION").filter(
ee.Filter.date("2016-01-01", "2017-03-01")
)
hyperion_vis = {
"min": 1000.0,
"max": 14000.0,
"gamma": 2.5,
}
Map.addLayer(hyperion, hyperion_vis, "Hyperion")
Map
Map.set_plot_options(add_marker_cluster=True, overlay=True)
Map = geemap.Map(center=(40, -100), zoom=4)
dem = ee.Image("USGS/SRTMGL1_003")
states = ee.FeatureCollection("TIGER/2018/States")
vis_params = {
"min": 0,
"max": 4000,
"palette": ["006633", "E5FFCC", "662A00", "D8D8D8", "F5F5F5"],
}
Map.addLayer(dem, vis_params, "SRTM DEM", True, 1)
Map.addLayer(states, {}, "US States", True)
Map
Map = geemap.Map(center=[12, 69], zoom=3)
dem = ee.Image("USGS/SRTMGL1_003")
vis_params = {
"min": 0,
"max": 4000,
"palette": ["006633", "E5FFCC", "662A00", "D8D8D8", "F5F5F5"],
}
Map.addLayer(dem, vis_params, "SRTM DEM")
Map
vis_params = {
"bands": ["elevation"],
"palette": ["333399", " 00b2b2", " 99eb85", " ccbe7d", " 997c76", " ffffff"],
"min": 0.0,
"max": 6000.0,
"opacity": 1.0,
"gamma": 1.0,
}
Map = geemap.Map()
landsat7 = ee.Image("LANDSAT/LE7_TOA_5YEAR/1999_2003")
vis_params = {
"min": 20,
"max": 200,
"gamma": 2,
"bands": ["B4", "B3", "B2"],
}
Map.addLayer(landsat7, vis_params, "Landsat 7")
Map
Map = geemap.Map()
states = ee.FeatureCollection("TIGER/2018/States")
Map.addLayer(states, {}, "US States")
Map
vis_params = {
"color": "ff0000ff",
"width": 2,
"lineType": "solid",
"fillColor": "00000000",
}
Map = geemap.Map(center=[40, -100], zoom=4)
states = ee.FeatureCollection("TIGER/2018/States")
Map.addLayer(states.style(**vis_params), {}, "US States")
Map
legends = geemap.builtin_legends
for legend in legends:
print(legend)
Map.add_legend(builtin_legend="NLCD")
Map = geemap.Map(center=[40, -100], zoom=4)
Map.add_basemap("HYBRID")
nlcd = ee.Image("USGS/NLCD_RELEASES/2019_REL/NLCD/2019")
landcover = nlcd.select("landcover")
Map.addLayer(landcover, {}, "NLCD Land Cover 2019")
Map.add_legend(
title="NLCD Land Cover Classification", builtin_legend="NLCD", height="465px"
)
Map
Map = geemap.Map(add_google_map=False)
labels = ["One", "Two", "Three", "Four", "etc"]
# colors can be defined using either hex code or RGB (0-255, 0-255, 0-255)
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(labels=labels, colors=colors, position="bottomright")
Map
Map = geemap.Map(center=[40, -100], zoom=4)
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",
}
nlcd = ee.Image("USGS/NLCD_RELEASES/2019_REL/NLCD/2019")
landcover = nlcd.select("landcover")
Map.addLayer(landcover, {}, "NLCD Land Cover 2019")
Map.add_legend(title="NLCD Land Cover Classification", legend_dict=legend_dict)
Map
Map = geemap.Map()
dem = ee.Image("USGS/SRTMGL1_003")
vis_params = {
"min": 0,
"max": 4000,
"palette": ["006633", "E5FFCC", "662A00", "D8D8D8", "F5F5F5"],
}
Map.addLayer(dem, vis_params, "SRTM DEM")
Map
Map.add_colorbar(vis_params, label="Elevation (m)", layer_name="SRTM DEM")
Map.add_colorbar(
vis_params, label="Elevation (m)", layer_name="SRTM DEM", orientation="vertical"
)
Map.add_colorbar(
vis_params,
label="Elevation (m)",
layer_name="SRTM DEM",
orientation="vertical",
transparent_bg=True,
)
Map = geemap.Map(center=[40, -100], zoom=4, add_google_map=False)
states = ee.FeatureCollection("TIGER/2018/States")
style = {"color": "black", "fillColor": "00000000"}
Map.addLayer(states.style(**style), {}, "US States")
Map
Map.add_labels(
data=states,
column="STUSPS",
font_size="12pt",
font_color="blue",
font_family="arial",
font_weight="bold",
draggable=True,
)
Map.remove_labels()
centroids = geemap.vector_centroids(states)
df = geemap.ee_to_df(centroids)
df
Map.add_labels(
data=df,
column="STUSPS",
font_size="12pt",
font_color="blue",
font_family="arial",
font_weight="bold",
x="longitude",
y="latitude",
)
Map
Map = geemap.Map()
Map.split_map(left_layer="HYBRID", right_layer="TERRAIN")
Map
Map = geemap.Map(center=(40, -100), zoom=4, height=600)
nlcd_2001 = ee.Image("USGS/NLCD_RELEASES/2019_REL/NLCD/2001").select("landcover")
nlcd_2019 = ee.Image("USGS/NLCD_RELEASES/2019_REL/NLCD/2019").select("landcover")
left_layer = geemap.ee_tile_layer(nlcd_2001, {}, "NLCD 2001")
right_layer = geemap.ee_tile_layer(nlcd_2019, {}, "NLCD 2019")
Map.split_map(left_layer, right_layer)
Map
image = (
ee.ImageCollection("COPERNICUS/S2")
.filterDate("2018-09-01", "2018-09-30")
.map(lambda img: img.divide(10000))
.median()
)
vis_params = [
{"bands": ["B4", "B3", "B2"], "min": 0, "max": 0.3, "gamma": 1.3},
{"bands": ["B8", "B11", "B4"], "min": 0, "max": 0.3, "gamma": 1.3},
{"bands": ["B8", "B4", "B3"], "min": 0, "max": 0.3, "gamma": 1.3},
{"bands": ["B12", "B12", "B4"], "min": 0, "max": 0.3, "gamma": 1.3},
]
labels = [
"Natural Color (B4/B3/B2)",
"Land/Water (B8/B11/B4)",
"Color Infrared (B8/B4/B3)",
"Vegetation (B12/B11/B4)",
]
geemap.linked_maps(
rows=2,
cols=2,
height="300px",
center=[38.4151, 21.2712],
zoom=12,
ee_objects=[image],
vis_params=vis_params,
labels=labels,
label_position="topright",
)
Map = geemap.Map(center=[40, -100], zoom=4)
collection = ee.ImageCollection("USGS/NLCD_RELEASES/2019_REL/NLCD").select("landcover")
vis_params = {"bands": ["landcover"]}
years = collection.aggregate_array("system:index").getInfo()
years
Map.ts_inspector(
left_ts=collection,
right_ts=collection,
left_names=years,
right_names=years,
left_vis=vis_params,
right_vis=vis_params,
width="80px",
)
Map
Map = geemap.Map()
collection = (
ee.ImageCollection("MODIS/MCD43A4_006_NDVI")
.filter(ee.Filter.date("2018-06-01", "2018-07-01"))
.select("NDVI")
)
vis_params = {
"min": 0.0,
"max": 1.0,
"palette": [
"FFFFFF",
"CE7E45",
"DF923D",
"F1B555",
"FCD163",
"99B718",
"74A901",
"66A000",
"529400",
"3E8601",
"207401",
"056201",
"004C00",
"023B01",
"012E01",
"011D01",
"011301",
],
}
Map.add_time_slider(collection, vis_params, time_interval=2)
Map
Map = geemap.Map()
collection = (
ee.ImageCollection("NOAA/GFS0P25")
.filterDate("2018-12-22", "2018-12-23")
.limit(24)
.select("temperature_2m_above_ground")
)
vis_params = {
"min": -40.0,
"max": 35.0,
"palette": ["blue", "purple", "cyan", "green", "yellow", "red"],
}
labels = [str(n).zfill(2) + ":00" for n in range(0, 24)]
Map.add_time_slider(collection, vis_params, labels=labels, time_interval=1, opacity=0.8)
Map
Map = geemap.Map(center=[37.75, -122.45], zoom=12)
collection = (
ee.ImageCollection("COPERNICUS/S2_SR")
.filterBounds(ee.Geometry.Point([-122.45, 37.75]))
.filterMetadata("CLOUDY_PIXEL_PERCENTAGE", "less_than", 10)
)
vis_params = {"min": 0, "max": 4000, "bands": ["B8", "B4", "B3"]}
Map.add_time_slider(collection, vis_params)
Map
import geemap.colormaps as cm
Map = geemap.Map()
dem = ee.Image("USGS/SRTMGL1_003")
hillshade = ee.Terrain.hillshade(dem)
vis = {"min": 0, "max": 6000, "palette": cm.palettes.terrain}
blend = geemap.blend(top_layer=dem, top_vis=vis)
Map.addLayer(hillshade, {}, "Hillshade")
Map.addLayer(blend, {}, "Shaded relief")
Map.add_colorbar(vis, label="Elevation (m)")
Map.setCenter(91.4206, 27.3225, zoom=9)
Map
left_layer = geemap.ee_tile_layer(blend, {}, "Shaded relief")
right_layer = geemap.ee_tile_layer(hillshade, {}, "Hillshade")
Map.split_map(left_layer, right_layer)
nlcd = ee.Image("USGS/NLCD_RELEASES/2019_REL/NLCD/2019").select("landcover")
nlcd_vis = {"bands": ["landcover"]}
blend = geemap.blend(nlcd, dem, top_vis=nlcd_vis, expression="a*b")
Map.addLayer(blend, {}, "Blend NLCD")
Map.add_legend(builtin_legend="NLCD", title="NLCD Land Cover")
Map.setCenter(-118.1310, 35.6816, 10)
import geemap.colormaps as cm
Map = geemap.Map()
image = ee.Image("USGS/SRTMGL1_003")
hillshade = ee.Terrain.hillshade(image)
Map.addLayer(hillshade, {}, "Hillshade")
Map
vis_params = {"min": 0, "max": 5000, "palette": cm.palettes.dem}
Map.addLayer(image, vis_params, "dem", True, 0.5)
Map.add_colorbar(vis_params, label="Elevation (m)")
contours = geemap.create_contours(image, 0, 5000, 100, region=None)
Map.addLayer(contours, {"palette": "black"}, "contours")
Map.setCenter(-119.3678, 37.1671, 12)
Map = geemap.Map()
centroid = ee.Geometry.Point([-122.4439, 37.7538])
image = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR").filterBounds(centroid).first()
vis = {"min": 0, "max": 3000, "bands": ["B5", "B4", "B3"]}
Map.centerObject(centroid, 8)
Map.addLayer(image, vis, "Landsat-8")
Map
image.propertyNames().getInfo()
image.get("CLOUD_COVER").getInfo() # 0.05
props = geemap.image_props(image)
props.getInfo()
stats = geemap.image_stats(image, scale=30)
stats.getInfo()
Map = geemap.Map(center=[40, -100], zoom=4)
# Add NASA SRTM
dem = ee.Image("USGS/SRTMGL1_003")
dem_vis = {
"min": 0,
"max": 4000,
"palette": ["006633", "E5FFCC", "662A00", "D8D8D8", "F5F5F5"],
}
Map.addLayer(dem, dem_vis, "SRTM DEM")
# Add 5-year Landsat TOA composite
landsat = ee.Image("LANDSAT/LE7_TOA_5YEAR/1999_2003")
landsat_vis = {"bands": ["B4", "B3", "B2"], "gamma": 1.4}
Map.addLayer(landsat, landsat_vis, "Landsat", False)
# Add US Census States
states = ee.FeatureCollection("TIGER/2018/States")
style = {"fillColor": "00000000"}
Map.addLayer(states.style(**style), {}, "US States")
Map
out_dem_stats = "dem_stats.csv"
geemap.zonal_stats(
dem, states, out_dem_stats, stat_type="MEAN", scale=1000, return_fc=False
)
out_landsat_stats = "landsat_stats.csv"
geemap.zonal_stats(
landsat,
states,
out_landsat_stats,
stat_type="MEAN",
scale=1000,
return_fc=False,
)
Map = geemap.Map(center=[40, -100], zoom=4)
# Add NLCD data
dataset = ee.Image("USGS/NLCD_RELEASES/2019_REL/NLCD/2019")
landcover = dataset.select("landcover")
Map.addLayer(landcover, {}, "NLCD 2019")
# Add US census states
states = ee.FeatureCollection("TIGER/2018/States")
style = {"fillColor": "00000000"}
Map.addLayer(states.style(**style), {}, "US States")
# Add NLCD legend
Map.add_legend(title="NLCD Land Cover", builtin_legend="NLCD")
Map
nlcd_stats = "nlcd_stats.csv"
geemap.zonal_stats_by_group(
landcover,
states,
nlcd_stats,
stat_type="SUM",
denominator=1e6,
decimal_places=2,
)
nlcd_stats = "nlcd_stats_pct.csv"
geemap.zonal_stats_by_group(
landcover,
states,
nlcd_stats,
stat_type="PERCENTAGE",
denominator=1e6,
decimal_places=2,
)
Map = geemap.Map(center=[40, -100], zoom=4)
dem = ee.Image("USGS/3DEP/10m")
vis = {"min": 0, "max": 4000, "palette": "terrain"}
Map.addLayer(dem, vis, "DEM")
Map
landcover = ee.Image("USGS/NLCD_RELEASES/2019_REL/NLCD/2019").select("landcover")
Map.addLayer(landcover, {}, "NLCD 2019")
Map.add_legend(title="NLCD Land Cover Classification", builtin_legend="NLCD")
stats = geemap.image_stats_by_zone(dem, landcover, reducer="MEAN")
stats
stats.to_csv("mean.csv", index=False)
geemap.image_stats_by_zone(dem, landcover, out_csv="std.csv", reducer="STD")
Map = geemap.Map(center=[40, -100], zoom=4)
dem = ee.Image("USGS/SRTMGL1_003")
landsat7 = ee.Image("LANDSAT/LE7_TOA_5YEAR/1999_2003")
vis_params = {
"min": 0,
"max": 4000,
"palette": ["006633", "E5FFCC", "662A00", "D8D8D8", "F5F5F5"],
}
Map.addLayer(
landsat7,
{"bands": ["B4", "B3", "B2"], "min": 20, "max": 200, "gamma": 2},
"Landsat 7",
)
Map.addLayer(dem, vis_params, "SRTM DEM", True, 1)
Map
in_shp = "us_cities.shp"
url = "https://github.com/giswqs/data/raw/main/us/us_cities.zip"
geemap.download_file(url)
in_fc = geemap.shp_to_ee(in_shp)
Map.addLayer(in_fc, {}, "Cities")
geemap.extract_values_to_points(in_fc, dem, out_fc="dem.shp")
geemap.shp_to_gdf("dem.shp")
geemap.extract_values_to_points(in_fc, landsat7, "landsat.csv")
geemap.csv_to_df("landsat.csv")
Map = geemap.Map(center=[40, -100], zoom=4)
Map.add_basemap("TERRAIN")
image = ee.Image("USGS/SRTMGL1_003")
vis_params = {
"min": 0,
"max": 4000,
"palette": ["006633", "E5FFCC", "662A00", "D8D8D8", "F5F5F5"],
}
Map.addLayer(image, vis_params, "SRTM DEM", True, 0.5)
Map
line = Map.user_roi
if line is None:
line = ee.Geometry.LineString(
[[-120.2232, 36.3148], [-118.9269, 36.7121], [-117.2022, 36.7562]]
)
Map.addLayer(line, {}, "ROI")
Map.centerObject(line)
reducer = "mean"
transect = geemap.extract_transect(
image, line, n_segments=100, reducer=reducer, to_pandas=True
)
transect
geemap.line_chart(
data=transect,
x="distance",
y="mean",
markers=True,
x_label="Distance (m)",
y_label="Elevation (m)",
height=400,
)
transect.to_csv("transect.csv")
Map = geemap.Map()
collection = (
ee.ImageCollection("MODIS/061/MOD13A2")
.filterDate("2015-01-01", "2019-12-31")
.select("NDVI")
)
image = collection.toBands()
ndvi_vis = {
"min": 0.0,
"max": 9000.0,
"palette": "ndvi",
}
Map.addLayer(image, {}, "MODIS NDVI Time-series")
Map.addLayer(image.select(0), ndvi_vis, "First image")
Map
dates = geemap.image_dates(collection).getInfo()
dates
len(dates)
Map.set_plot_options(add_marker_cluster=True)
Map.roi_reducer = ee.Reducer.mean()
Map
Map.extract_values_to_points("ndvi.csv")
collection = ee.ImageCollection("LANDSAT/LC08/C02/T1_L2")
image = geemap.image_count(
collection, region=None, start_date="2021-01-01", end_date="2022-01-01", clip=False
)
Map = geemap.Map()
vis = {"min": 0, "max": 60, "palette": "coolwarm"}
Map.addLayer(image, vis, "Image Count")
Map.add_colorbar(vis, label="Landsat 8 Image Count")
countries = ee.FeatureCollection(geemap.examples.get_ee_path("countries"))
style = {"color": "00000088", "width": 1, "fillColor": "00000000"}
Map.addLayer(countries.style(**style), {}, "Countries")
Map
Map = geemap.Map()
collection = ee.ImageCollection("LANDSAT/LC08/C02/T1").filterDate(
"2021-01-01", "2022-01-01"
)
composite = ee.Algorithms.Landsat.simpleComposite(collection)
vis_params = {"bands": ["B5", "B4", "B3"], "max": 128}
Map.setCenter(-122.3578, 37.7726, 10)
Map.addLayer(composite, vis_params, "TOA composite")
Map
customComposite = ee.Algorithms.Landsat.simpleComposite(
**{"collection": collection, "percentile": 30, "cloudScoreRange": 5}
)
Map.addLayer(customComposite, vis_params, "Custom TOA composite")
Map.setCenter(-105.4317, 52.5536, 11)
vis_params = [
{"bands": ["B4", "B3", "B2"], "min": 0, "max": 128},
{"bands": ["B5", "B4", "B3"], "min": 0, "max": 128},
{"bands": ["B7", "B6", "B4"], "min": 0, "max": 128},
{"bands": ["B6", "B5", "B2"], "min": 0, "max": 128},
]
labels = [
"Natural Color (4, 3, 2)",
"Color Infrared (5, 4, 3)",
"Short-Wave Infrared (7, 6 4)",
"Agriculture (6, 5, 2)",
]
geemap.linked_maps(
rows=2,
cols=2,
height="300px",
center=[37.7726, -122.1578],
zoom=9,
ee_objects=[composite],
vis_params=vis_params,
labels=labels,
label_position="topright",
)
Map = geemap.Map()
image = ee.Image("LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318").select(
["B5", "B4", "B3"]
)
vis_params = {"min": 0, "max": 0.5, "gamma": [0.95, 1.1, 1]}
Map.centerObject(image)
Map.addLayer(image, vis_params, "Landsat")
Map
region = ee.Geometry.BBox(-122.5955, 37.5339, -122.0982, 37.8252)
fc = ee.FeatureCollection(region)
style = {"color": "ffff00ff", "fillColor": "00000000"}
Map.addLayer(fc.style(**style), {}, "ROI")
Map
geemap.ee_export_image(image, filename="landsat.tif", scale=30, region=region)
projection = image.select(0).projection().getInfo()
projection
crs = projection["crs"]
crs_transform = projection["transform"]
geemap.ee_export_image(
image,
filename="landsat_crs.tif",
crs=crs,
crs_transform=crs_transform,
region=region,
)
geemap.download_ee_image(image, filename="landsat_full.tif", scale=60)
fishnet = geemap.fishnet(image.geometry(), rows=4, cols=4, delta=0.5)
style = {"color": "ffff00ff", "fillColor": "00000000"}
Map.addLayer(fishnet.style(**style), {}, "Fishnet")
Map
geemap.download_ee_image_tiles(
image, fishnet, out_dir=".", prefix="landsat_", crs="EPSG:3857", scale=30
)
geemap.ee_export_image_to_drive(
image, description="landsat", folder="export", region=region, scale=30
)
assetId = "landsat_sfo"
geemap.ee_export_image_to_asset(
image, description="landsat", assetId=assetId, region=region, scale=30
)
region = ee.Geometry.BBox(-122.5003, 37.7233, -122.3410, 37.8026)
rgb_img = geemap.ee_to_numpy(image, region=region)
print(rgb_img.shape)
import matplotlib.pyplot as plt
rgb_img_test = (255 * ((rgb_img[:, :, 0:3]) + 0.2)).astype("uint8")
plt.imshow(rgb_img_test)
plt.show()
point = ee.Geometry.Point(-99.2222, 46.7816)
collection = (
ee.ImageCollection("USDA/NAIP/DOQQ")
.filterBounds(point)
.filterDate("2008-01-01", "2018-01-01")
.filter(ee.Filter.listContains("system:band_names", "N"))
)
collection.aggregate_array("system:index").getInfo()
out_dir = os.path.expanduser("~/Downloads")
geemap.ee_export_image_collection(collection, out_dir=out_dir, scale=10)
geemap.ee_export_image_collection_to_drive(collection, folder="export", scale=10)
geemap.ee_export_image_collection_to_asset(collection)
Map = geemap.Map()
fc = ee.FeatureCollection("USDOS/LSIB_SIMPLE/2017").filter(
ee.Filter.eq("wld_rgn", "Europe")
)
Map.addLayer(fc, {}, "Europe")
Map.centerObject(fc, 3)
Map
geemap.ee_to_shp(fc, filename="europe.shp", selectors=None)
geemap.ee_export_vector(fc, filename="europe2.shp")
geemap.ee_to_geojson(fc, filename="europe.geojson")
geemap.ee_to_csv(fc, filename="europe.csv")
gdf = geemap.ee_to_gdf(fc)
gdf
df = geemap.ee_to_df(fc)
df
geemap.ee_export_vector_to_drive(
fc, description="europe", fileFormat="SHP", folder="export"
)
geemap.ee_export_vector_to_asset(fc, description="Exporting Europe", assetId="europe")
Map = geemap.Map()
image = ee.Image("USGS/SRTMGL1_003")
vis_params = {
"min": 0,
"max": 4000,
"palette": ["006633", "E5FFCC", "662A00", "D8D8D8", "F5F5F5"],
}
Map.addLayer(image, vis_params, "SRTM DEM", True)
Map
Map.to_html(
filename="mymap.html", title="Earth Engine Map", width="100%", height="800px"
)