Interactive Cloud Computing with Google Earth Engine and geemap
Notebook: https://geemap.org/workshops/NCSU_2023
Earth Engine: https://earthengine.google.com
Geemap: https://geemap.org
Introduction (10 mins)
This notebook is for the workshop presented at the GIS Week at North Carolina State University.
Abstract
This workshop provides an introduction to cloud-based geospatial analysis using the Earth Engine Python API. Attendees will learn the basics of Earth Engine data types and how to visualize, analyze, and export Earth Engine data in a Jupyter environment with geemap. Through practical examples and hands-on exercises, attendees will enhance their learning experience. During each hands-on session, attendees will walk through Jupyter Notebook examples on Google Colab. At the end of each session, they will complete a hands-on exercise to apply the knowledge they have learned.
Prerequisites
To use geemap and the Earth Engine Python API, you must register for an Earth Engine account and follow the instructions here to create a Cloud Project. Earth Engine is free for noncommercial and research use. To test whether you can use authenticate the Earth Engine Python API, please run this notebook on Google Colab.
It is recommended that attendees have a basic understanding of Python and Jupyter Notebook.
Familiarity with the Earth Engine JavaScript API is not required but will be helpful.
Attendees can use Google Colab to follow this workshop without installing anything on their computer.
Introduction to Earth Engine and geemap (15 mins)
Earth Engine is free for noncommercial and research use. For more than a decade, Earth Engine has enabled planetary-scale Earth data science and analysis by nonprofit organizations, research scientists, and other impact users.
With the launch of Earth Engine for commercial use, commercial customers will be charged for Earth Engine services. However, Earth Engine will remain free of charge for noncommercial use and research projects. Nonprofit organizations, academic institutions, educators, news media, Indigenous governments, and government researchers are eligible to use Earth Engine free of charge, just as they have done for over a decade.
The geemap Python package is built upon the Earth Engine Python API and open-source mapping libraries. It allows Earth Engine users to interactively manipulate, analyze, and visualize geospatial big data in a Jupyter environment. Since its creation in April 2020, geemap has received over 2,900 GitHub stars and is being used by over 1,000 projects on GitHub.
Google Colab and Earth Engine Python API authentication (5 mins)
Change Colab dark theme
Currently, ipywidgets does not work well with Colab dark theme. Some of the geemap widgets may not display properly in Colab dark theme.It is recommended that you change Colab to the light theme.

Install geemap
The geemap package is pre-installed in Google Colab and is updated to the latest minor or major release every few weeks. Some optional dependencies of geemap being used by this notebook are not pre-installed in Colab. Uncomment the following line to install geemap and some optional dependencies.
Import libraries
Import the earthengine-api and geemap.
Authenticate and initialize Earth Engine
You will need to create a Google Cloud Project and enable the Earth Engine API for the project. You can find detailed instructions here.
Creating interactive maps
Let's create an interactive map using the ipyleaflet plotting backend. The geemap.Map class inherits the ipyleaflet.Map class. Therefore, you can use the same syntax to create an interactive map as you would with ipyleaflet.Map.
To display it in a Jupyter notebook, simply ask for the object representation:
To customize the map, you can specify various keyword arguments, such as center ([lat, lon]), zoom, width, and height. The default width is 100%, which takes up the entire cell width of the Jupyter notebook. The height argument accepts a number or a string. If a number is provided, it represents the height of the map in pixels. If a string is provided, the string must be in the format of a number followed by px, e.g., 600px.
To hide a control, set control_name to False, e.g., draw_ctrl=False.
Adding basemaps
There are several ways to add basemaps to a map. You can specify the basemap to use in the basemap keyword argument when creating the map. Alternatively, you can add basemap layers to the map using the add_basemap method. Geemap has hundreds of built-in basemaps available that can be easily added to the map with only one line of code.
Create a map by specifying the basemap to use as follows. For example, the Esri.WorldImagery basemap represents the Esri world imagery basemap.
You can add as many basemaps as you like to the map. For example, the following code adds the OpenTopoMap basemap to the map above:
Print out the first 10 basemaps:
You can also change basemaps interactively using the basemap GUI.
Using Earth Engine data (30 mins)
Earth Engine data types (Image, ImageCollection, Geometry, Feature, FeatureCollection)
Earth Engine objects are server-side objects rather than client-side objects, which means that they are not stored locally on your computer. Similar to video streaming services (e.g., YouTube, Netflix, and Hulu), which store videos/movies on their servers, Earth Engine data are stored on the Earth Engine servers. We can stream geospatial data from Earth Engine on-the-fly without having to download the data just like we can watch videos from streaming services using a web browser without having to download the entire video to your computer.
Image: the fundamental raster data type in Earth Engine.
ImageCollection: a stack or time-series of images.
Geometry: the fundamental vector data type in Earth Engine.
Feature: a Geometry with attributes.
FeatureCollection: a set of features.
Image
Raster data in Earth Engine are represented as Image objects. Images are composed of one or more bands and each band has its own name, data type, scale, mask and projection. Each image has metadata stored as a set of properties.
Loading Earth Engine images
Visualizing Earth Engine images
ImageCollection
An ImageCollection is a stack or sequence of images. An ImageCollection can be loaded by passing an Earth Engine asset ID into the ImageCollection constructor. You can find ImageCollection IDs in the Earth Engine Data Catalog.
Loading image collections
For example, to load the image collection of the Sentinel-2 surface reflectance:
Visualizing image collections
To visualize an Earth Engine ImageCollection, we need to convert an ImageCollection to an Image by compositing all the images in the collection to a single image representing, for example, the min, max, median, mean or standard deviation of the images. For example, to create a median value image from a collection, use the collection.median() method. Let's create a median image from the Sentinel-2 surface reflectance collection:
Filtering image collections
FeatureCollection
A FeatureCollection is a collection of Features. A FeatureCollection is analogous to a GeoJSON FeatureCollection object, i.e., a collection of features with associated properties/attributes. Data contained in a shapefile can be represented as a FeatureCollection.
Loading feature collections
The Earth Engine Data Catalog hosts a variety of vector datasets (e.g,, US Census data, country boundaries, and more) as feature collections. You can find feature collection IDs by searching the data catalog. For example, to load the TIGER roads data by the U.S. Census Bureau:
Filtering feature collections
Visualizing feature collections
Earth Engine Data Catalog
The Earth Engine Data Catalog hosts a variety of geospatial datasets. As of October 2023, the catalog contains over 1,000 datasets with a total size of over 80 petabytes. Some notable datasets include: Landsat, Sentinel, MODIS, NAIP, etc. For a complete list of datasets in CSV or JSON formats, see the Earth Engine Datasets List.
Searching for datasets
The Earth Engine Data Catalog is searchable. You can search datasets by name, keyword, or tag. For example, enter "elevation" in the search box will filter the catalog to show only datasets containing "elevation" in their name, description, or tags. 52 datasets are returned for this search query. Scroll down the list to find the NASA SRTM Digital Elevation 30m dataset. On each dataset page, you can find the following information, including Dataset Availability, Dataset Provider, Earth Engine Snippet, Tags, Description, Code Example, and more (see {numref}ch03_gee_srtm). One important piece of information is the Image/ImageCollection/FeatureCollection ID of each dataset, which is essential for accessing the dataset through the Earth Engine JavaScript or Python APIs.

Using the datasets module
Exercise 1 - Creating cloud-free imagery
Create a cloud-free imagery for a state of your choice for the year of 2022. You can use either Landsat 9 or Sentinel-2 imagery. Relevant Earth Engine assets:

Visualizing Earth Engine data (30 mins)
Geemap Inspector tool, plotting tool, interactive GUI for data visualization
Using the inspector tool
Using the plotting tool
Set plotting options for Landsat.
Set plotting options for Hyperion.
Legends, color bars, and labels
Built-in legends
Add NLCD WMS layer and legend to the map.
Add NLCD Earth Engine layer and legend to the map.
Custom legends
Add a custom legend by specifying the colors and labels.
Add a custom legend by specifying a dictionary of colors and labels.
Creating color bars
Add a horizontal color bar.
Add a vertical color bar.
Make the color bar background transparent.
Split-panel maps
Create a split map with basemaps. Note that ipyleaflet has a bug with the SplitControl. You can't pan the map, which should be resolved in the next ipyleaflet release.
Create a split map with Earth Engine layers.
Exercise 2 - Creating land cover maps with a legend
Create a split map for visualizing NLCD land cover change in Texas between 2001 and 2019. Add the NLCD legend to the map. Relevant Earth Engine assets:

Analyzing Earth Engine data (30 mins)
Image descriptive statistics
Use a sample Landsat image.
Check image properties.
Check image property values.
Get specific image properties.
Get image properties with easy-to-read time format.
Compute image descriptive statistics.
Zonal statistics
Zonal statistics
Add Earth Engine data to the map.
Compute zonal statistics. In this case, we compute the mean elevation of each state and export the results to a CSV file.
Display the csv file as a table.
Compute zonal statistics of mean spectral values of each state.
Zonal statistics by group
Compute zonal statistics by group. In this case, we compute the area of each land cover type in each state and export the results to a CSV file.
Compute zonal statistics by group and convert the area unit from square meters to square kilometers.
Calculate the percentage of each land cover type in each state.
Exercise 3 - Zonal statistics
Find out which state has the highest mean temperature on in the United States on June 28, 2023. Relevant Earth Engine assets:

Creating satellite timelapse animations (30 mins)
Creating satellite timeseries
Use the Harmonized Sentinel-2 MSI dataset to create a timeseries for a given location.
Specify the location of interest and date range.
Create an annual composite.
Display the timeseries.
Creating satellite timelapse animations
NAIP timelapse
Landsat timelapse
Pan and zoom the map to an area of interest. Use the drawing tools to draw a rectangle on the map. If no rectangle is drawn, the default rectangle shown below will be used.
Sentinel-2 timelapse
Pan and zoom the map to an area of interest. Use the drawing tools to draw a rectangle on the map. If no rectangle is drawn, the default rectangle shown below will be used.
MODIS timelapse
MODIS vegetation indices
MODIS temperature
GOES timelapse
Exercise 4 - Creating timelapse animations
Use the geemap timelapse GUI to create a timelapse animation for any location of your choice. Share the timelapse on social media and use the hashtagd such as #EarthEngine and #geemap. See this example.
