{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Pydeck + Earth Engine: Polygon FeatureCollection\n", "\n", "This is an example of using [pydeck](https://pydeck.gl) to visualize a Google Earth Engine `FeatureCollection` of polygons.\n", "To install and run this notebook locally, refer to the [Pydeck Earth Engine documentation](https://earthengine-layers.com/docs/developer-guide/pydeck-integration).\n", "\n", "To see this example online, view the [JavaScript version][js-example].\n", "\n", "[js-example]: https://earthengine-layers.com/examples/intl-boundary" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Import required packages:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pydeck_earthengine_layers import EarthEngineLayer\n", "import pydeck as pdk\n", "import ee" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Authenticate with Earth Engine\n", "\n", "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/." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "try:\n", " ee.Initialize()\n", "except Exception as e:\n", " ee.Authenticate()\n", " ee.Initialize()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### International Boundaries dataset\n", "\n", "This example uses the [Large Scale International Boundary Polygons][lsib] dataset, which contains simplified boundaries of countries.\n", "\n", "[lsib]: https://developers.google.com/earth-engine/datasets/catalog/USDOS_LSIB_SIMPLE_2017" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Import the dataset by creating an Earth Engine object that references it." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dataset = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "countries = dataset.style(\n", " fillColor='b5ffb4',\n", " color='00909F',\n", " width=3\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a new `EarthEngineLayer` with this dataset that can then be passed to Pydeck." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "layer = EarthEngineLayer(countries, id=\"international_boundaries\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Then just pass this layer to a `pydeck.Deck` instance, and call `.show()` to create a map:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "view_state = pdk.ViewState(latitude=36, longitude=10, zoom=3)\n", "r = pdk.Deck(\n", " layers=[layer], \n", " initial_view_state=view_state\n", ")\n", "r.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.7" } }, "nbformat": 4, "nbformat_minor": 4 }