Author's illustration
Geospatial data analysis is a field aimed at treating, visualizing and analyzing a special type of data, called geospatial data. Compared to normal data, we have tabular data with an extra column, the location information, such as latitude and longitude.
There are two main types of data: vector data and raster data. When it comes to vector data, you still have a tabular data set, while raster data is more similar to images, such as satellite images and aerial photographs.
In this article, I will focus on the raster data provided by Google Earth Engine, a cloud computing platform that provides a huge catalog of satellite image data. This type of data can be easily mastered from your Jupyter Notebook using a life-saving Python package called Geemap. Let us begin!
What is the Google Earth engine?
Author's screenshot. Google Earth Engine home page.
Before starting with the Python library, we must understand the potential of Google Earth Engine. This cloud-based platform, powered by the Google Cloud platform, hosts free, public geospatial datasets for academic, nonprofit, and commercial purposes.
Author's screenshot. Earth Engine Data Catalog Overview.
The great thing about this platform is that it provides a catalog of several petabytes of raster and vector data, stored on Earth Engine's servers. You can get a quick overview from this link. Additionally, it provides APIs to facilitate the analysis of raster data sets.
What is Geemap?
Author's illustration. Geemap Library.
Geemap is a Python library that allows you to analyze and visualize large amounts of geospatial data from Google Earth Engine.
Prior to this package, it was already possible to make computational requests through the JavaScript and Python APIs, but the Python APIs had limited functionality and lacked documentation.
To fill this gap, Geemap was created to allow users to access Google Earth Engine resources with a few lines of code. Geemap is based on EarthEngine API, ipybrochure and sheet.
To install the library, you only need the following command:
I recommend you experiment with this amazing package in Google Colab to understand its full potential. Take a look at this book free written by Professor Dr. Qiusheng Wu to get started with Geemap and Google Earth Engine.
How to access Earth Engine?
First, we need to import two Python libraries, which will be used in the tutorial:
In addition to geemap, we have imported the Earth Engine Python client library, called ee.
This Python library can be used for authentication in Earth Engine, but can be faster by using the Geemap library directly:
You need to click on the URL returned by this line of code, which will generate the authorization code. First, select the cloud project and then click on the “GENERAT TOKEN” button.
Author's screenshot. Laptop authenticator.
Afterwards, it will ask you to choose the account. I recommend having the same Google Colab account if you are using it.
Author's screenshot. Choose an account.
Then, click the checkbox next to Select All and press the “Continue” button. In a nutshell, this step allows the Notebook Client to access the Earth Engine account.
Author's screenshot. Allow Notebook Client to access your Earth Engine account.
After this action, the authentication code is generated and you can paste it into the notebook cell.
Author's screenshot. Copy the authentication code.
Once the verification code has been entered, you will finally be able to create and view this interactive map:
For now, you're just looking at the basemap on top of ipyleaflet, a Python package that enables display of interactive maps within Jupyter Notebook.
Create interactive maps
Previously, we have seen how to authenticate and display an interactive map using a single line of code. We can now customize the default map by specifying the centroid's latitude and longitude, zoom level, and height. I have chosen the coordinates of Rome so that the center is centered on the map of Europe.
m = geemap.Map(center=(41, 12), zoom=6, height=600)
m
If we want to change the basemap, there are two possible ways. The first way is to write and execute the following line of code:
m.add_basemap("ROADMAP")
m
Alternatively, you can manually change the basemap by clicking the wrench icon on the right.
Additionally, we see the list of basemaps provided by Geemap:
basemaps = geemap.basemaps.keys()
for bm in basemaps:
print(bm)
This is the output:
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 them available thanks to OpenStreetMap, ESRI and USGS.
Land Engine Data Types
Before showing the full potential of Geemap, it is important to know two main data types in Earth Engine. Take a look at the Google Earth Engine Documentation for more details.
Author's illustration. Example of vector data types: Geometry, Feature and FeatureCollection.
When we handle vector data, we mainly use three types of data:
- Geometry stores the coordinates necessary to draw the vector data on a map. Earth Engine supports three main types of geometries: point, line string, and polygon.
- Characteristic It is essentially a row that combines geometry and non-geographic attributes. It is very similar to GeoPandas' GeoSeries class.
- Feature Collection It is a tabular data structure that contains a set of characteristics. FeatureCollection and GeoDataFrame are almost conceptually identical.
Author's screenshot. Example of image data type. Displays the smoothed Australian digital elevation model (DEM-S)
In the world of raster data, we focus on Image objects. Google Earth Engine Images are made up of one or more brands, where each band has a specific name, estimated minimum and maximum, and description.
If we have a collection or time series of images, Image Collection is more appropriate as a data type.
Author's screenshot. Copernicus CORINE Land Cover.
We view satellite images showing the land cover map of Europe. This data set provides the changes between 1986 and 2018.
We first load the image using ee.Image and then select the “landcover” band. Finally, let's visualize the image by adding the loaded dataset to the map as a layer using Map.addLayer.
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
Author's screenshot.
Similarly, we can do the same to upload and view the satellite images showing the land cover map of Europe. This data set provides the changes between 1986 and 2018.
Author's screenshot. Offline high-resolution images of methane concentrations.
To display an Earth Engine ImageCollection, the lines of code are similar, except 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
Author's screenshot.
Brilliant! In this map, we see how methane, one of the most important contributors to the greenhouse effect, is distributed around the world.
Final thoughts
This was an introductory guide that can 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 want to go deeper into this package, you can check out the resources I suggested below.
The code can be found. here. I hope you found the article useful. Have a nice day!
Useful resources:
Eugenia Anello He is currently a researcher at the Department of Information Engineering at the University of Padova, Italy. His research project focuses on Continuous Learning combined with Anomaly Detection.