Skip to content
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

Support pystac.ItemCollection #64

Merged
merged 1 commit into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 0.2.2 (...)
- Support [pystac](https://github.com/stac-utils/pystac) ItemCollections

## 0.2.1 (2021-05-07)
Support [xarray 0.18](http://xarray.pydata.org/en/stable/whats-new.html#v0-18-0-6-may-2021) and beyond, as well as looser version requirements for some other dependencies.

Expand Down
10 changes: 8 additions & 2 deletions stackstac/stac_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class PystacCatalog:
def get_all_items(self) -> Iterator[PystacItem]:
...

# pystac 1.0
try:
from pystac import ItemCollection as PystacItemCollection
except ImportError:
class PystacItemCollection:
features: List[PystacItem]

try:
from pystac_client import ItemCollection as PystacClientItemCollection
Expand Down Expand Up @@ -113,7 +119,7 @@ class ItemDict(TypedDict):

ItemIsh = Union[SatstacItem, PystacItem, ItemDict]
ItemCollectionIsh = Union[
SatstacItemCollection, PystacCatalog, PystacClientItemCollection, ItemSequence
SatstacItemCollection, PystacCatalog, PystacClientItemCollection, PystacItemCollection, ItemSequence
]


Expand Down Expand Up @@ -153,7 +159,7 @@ def items_to_plain(items: Union[ItemCollectionIsh, ItemIsh]) -> ItemSequence:
if isinstance(items, PystacCatalog):
return [item.to_dict() for item in items.get_all_items()]

if isinstance(items, PystacClientItemCollection):
if isinstance(items, (PystacItemCollection, PystacClientItemCollection)):
return [item.to_dict() for item in items.features]

raise TypeError(f"Unrecognized STAC collection type {type(items)}: {items!r}")