# Uncomment and run the following line if working out of Google Colab
# !pip install d2spy
# !pip install leafmap
import os
import leafmap
from d2spy.workspace import Workspace
You must connect to your D2S workspace before you can request any data. The Workspace
module's connect
method can be used to login to a D2S instance and connect to your workspace in one go.
Note: This tutorial uses a D2S instance hosted at https://ps2.d2s.org. You will need to have an account and access to data on this instance to use it. Change the URL if you are self-hosting an instance or using an instance hosted elsewhere.
# Connect to D2S workspace
workspace = Workspace.connect("https://ps2.d2s.org", "yourD2Semail@example.com")
An API key will need to be used to view private D2S hosted data products. Data products toggled to public on D2S do not require an API key.
Your API key will be accessible from the workspace api_key
property.
Important
You will not have an active API key by default. You must request one from the D2S profile page. As an example, here is the profile page URL for a local development server: http://localhost:8000/auth/profile
# Check for API key
api_key = workspace.api_key
if not api_key:
print("No API key. Please request one from the D2S profile page and re-run this cell.")
Leafmap uses TiTiler, a dynamic tile server, for streaming map tiles to its interactive map. On this next line, we will set up an environment variable that points to the demo TiTiler service.
os.environ["TITILER_ENDPOINT"] = "https://tt.d2s.org"
Next, we will create a default leafmap Map and provide the URL for our D2S hosted data product.
D2S automatically converts uploaded GeoTIFF data products to the Cloud Optimized GeoTIFF (COG) format. This format is what makes it possible to stream the data product from D2S to TiTiler which in turn serves the tiles rendered on our map.
# Interactive leafmap Map
m = leafmap.Map()
# URL for a D2S hosted GeoTIFF data product
ortho_url = "https://ps2.d2s.org/static/projects/afc5005d-4977-4bdd-a53a-96a3f051d312/flights/32607eae-0cd9-4c06-b4d1-a4837d237ce1/data_products/0e4c3bc2-00da-41b3-bf79-d1d1f83e4194/bb62658b-a250-46e2-8e93-081828880634.tif"
# Add a publicly available data product to the map
m.add_cog_layer(ortho_url, name="Orthomosaic")
# If you want to display a private data product, comment out the previously line and uncomment the below m.add_cog_layer line
# Add a private data product to the map
# m.add_cog_layer(f"{ortho_url}?API_KEY={api_key}", name="DSM", colormap_name="rainbow")
# Display the map
m
Once finished viewing your data, you can revoke your authorization session by logging out.
# Removes access token from future requests
workspace.logout()