If you want to create or develop any geological-based project/app or if you want to include data mapping capabilities in your project then one possible solution is to use Google Earth Engine, which is a powerful and flexible cloud-based API that lets you process massive amounts of satellite images from the comfort of the Google Cloud. And in this blog post, we will use “geemap” which is one of the best and newest libraries for Python to interact with the Google Earth Engine features in Python.

What is geemap?

geemap is a Python package that allows you to use Google Earth Engine (GEE) interactively. With GEE one can access satellite imagery, terrain, and geospatial datasets, for example, the mass of trees for different areas in the world, or how vegetation changes over some time. geemap is based on Python and hence it may be used with other libraries and tutorials that are available through this wonderful language.

Prerequisites:

Miniconda: We will be using miniconda in this tutorial it is a free minimal installer for conda. It is a small, bootstrap version of Anaconda that includes only conda, Python, and some other small number of useful packages. If you want to follow along, go to the given link then download and install miniconda, after that you should have a conda terminal open.

https://docs.conda.io/en/latest/miniconda.html

Geemap installation: Go through the following steps to install geemap

First, let’s create a conda environment and active it 

conda create -n gee python
conda activate gee

Now let’s install a geemap

conda install mamba -c conda-forge
mamba install geemap -c conda-forge

That’s it geemap is installed

Jupyter notebook: we also need a jupyter notebook that can improve your productivity in the notebook environment. To install the Jupiter notebook use the following command 

mamba install jupyter_contrib_nbextensions -c conda-forge

And to run jupyter notebook run the following command

jupyter notebook
Or
python -m notebook

Code

Simple example:

Firstly, start your Jupyter notebook and create a new Python file. Then, let us begin our interaction with the Google Earth Engine.

# importing the geemap library
import ee
import geemap

# creating an interactive map (you can change the value to specify where should map start and how zoomed in the map will be)
Map = geemap.Map(center=(20, 80), zoom=4)
Map

Note: when you use geemap first time it will ask you to log into your google account to access the google earth engine API. You just have to log in and then an API key will appear on the next screen – paste that API key into the box and you’re good to go.

Output:

As you can see in the output we have a fully interactive map on the left side of the map you can see lots of tools like zoom in, zoom out, draw shapes, draw a marker, and so on. You can try yourself to see what all the tools do 

Changing the map type

There are many aspects of a map that we have to keep track of like the type of map we’re viewing is especially important. We can easily change the current map type by using the following command

Map.add_basemap('SATELLITE')

Output:

You can see in the output that the map type is now satellite view. You can also choose from a variety of map types – try out the other ones and see what happens!

Map.add_basemap('SATELLITE')
Map.add_basemap('ROADMAP')
Map.add_basemap('HYBRID')
Map.add_basemap('TERRAIN')
Map.add_basemap('OpenStreetMap')

If you want more types of base maps use the following command

m = geemap.Map()
m.basemap_demo()
m

Output

You can choose in the dropdown menu of the base map

To get all the base maps in your terminal use the following command

basemaps = geemap.basemaps.keys()
       for basemap in basemaps:
       print(basemap)

Inspector tool for Earth Engine

import geemap# adding google earth engine data layer

# here we are adding google Earth Engine dataset
dem = ee.Image('USGS/SRTMGL1_003')
landcover = ee.Image("ESA/GLOBCOVER_L4_200901_200912_V2_3").select('landcover')
landsat7 = ee.Image('LE7_TOA_5YEAR/1999_2003').select(['B1', 'B2', 'B3', 'B4', 'B5', 'B7'])
states = ee.FeatureCollection("TIGER/2018/States")

# Set visualization parameters.
vis_params = {
  'min': 0,
  'max': 4000,
  'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']}

# Add Earth Engine layers to Map
Map.addLayer(dem, vis_params, 'SRTM DEM', True, 0.5)
Map.addLayer(landcover, {}, 'Land cover')
Map.addLayer(landsat7, {'bands': ['B4', 'B3', 'B2'], 'min': 20, 'max': 200, 'gamma': 2.0}, 'Landsat 7')
Map.addLayer(states, {}, "US States")

Map

Output

In the output, you can also hide specific layers. Just go to the top right corner and uncheck the layers you do not need for!

Now we can use the inspector tool to get the values of each layer. First, go to settings and press on the “Inspector Tool” icon. Then, click on any location on the map that you want to get the values for and it will pull up basic information about it such as its elevation and land cover. This tool is great for getting quick access to information without having to write any lines of code!

Creating a split-panel map:

The split-panel feature is very useful in this way you can visualize side by side the difference between two maps.

import geemap#creating an interactive map
Map = geemap.Map()

# here creating a slit map using split_map method
# change the map type in the left_layer and right_layer to change the map type showing in both sides
Map.split_map(left_layer='NLCD 2019 CONUS Land Cover', right_layer='SATELLITE')
Map

Output

Using inbuilt search tools to get different data

The interactive map already has an inbuilt search tool with the use of that you can search available data and add them as a layer to use this feature follow the below steps

  1. Press on the top left-corner icon 
  2. Go to the Data tab
  3. Search the data (If you want to see all the datasets go to the following link https://developers.google.com/earth-engine/datasets/catalog)
  4. Select the data that you want to show on the map
  5. Press on import it will automatically write the code in the below section 
  6. Run the code and that’s it.
# creating a simple interactive map
import geemap
import os
Map = geemap.Map(toolbar_ctrl=True, layer_ctrl=True)
Map

# this is the auto generated code when we imported the data
dataset_hlh = ee.ImageCollection('JRC/GHSL/P2016/POP_GPW_GLOBE_V1')
Map.addLayer(dataset_hlh, {}, "JRC/GHSL/P2016/POP_GPW_GLOBE_V1")

Output

Export map as an HTML file

It is very useful to share this type of interactive map with other people or show it on your project or website and we do that by exporting the map as an HTML file. Let’s see how it’s done.

  1. Go to the settings icon present in the top right corner.
  2. Press on the camera icon 
  3. Here you will see three tabs HTML, PNG, and jpg press on the HTML.
  4. Then select the location and add the name of the HTML file and press ok. 
  5. It’s done!

Final Words

In this blog post, we introduced geemap, a Python package that allows you to use Google Earth Engine (GEE) interactively. We also provided a basic example of how to use a geemap. We hope you enjoyed this blog post! If you have any questions or comments, please let us know!