Skip to content

37 planetary computer

image image image

Uncomment the following line to install leafmap if needed.

1
# !pip install leafmap
1
import leafmap

Add a STAC item via an HTTP URL

1
url = "https://canada-spot-ortho.s3.amazonaws.com/canada_spot_orthoimages/canada_spot5_orthoimages/S5_2007/S5_11055_6057_20070622/S5_11055_6057_20070622.json"
1
leafmap.stac_assets(url)
1
leafmap.stac_bounds(url)
1
leafmap.stac_center(url)
1
# leafmap.stac_info(url)
1
# leafmap.stac_stats(url)
1
2
3
m = leafmap.Map()
m.add_stac_layer(url, bands=["B3", "B2", "B1"])
m

Add a Microsoft Planetry Computer STAC item. The titiler endpoint can set in one of the ways below:

1
2
3
os.environ["TITILER_ENDPOINT"] = "planetary-computer"
titiler_endpoint="pc"
titiler_endpoint="planetary-computer"
1
2
# import os
# os.environ["TITILER_ENDPOINT"] = "planetary-computer"
1
collection = "landsat-8-c2-l2"
1
item = "LC08_L2SP_047027_20201204_02_T1"
1
leafmap.stac_assets(collection=collection, item=item, titiler_endpoint="pc")
1
leafmap.stac_bounds(collection=collection, item=item)
1
leafmap.stac_info(collection=collection, item=item, assets="SR_B7")
1
leafmap.stac_stats(collection=collection, item=item, assets="SR_B7")

Color infrared composite.

1
2
3
4
5
6
7
8
m = leafmap.Map()
m.add_stac_layer(
    collection=collection,
    item=item,
    assets=["SR_B5", "SR_B4", "SR_B3"],
    name="Color infrared",
)
m

False color composite.

1
2
3
4
5
m = leafmap.Map()
m.add_stac_layer(
    collection=collection, item=item, assets="SR_B7,SR_B5,SR_B4", name="False color"
)
m

Calculate NDVI.

1
2
3
4
5
6
7
8
9
m = leafmap.Map()
m.add_stac_layer(
    collection=collection,
    item=item,
    expression="(SR_B5-SR_B4)/(SR_B5+SR_B4)",
    rescale="-1,1",
    name="NDVI",
)
m

Calculate NDVI and add a colormap. See available colormaps at https://planetarycomputer.microsoft.com/docs/reference/data/

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
m = leafmap.Map()
m.add_stac_layer(
    collection=collection, item=item, assets="SR_B5,SR_B4,SR_B3", name="Color infrared"
)
m.add_stac_layer(
    collection=collection,
    item=item,
    expression="(SR_B5-SR_B4)/(SR_B5+SR_B4)",
    rescale="-1,1",
    colormap_name="greens",
    name="NDVI Green",
)
m