Cloud Computing with Earth Engine and Geemap
Notebook: https://geemap.org/workshops/HGAC_2024
Earth Engine: https://earthengine.google.com
Geemap: https://geemap.org
Introduction
This notebook is for the workshop presented at the Houston Area GIS Day Workshops.
Participants will dive into Google Earth Engine and Geemap to create interactive maps and analyze large-scale geospatial datasets. Topics include:
Building interactive maps
Visualizing and analyzing Earth Engine datasets
Exploring Earth Engine Data Catalogs
Exporting data for further use
Creating interactive charts from Earth Engine datasets
Creating stunning timelapse animations
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 Google Earth Engine
Google Earth Engine Overview
Google Earth Engine is a cloud-computing platform that enables scientific analysis and visualization of large-scale geospatial datasets. It provides a rich data catalog and processing capabilities, allowing users to analyze satellite imagery and geospatial data at planetary scale.
Earth Engine is free for noncommercial and research use. Nonprofit organizations, research institutions, educators, Indigenous governments, and government researchers can continue using Earth Engine for free, as they have for more than a decade. However, commercial users may require a paid license.
Installing Geemap
The geemap package simplifies the use of Google Earth Engine in Python, offering an intuitive API for visualization and analysis in Jupyter notebooks. In Google Colab, geemap is pre-installed, but you may need to install additional dependencies for certain features. To install the latest version with optional dependencies, use the following command:
Import Libraries
To start, import the necessary libraries for working with Google Earth Engine (GEE) and geemap.
Authenticate and Initialize Earth Engine
To authenticate and initialize your Earth Engine environment, you’ll need to create a Google Cloud Project and enable the Earth Engine API for the project if you have not done so already. You can find detailed setup instructions here.
Creating Interactive Maps
Let’s create an interactive map using the ipyleaflet plotting backend. The geemap.Map class inherits from the ipyleaflet.Map class, so the syntax is similar to creating an interactive map with ipyleaflet.Map.
To display the map in a Jupyter notebook, simply enter the map object:
To customize the map’s display, you can set various keyword arguments, such as center (latitude and longitude), zoom, width, and height. By default, the width is 100%, filling the entire width of the Jupyter notebook cell. The height parameter can be a number (in pixels) or a string with a pixel format, e.g., 600px.
Example Maps
Map of the Contiguous United States
To center the map on the contiguous United States, use:
Map of the state of Tennessee
Map of the city of Knoxville, TN
To hide specific map controls, set the corresponding control argument to False, such as draw_ctrl=False to hide the drawing control.
Adding Basemaps
There are several ways to add basemaps to a map in geemap. You can specify a basemap in the basemap keyword argument when creating the map, or you can add additional basemap layers using the add_basemap method. Geemap provides access to hundreds of built-in basemaps, making it easy to add layers to a map with a single line of code.
To create a map with a specific basemap, use the basemap argument as shown below. For example, Esri.WorldImagery provides an Esri world imagery basemap.
Adding Multiple Basemaps
You can add multiple basemaps to a map by calling add_basemap multiple times. For example, the following code adds the Esri.WorldTopoMap and OpenTopoMap basemaps to the existing map:
Listing Available Basemaps
To view the first 10 available basemaps, use:
Google Basemaps
Due to licensing restrictions, Google basemaps are not included in geemap by default. However, users can add Google basemaps manually at their own discretion using the following URLs:
For example, to add Google Satellite as a tile layer:
You can also add text to the map using the add_text method. The text will be displayed at the specified location on the map.
Introduction to Interactive Maps and Tools
Basemap Selector
The basemap selector allows you to choose from various basemaps via a dropdown menu. Adding it to your map provides easy access to different map backgrounds.
Layer Manager
The layer manager provides control over layer visibility and transparency. It enables toggling layers on and off and adjusting transparency with a slider, making it easy to customize map visuals.
Inspector Tool
The inspector tool allows you to click on the map to query Earth Engine data at specific locations. This is helpful for examining the properties of datasets directly on the map.
Layer Editor
With the layer editor, you can adjust visualization parameters of Earth Engine data for better clarity and focus. It supports single-band images, multi-band images, and feature collections.
Single-Band image
Multi-Band image
Feature Collection
Draw Control
The draw control feature allows you to draw shapes directly on the map, converting them automatically into Earth Engine objects. Access the drawn features as follows:
To return the last drawn feature as an
ee.Geometry(), usem.user_roiTo return all drawn features as an
ee.FeatureCollection(), usem.user_rois
The Earth Engine Data Catalog
The Earth Engine Data Catalog hosts an extensive collection of geospatial datasets. Currently, he catalog includes over 1,000 datasets with a combined size exceeding 100 petabytes. Notable datasets include Landsat, Sentinel, MODIS, and NAIP. For a comprehensive list of datasets in CSV or JSON format, refer to the Earth Engine Datasets List.
Searching Datasets on the Earth Engine Website
To browse datasets directly on the Earth Engine website:
View the full catalog: https://developers.google.com/earth-engine/datasets/catalog
Search by tags: https://developers.google.com/earth-engine/datasets/tags
Searching Datasets Within Geemap
The Earth Engine Data Catalog can also be searched directly from geemap. Use keywords to filter datasets by name, tag, or description. For instance, searching for "elevation" will display only datasets containing "elevation" in their metadata, returning 52 datasets. You can scroll through the results to locate the NASA SRTM Digital Elevation 30m dataset.

Each dataset page contains detailed information such as availability, provider, Earth Engine snippet, tags, description, and example code. The Image, ImageCollection, or FeatureCollection ID is essential for accessing the dataset in Earth Engine’s JavaScript or Python APIs.
Using the Datasets Module in Geemap
Geemap offers a built-in datasets module to access specific datasets programmatically. For example, to access the USGS GAP Alaska dataset:
To retrieve metadata for a specific dataset, use the get_metadata function:
Earth Engine Data Types
Earth Engine objects are server-side entities, meaning they are stored and processed on Earth Engine’s servers rather than locally. This setup is comparable to streaming services (e.g., YouTube or Netflix) where the data remains on the provider’s servers, allowing us to access and process geospatial data in real time without downloading it to our local devices.
Image: The core raster data type in Earth Engine, representing single images or scenes.
ImageCollection: A collection or sequence of images, often used for time series analysis.
Geometry: The fundamental vector data type, including shapes like points, lines, and polygons.
Feature: A Geometry with associated attributes, used to add descriptive data to vector shapes.
FeatureCollection: A collection of Features, similar to a shapefile with attribute data.
Earth Engine Raster Data
Image
In Earth Engine, raster data is represented as Image objects. Each Image is composed of bands, with each band having its own name, data type, scale, mask, and projection. Metadata for each image is stored as a set of properties.
Loading Earth Engine Images
To load images, use the Earth Engine asset ID within the ee.Image constructor. Asset IDs can be found in the Earth Engine Data Catalog. For example, to load the NASA SRTM Digital Elevation dataset:
Visualizing Earth Engine Images
To visualize an image, you can specify visualization parameters such as minimum and maximum values and color palettes.
ImageCollection
An ImageCollection represents a sequence of images, often used for temporal data like satellite image time series. ImageCollections are created by passing an Earth Engine asset ID into the ImageCollection constructor. Asset IDs are available in the Earth Engine Data Catalog.
Loading Image Collections
To load an ImageCollection, such as the Sentinel-2 surface reflectance collection:
Filtering Image Collections
You can filter ImageCollections by location and time. For example, to filter images covering a specific location with low cloud cover:
To view the filtered collection on a map:
Visualizing Image Collections
To visualize an ImageCollection as a single composite image, you need to aggregate the collection. For example, using the collection.median() method creates an image representing the median value across the collection.
Earth Engine Vector Data
A FeatureCollection is a collection of Features. It functions similarly to a GeoJSON FeatureCollection, where features include associated properties or attributes. For example, a shapefile’s data can be represented as a FeatureCollection.
Loading Feature Collections
The Earth Engine Data Catalog includes various vector datasets, such as U.S. Census data and country boundaries, as feature collections. Feature Collection IDs are accessible by searching the data catalog. For example, to load the TIGER roads data by the U.S. Census Bureau:
Filtering Feature Collections
The filter method allows you to filter a FeatureCollection based on certain attribute values. For instance, we can filter for specific states using the eq filter to select "Tennessee":
To retrieve properties of the first feature in the collection, use:
You can also convert a FeatureCollection to a Pandas DataFrame for easier analysis with:
A FeatureCollection can be used to clip an image. The clipToCollection method clips an image to the geometry of a feature collection. For example, to clip a Landsat image to the boundary of France:
Visualizing Feature Collections
Once loaded, feature collections can be visualized on an interactive map. For example, visualizing U.S. state boundaries from the census data:
Feature collections can also be styled with additional parameters. To apply a custom style, specify options like color and line width:
Using add_styled_vector, you can apply a color palette to style different features by attribute:
More Tools for Visualizing Earth Engine Data
Using the Plotting Tool
The plotting tool in geemap enables visualization of Earth Engine data layers. In this example, Landsat 7 and Hyperion data are added with specific visualization parameters, allowing for comparison of these datasets. The plot GUI is then added to facilitate detailed exploration of the data.
Set the plotting options for Landsat to add marker clusters and overlays, enhancing the interactivity of plotted data on the map.
Adjust the plotting options for Hyperion data by setting a bar plot type with marker clusters, suitable for visualizing Hyperion’s data values in bar format.
Legends
Built-in Legends
Geemap provides built-in legends that can be easily added to maps for better interpretability of data classes. Here, an NLCD legend is added to both a WMS layer and an Earth Engine land cover layer, giving quick visual reference to the data's classification scheme.
Print out all available built-in legends, which can be used with various data layers to enhance map readability.
Add an NLCD WMS layer along with its corresponding legend, which appears as an overlay, providing users with an informative legend display.
Add an Earth Engine layer for NLCD land cover and display its legend, specifying title, legend type, and dimensions for user convenience.
Custom Legends
Create a custom legend by defining unique labels and colors for each class, allowing for flexible map customization. This example uses a color palette for labeling several map categories.
Define a custom legend using a dictionary that links specific colors to labels. This approach provides flexibility to represent specific categories in the data, such as various land cover types.
Color Bars
Add a horizontal color bar representing elevation data. This example demonstrates how to add an SRTM elevation layer and overlay a color bar for quick visual reference of elevation values.
Add a vertical color bar for elevation data, adjusting its orientation and dimensions to fit the map layout.
Make the color bar’s background transparent, which improves visual integration with the map when adding color bars for data layers.
Split-panel Maps
Create a split-panel map with basemaps, allowing users to compare two different basemaps side by side.
Use Earth Engine layers in a split-panel map to compare NLCD data from 2001 and 2021. This layout is effective for examining changes between datasets across time.
Linked Maps
Set up a 2x2 grid of linked maps showing Sentinel-2 imagery in different band combinations, ideal for comparing multiple visual perspectives. Note that this feature may not work in Colab.
Timeseries Inspector
Retrieve the available years in the NLCD collection for setting up a timeseries. This step helps confirm available time points for inspecting changes over time.
Use a timeseries inspector to compare changes in NLCD data across different years. This tool is ideal for temporal data visualization, showing how land cover changes in an interactive format.
Time Slider
Create a time slider to explore MODIS vegetation data, setting the slider to visualize NDVI values over a specific period. This feature allows users to track vegetation changes month-by-month.
Add a time slider for visualizing NOAA weather data over a 24-hour period, using color-coding to show temperature variations. The slider enables temporal exploration of hourly data.
Add a time slider to visualize Sentinel-2 imagery with specific bands and cloud cover filtering. This feature enables temporal analysis of imagery data, allowing users to explore seasonal and other changes over time.
Processing of Vector Data
From GeoJSON
Load GeoJSON data into an Earth Engine FeatureCollection. This example retrieves countries data from a remote URL, converting it to a FeatureCollection and visualizing it with a specified style.
From Shapefile
Download and load a shapefile of country boundaries. The shapefile is converted to a FeatureCollection for visualization on the map.
From GeoDataFrame
Read a shapefile into a GeoDataFrame using geopandas, then convert the GeoDataFrame to an Earth Engine FeatureCollection for mapping.
To GeoJSON
Filter U.S. state data to select Tennessee and save it as a GeoJSON file, which can be shared or used in other GIS tools.
To Shapefile
Export the filtered Tennessee FeatureCollection to a shapefile format for offline use or compatibility with desktop GIS software.
To GeoDataFrame
Convert an Earth Engine FeatureCollection to a GeoDataFrame for further analysis in Python or use in interactive maps.
To DataFrame
Transform an Earth Engine FeatureCollection into a pandas DataFrame, which can then be used for data analysis in Python.
To CSV
Export the FeatureCollection data to a CSV file, useful for spreadsheet applications and data reporting.
Processing of Raster Data
Extract Pixel Values
Extracting Values to Points
Load and visualize SRTM DEM and Landsat 7 imagery. Points from a shapefile of U.S. cities are added, and the tool extracts DEM values to these points, saving the results in a shapefile.
Extracting Pixel Values Along a Transect
Visualize SRTM DEM with a terrain basemap. Define a line transect, either interactively or manually, and extract elevation values along this line. Display the elevation profile in a line chart, then export it as a CSV file for further analysis.
Zonal Statistics
Zonal Statistics with an Image and a Feature Collection
This section demonstrates the use of zonal statistics to calculate the mean elevation values within U.S. state boundaries using NASA’s SRTM DEM data and a 5-year Landsat composite. The geemap.zonal_stats function exports results to CSV files for analysis.
Zonal Statistics by Group
Here, zonal statistics are applied to NLCD land cover data, calculating the area of each land cover type within each U.S. state. The results are saved to CSV files as both raw totals and percentages. This provides insights into the spatial distribution of land cover categories across states.
Zonal Statistics with Two Images
This example calculates the mean elevation values within different NLCD land cover types using DEM and NLCD data. The geemap.image_stats_by_zone function provides summary statistics (e.g., mean and standard deviation), which can be exported to CSV files for further analysis or visualization.
Map Algebra
This example demonstrates basic map algebra by computing the Normalized Difference Vegetation Index (NDVI) for a 5-year Landsat composite and the Enhanced Vegetation Index (EVI) for a Landsat 8 image. These indices are visualized with color scales to highlight areas of vegetation.
Working with Local Geospatial Data
Raster Data
Single-band and multi-band raster data can be loaded from local files. Here, a digital elevation model (DEM) is loaded and displayed with a terrain color scheme, and another raster is displayed with a false-color composite to highlight different features.
Single-Band Raster Data
Multi-Band Raster Data
Vector Data
Various vector data formats can be loaded and visualized with geemap, including GeoJSON, Shapefile, GeoDataFrame, and GeoPackage formats. GeoJSON data is styled dynamically with custom colors based on attributes, while Shapefiles and GeoDataFrames allow for simple, structured addition of geographic features to the map.
GeoJSON
Shapefile
GeoDataFrame
GeoPackage
CSV to Vector
Geemap enables easy conversion from CSV files to vector data formats like GeoJSON, Shapefile, and GeoPackage. The data from a CSV is visualized on a map, where cities are displayed with markers styled by region, and a legend is added for clear reference.
Accessing Cloud Optimized GeoTIFFs
Cloud Optimized GeoTIFFs (COG)
This section shows how to add Cloud Optimized GeoTIFF (COG) layers to a map using URLs, which allows for efficient loading and visualization of large raster files stored on the cloud. In this example, a pre-event image of the 2020 California wildfire is added to a map, allowing for remote sensing analysis without local file storage.
The COG functions also allow inspection of data, such as viewing the bounds and available bands in the GeoTIFF file. The pre- and post-event images can be compared in a split map view to analyze changes due to the fire.
SpatioTemporal Asset Catalog (STAC)
STAC collections can be accessed and visualized similarly, enabling dynamic mapping of spatiotemporal data. By specifying STAC URLs, you can view dataset bounds, center the map on a dataset, and select specific bands to add as layers. This example shows adding panchromatic and false-color imagery for enhanced visual analysis.
Exporting Earth Engine Data
Exporting Images
This section demonstrates exporting Earth Engine images. First, a Landsat image is added to the map for visualization, and a rectangular region of interest (ROI) is specified. Exporting options include saving the image locally with specified scale and region or exporting to Google Drive. It’s possible to define custom CRS and transformation settings when saving the image.
Add a Landsat image to the map.
Add a rectangle to the map.
To local drive
Check image projection.
Specify region, crs, and crs_transform.
To Google Drive
Exporting Image Collections
Image collections, like time series data, can be filtered and exported as multiple images. Here, a National Agriculture Imagery Program (NAIP) collection is filtered by date and location. The collection can then be saved locally or sent to Google Drive, making it easier to handle large datasets.
To local drive
To Google Drive
Exporting Feature Collections
Feature collections, such as state boundaries, are exportable in multiple formats (e.g., Shapefile, GeoJSON, and CSV). This example exports the Alaska state boundary as different vector formats both locally and to Google Drive. Additionally, exported data can be directly loaded into a GeoDataFrame for further manipulation in Python.
To local drive
To Google Drive
Creating Timelapse Animations
Landsat Timelapse
The Landsat timelapse tool creates animations of changes over time. Here, we use a defined region of interest (ROI) to generate timelapse GIFs for Las Vegas (1984-2023):
Sentinel-2 Timelapse
This example generates a timelapse of Sentinel-2 data for a selected ROI, with options to draw a custom ROI on the map. The timelapse spans 2017-2023, focusing on the June to September period each year.
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
The MODIS timelapse can showcase NDVI (vegetation index) or ocean color data over time. In the vegetation example, we visualize NDVI from 2000-2022 with country overlays. The temperature example animates Aqua satellite data for monthly temperature trends from 2018-2020 with continent overlays.
MODIS temperature
GOES Timelapse
GOES timelapse generation can animate atmospheric phenomena in near real-time. We create animations for different ROIs, including hurricane tracking and fire events using GOES-17 data with custom time windows and frame rates.
Charting
Charting Features
Import libraries
To create charts for Earth Engine features, import required libraries like calendar, ee, geemap, and chart.
Initialize Earth Engine using geemap.ee_initialize().
feature_by_feature
This function allows feature plotting along the x-axis, with values from selected properties represented along the y-axis. Ecoregions data is used to chart average monthly temperature across regions, where months serve as series columns.

feature.by_property
Displays average precipitation by month for each ecoregion. Properties represent precipitation values for each month, allowing for visual comparison across regions by month.

feature_groups
Plots groups of features based on property values, showing average January temperature for ecoregions divided into "Warm" and "Cold" categories.

feature_histogram
Generates a histogram displaying July precipitation distribution across a region, showing pixel count for different precipitation levels, useful for understanding data spread.

Charting Images
image_by_region
Displays monthly temperature for each ecoregion using the image_by_region function, aggregating data to visualize average temperature by month across regions.

image_regions
Generates a chart showing average monthly precipitation across regions, using properties to represent months and comparing precipitation levels.

image_by_class
Displays spectral signatures of ecoregions by wavelength, showing reflectance values across spectral bands for comparison.

image_histogram
Generates histograms to visualize MODIS surface reflectance distribution across red, NIR, and SWIR bands, providing insights into data distribution by band.

Charting Image Collections
image_series
Creates a time series chart of vegetation indices (NDVI and EVI) for a forest region, helping to track vegetation health over time.

image_series_by_region
Shows NDVI time series by region, comparing desert, forest, and grassland areas. Each region has a unique series for easy comparison.

image_doy_series
Plots average vegetation index by day of year for a specific region, showing seasonal vegetation patterns over a decade.

image_doy_series_by_year
Compares NDVI by day of year across two different years, showing how vegetation patterns vary between 2012 and 2019.

image_doy_series_by_region
Visualizes average NDVI by day of year across regions, showcasing seasonal changes for desert, forest, and grassland ecoregions.

Charting Array and List
Scatter Plot
Displays relationships between spectral bands, plotting red reflectance against NIR and SWIR reflectance to examine band correlations.


Transect Line Plot
Plots elevation along a transect line across a specific region, providing a profile view of terrain elevation.

Metadata Scatter Plot
Visualizes Landsat image metadata by plotting cloud cover against geometric RMSE, useful for quality assessment of image collections.

Mapped Function Scatter & Line Plot
Plots a sine function as a line chart, mapping mathematical functions onto chart axes for visualization.

Charting Data Table
Manual DataTable chart
Creates a chart from a manually created DataTable, such as US state populations.

Computed DataTable chart
Computes a DataTable from MODIS vegetation indices data for a forest area, then charts NDVI and EVI time series.

Interval chart
Displays annual NDVI time series with variance, showing inter-annual vegetation change and variability across the year.

Exercises
Exercise 1: Visualizing DEM Data
Find a DEM dataset in the Earth Engine Data Catalog and clip it to a specific area (e.g., your country, state, or city). Display it with an appropriate color palette. For example, the sample map below shows the DEM of the state of Colorado.

Exercise 2: Cloud-Free Composite with Sentinel-2 or Landsat
Use Sentinel-2 or Landsat-9 data to create a cloud-free composite for a specific year in a region of your choice.
Use Sentinel-2 or Landsat-9 data data to create a cloud-free composite for a specific year in a region of your choice. Display the imagery on the map with a proper band combination. For example, the sample map below shows a cloud-free false-color composite of Sentinel-2 imagery of the year 2021 for the state of Colorado.

Exercise 3: Visualizing NAIP Imagery
Use NAIP imagery to create a cloud-free imagery for a U.S. county of your choice. For example, the sample map below shows a cloud-free true-color composite of NAIP imagery for Knox County, Tennessee. Keep in mind that there might be some counties with the same name in different states, so make sure to select the correct county for the selected state.

Exercise 4: Visualizing Watershed Boundaries
Visualize the USGS Watershed Boundary Dataset with outline color only, no fill color.

Exercise 5: Visualizing Land Cover Change
Use the USGS National Land Cover Database and US Census States to create a split-panel map for visualizing land cover change (2001-2019) for a US state of your choice. Make sure you add the NLCD legend to the map.

Exercise 6: Creating a Landsat Timelapse Animation
Generate a timelapse animation using Landsat data to show changes over time for a selected region.