Skip to content

Add role, media_type filtering arguments to Item.get_assets #873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TomAugspurger opened this issue Aug 15, 2022 · 0 comments · Fixed by #936
Closed

Add role, media_type filtering arguments to Item.get_assets #873

TomAugspurger opened this issue Aug 15, 2022 · 0 comments · Fixed by #936
Assignees
Milestone

Comments

@TomAugspurger
Copy link
Collaborator

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

Args:
rel : If set, filter links such that only those
matching this relationship are returned.
media_type: If set, filter the links such that only
those matching media_type are returned

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.

@gadomski gadomski added this to the 1.7 milestone Dec 30, 2022
@gadomski gadomski linked a pull request Jan 5, 2023 that will close this issue
5 tasks
@pjhartzell pjhartzell self-assigned this Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants