Skip to content

Commit

Permalink
Support pystac ItemCollection (#64)
Browse files Browse the repository at this point in the history
stac-utils/pystac#430 implemented `pystac.ItemCollection`, which is being removed from `pystac-client` in the next release. This PR adds similar handling for `pystac.ItemCollection`.
  • Loading branch information
TomAugspurger authored Jul 7, 2021
1 parent 5f984b2 commit c431e09
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
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}")

0 comments on commit c431e09

Please sign in to comment.