Start a personal dev blog on your domain for free with Hashnode and grow your readership.
Get Started

How to map USA states boundaries using Earth Engine Python API and Google Colab

In this tutorial, we will discuss on how to map USA state boundaries using the Earth Engine Python API and Google Colab. Earth Engine is by default integrated with Google Colab so you do not need to manually install it. Rather you need to import, authenticate and initialize to start the Python API.

#Import earth engine
import ee

# Trigger the authentication flow.
ee.Authenticate()

# Initialize the library.
ee.Initialize()

Next, lets import the USA states boundaries data from the Earth Engine data library.

# Import the Folium library.
import folium

# Define a method for displaying Earth Engine image tiles to folium map.
def add_ee_layer(self, ee_image_object, vis_params, name):
  map_id_dict = ee.Image(ee_image_object).getMapId(vis_params)
  folium.raster_layers.TileLayer(
    tiles = map_id_dict['tile_fetcher'].url_format,
    attr = 'Map Data &copy; <a href="https://earthengine.google.com/">Google Earth Engine</a>',
    name = name,
    overlay = True,
    control = True
  ).add_to(self)

# Add EE drawing method to folium.
folium.Map.add_ee_layer = add_ee_layer

# Create a folium map object.
my_map = folium.Map(location=[37.649, -99.844], zoom_start = 4)

# Add the layer to the map object.
my_map.add_ee_layer(image, {'palette': '00FFFF'}, 'TIGER/2018/States')

# Add a layer control panel to the map.
my_map.add_child(folium.LayerControl())

# Display the map.
display(my_map)

Check out the video tutorial below.

Start a personal dev blog on your domain for free and grow your readership.

3.4K+ developers have started their personal blogs on Hashnode in the last one month.

Write in Markdown · Publish articles on custom domain · Gain readership on day zero · Automatic GitHub backup and more

Comments (1)

Afework Mekeberiaw Worku's photo

Very helpful , thank you for making me familar to undesrtand the colab platform and python language easily.