Illustrations by the author
Geospatial data analysis is the field dedicated to processing, visualizing, and analyzing a special type of data called geospatial data: data in a tabular format with additional columns of location information, such as latitude and longitude, compared to regular data.
There are two main types of data: vector data and raster data. When you work with vector data, your datasets are still in a tabular format, but raster data is more similar to imagery such as satellite imagery or aerial photography.
In this article, we’ll focus on raster data provided by Google Earth Engine, a cloud computing platform that provides a vast data catalog of satellite imagery. This kind of data can be easily retrieved from a Jupyter Notebook using a life-saving Python package called Geemap. Let’s get started.
What is Google Earth Engine?
Screenshot by author. Google Earth Engine home page.
Before we start using the Python library, we need to understand the potential of Google Earth Engine. Powered by the Google Cloud Platform, this cloud-based platform hosts public and free geospatial datasets for academic, non-profit, and business purposes.
Screenshot by author. Overview of Earth Engine Data Catalog.
What’s great about this platform is that it provides a multi-petabyte catalog of raster and vector data stored on Earth Engine servers. You can get a quick overview from this link. Additionally, it provides an API that makes it easy to analyze raster datasets.
What is Geemap?
Illustration by the author. Geemap library.
Geemap is a Python library that allows you to analyze and visualize vast amounts of geospatial data from Google Earth Engine.
Prior to this package, it was possible to make computational requests via JavaScript and Python APIs, but the Python APIs were limited in functionality and poorly documented.
To fill this gap, Geemap was created to allow users to access Google Earth Engine resources with just a few lines of code. Geemap is built on eartengine-api, ipyleaflet and folium.
To install the library, simply run the following command:
To understand the full potential of this great package, we recommend trying it out on Google Colab. To get started with Geemap and Google Earth Engine, check out this free book written by Professor Qiusheng Wu.
How do I access Earth Engine?
First, you need to import two Python libraries that will be used within the tutorial.
In addition to geemap, I imported the Earth Engine Python client library called ee.
This Python library is available for authentication with Earth Engine, but using the Geemap library directly will be faster.
You need to generate an authorization code by clicking on the URL returned by this line of code. First, select your cloud project and click on the “Generate Token” button.
Screenshot by the author. Notebook authentication system.
You will then be asked to select an account, if you are using Google Colab we recommend you use the same account.
Screenshot by author. Choose your account.
next,[すべて選択]Click the check box next to[続行]Press the button. In simple terms, this step allows your notebook client to access your Earth Engine account.
Screenshot by the author. Allows the notebook client to access your Earth Engine account.
Once you do this, an authentication code will be generated that you can paste into a cell in your notebook.
Screenshot by author. Copy the authorization code.
Once you enter the verification code, you will finally be able to create and visualize this interactive map.
For now, we are just observing the base map on ipyleaflet, a Python package that allows you to visualize interactive maps within Jupyter Notebooks.
Create an interactive map
So far, we have seen how to authenticate and visualize an interactive map with one line of code. Now, we can customize the default map by specifying the latitude and longitude of the center, the zoom level and the height. To focus on the map of Europe, we chose the coordinates of Rome for the center.
m = geemap.Map(center =[41, 12]zoom=6, height=600) m
If you want to change the basemap, there are two ways to do it. The first way is to write and run the following line of code:
m.add_basemap(“Road Map”) m
Alternatively, you can change the base map manually by clicking the ring spanner icon on the right.
Additionally, you will see a list of basemaps provided by Geemap.
if basemaps = geemap.basemaps.keys() then bm is basemaps: print(bm) .
The output will be similar to the following:
OpenStreetMap Esri.WorldStreetMap Esri.WorldImagery Esri.WorldTopoMap FWS NWI Wetlands FWS NWI Wetlands Raster NLCD 2021 CONUS Land Cover NLCD 2019 CONUS Land Cover…
As you can see, there is a long series of basemaps, most of which are available thanks to OpenStreetMap, ESRI and USGS.
Earth Engine Data Types
Before you can use Geemap to its full potential, it’s important to know about the two main data types in Earth Engine. For more information, see the Google Earth Engine documentation:
Illustration by the author. Examples of vector data types: Geometry, Feature, FeatureCollection.
When working with vector data, there are three main data types you will use:
Geometry stores the coordinates needed to draw vector data on a map. Earth Engine supports three main geometry types: points, linestrings, and polygons. Features are essentially rows that combine geometry and non-geographic attributes. They are very similar to the GeoSeries class in GeoPandas. A FeatureCollection is a tabular data structure that contains a set of features. FeatureCollection and GeoDataFrame are conceptually nearly identical.
Screenshot by author. Example of image data type, showing a smoothed digital elevation model of Australia (DEM-S).
In the world of raster data, we are focused on imagery objects. Imagery in Google Earth Engine consists of one or more bands, and each band has a specific name, estimated minimum and maximum values, and a description.
If you have a collection or time series of images, ImageCollection is a better data type.
Screenshot by author. Copernicus CORINE Land Cover.
Visualize a satellite image showing the land cover map of Europe. The dataset shows the changes from 1986 to 2018.
First, load the image using ee.Image, then select the band “landcover”, and finally add the loaded dataset as a layer to the map using Map.addLayer to visualize the image.
map = geemap.Map() dataset = ee.Image(‘COPERNICUS/CORINE/V20/100m/2012’) landCover = dataset.select(‘landcover’) Map.setCenter(16.436, 39.825, 6) Map.addLayer(landCover, {}, ‘Land Cover’) Map
Screenshot by author.
Similarly, you can load and visualize a satellite image showing a land cover map of Europe. This dataset shows the changes from 1986 to 2018.
Screenshot by author. Offline high-resolution image of methane concentrations.
If you are visualizing an Earth Engine ImageCollection, the lines of code are similar, except for ee.ImageCollection.
map = geemap.Map() collection = ee.ImageCollection(‘COPERNICUS/S5P/OFFL/L3_CH4’).select(‘CH4_column_volume_mixing_ratio_dry_air’).filterDate(‘2019-06-01’, ‘2019-07-16’) band_viz = { ‘min’: 1750, ‘max’: 1900, ‘palette’: [‘black’, ‘blue’, ‘purple’, ‘cyan’, ‘green’, ‘yellow’, ‘red’]} Map.addLayer(collection.mean(), band_viz, ‘S5P CH4’) Map.setCenter(0.0, 0.0, 2) Map
Screenshot by author.
Awesome! This map shows how methane, one of the largest contributors to the greenhouse effect, is distributed across the planet.
Final thoughts
This is a beginner’s guide to help you work with Google Earth Engine data using Python. Geemap is the most complete Python library for visualizing and analyzing this type of data.
If you would like to learn more about this package, please see the resources suggested below:
The code can be found here. I hope this article was helpful. Have a nice day.
Helpful resources:
Eugenia Anello is currently a Research Fellow at the Department of Computer Science, University of Padua, Italy. Her research projects focus on combining continuous learning and anomaly detection.