#!/usr/bin/env python # coding: utf-8 # # Pydeck + Earth Engine: Polygon FeatureCollection # # This is an example of using [pydeck](https://pydeck.gl) to visualize a Google Earth Engine `FeatureCollection` of polygons. # To install and run this notebook locally, refer to the [Pydeck Earth Engine documentation](https://earthengine-layers.com/docs/developer-guide/pydeck-integration). # # To see this example online, view the [JavaScript version][js-example]. # # [js-example]: https://earthengine-layers.com/examples/intl-boundary # Import required packages: # In[ ]: from pydeck_earthengine_layers import EarthEngineLayer import pydeck as pdk import ee # ### Authenticate with Earth Engine # # Using Earth Engine requires authentication. If you don't have a Google account approved for use with Earth Engine, you'll need to request access. For more information and to sign up, go to https://signup.earthengine.google.com/. # In[ ]: try: ee.Initialize() except Exception as e: ee.Authenticate() ee.Initialize() # ### International Boundaries dataset # # This example uses the [Large Scale International Boundary Polygons][lsib] dataset, which contains simplified boundaries of countries. # # [lsib]: https://developers.google.com/earth-engine/datasets/catalog/USDOS_LSIB_SIMPLE_2017 # Import the dataset by creating an Earth Engine object that references it. # In[ ]: dataset = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017') # Apply Earth Engine styling on this dataset. Here we render the fill of the polygon with a shade of green, and the border color with a shade of blue. # In[ ]: countries = dataset.style( fillColor='b5ffb4', color='00909F', width=3 ) # Create a new `EarthEngineLayer` with this dataset that can then be passed to Pydeck. # In[ ]: layer = EarthEngineLayer(countries, id="international_boundaries") # Then just pass this layer to a `pydeck.Deck` instance, and call `.show()` to create a map: # In[ ]: view_state = pdk.ViewState(latitude=36, longitude=10, zoom=3) r = pdk.Deck( layers=[layer], initial_view_state=view_state ) r.show() # In[ ]: