My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more
How to map USA states boundaries using Earth Engine Python API and Google Colab

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

Deactivated User's photo
Deactivated User
·May 7, 2021·

1 min read

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.