How to Add Layers to a Map with Google Earth Engine Python API

jmarbrentano
2 min readMar 12, 2020

--

If you’re trying to get into Google Earth Engine with Python as a newbie, I feel for you! There’s just not that much documentation in Python, and certain objects or methods that make things a snap with the Javascript IDE don’t translate directly to Python. One of those is the map object that has many important methods that allow one to add layers and customize map visualizations.

After unsuccessful attempts to follow along with the example code from the second half of this video* where the plugin foliumgee was used to add layers to a folium map, I spent hours searching for an alternative to foliumgee for displaying a layer on my map. The answer was geehydro!

All I did was install geehydro, and without even calling it by name, I could call .addLayer and other methods on my folium map. See my example below where I plot an NDVI image layer over my basemap.

import geehydro
import folium
# Get a composite of all Sentinal 2 images within a date range that include my point of interest.poi = ee.Geometry.Point([-82.4572, 27.9506])
image = ee.ImageCollection('COPERNICUS/S2').filterBounds(poi).filterDate('2016-10-01', '2016-12-31').min()
Map = folium.Map(location=[27.9506, -82.4572], zoom_start=8)# To see a google satellite view as a basemap
Map.setOptions('HYBRID')
nir = image.select('B8')
red = image.select('B4')
ndvi = nir.subtract(red).divide(nir.add(red)).rename('NDVI Layer')
ndviParams = {'min': -1, 'max': 1, 'palette': ['blue', 'white', 'green']}
Map.addLayer(ndvi, ndviParams, 'NDVI image')
Map.setControlVisibility(layerControl=True, fullscreenControl=True, latLngPopup=True)
Map

*The first half is an amazing demo of a dynamic visualization of an Indian monsoon, bird migration and wind patterns and worth checking out!

--

--