Interactive cloud computing with Google Earth Engine and geemap
Earth Engine: https://earthengine.google.com
Geemap: https://geemap.org
Introduction
This notebook is for the short course presented at the City+2023@Perth International Conference.
Abstract
This short course 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 and analyze Earth Engine data interactively in a Jupyter environment with geemap. Through practical examples and hands-on exercises, attendees will enhance their learning experience.
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
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,800 GitHub stars and is being used by over 1,000 projects on GitHub.
Google Colab and Earth Engine Python API authentication
Install geemap
Uncomment the following line to install geemap if you are running this notebook in Google Colab.
Import libraries
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:
Using Earth Engine data
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 March 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.

Converting Earth Engine JavaScripts to Python
Find some Earth Engine JavaScript code that you want to convert to Python. For example, you can grab some sample code from the Earth Engine Documentation.
Visualizing Earth Engine data
Using the inspector tool
Using the plotting tool
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 a dictionary of colors and labels.
Creating color bars
Add a horizontal color bar.
Add a vertical color bar.
Split-panel map and linked maps
Split-panel maps
Create a split map with basemaps.
Create a split map with Earth Engine layers.
Linked maps
Create a 2x2 linked map for visualizing Sentinel-2 imagery with different band combinations.
Timeseries inspector and time slider
Timeseries inspector
Check the available years of NLCD.
Create a timeseries inspector for NLCD.
Time slider
Create a map for visualizing MODIS vegetation data.
Create a map for visualizing weather data.
Visualizing Sentinel-2 imagery
Exercise - 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:
