pystac icon indicating copy to clipboard operation
pystac copied to clipboard

Add `role`, `media_type` filtering arguments to `Item.get_assets`

Open TomAugspurger opened this issue 3 years ago • 0 comments

Item.get_links includes some arguments to filter which links are returned by rel and media_type:

https://github.com/stac-utils/pystac/blob/876b60a8547d9307b564cfb372c1237b324c555b/pystac/stac_object.py#L115-L119

Item.get_assets would be more useful if it could filter on roles and media_type. We could replace

import pystac

item = pystac.read_file("https://planetarycomputer.microsoft.com/api/stac/v1/collections/jrc-gsw/items/90E_30Nv1_3_2020")

cog_assets = {
    asset_key: asset
    for asset_key, asset in item.assets.items()
    if asset.media_type == pystac.MediaType.COG
}

with cog_assets = item.get_assets(media_type=pystac.MediaType.COG)

Since roles is a list, we might need a flag to control whether you need any / all of the roles specified to be returned. But as a start, I think allowing a single role and returning any assets with that would be best.

TomAugspurger avatar Aug 15 '22 16:08 TomAugspurger