Skip to content

Commit c431e09

Browse files
Support pystac ItemCollection (#64)
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`.
1 parent 5f984b2 commit c431e09

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 0.2.2 (...)
4+
- Support [pystac](https://github.com/stac-utils/pystac) ItemCollections
5+
36
## 0.2.1 (2021-05-07)
47
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.
58

stackstac/stac_types.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ class PystacCatalog:
4545
def get_all_items(self) -> Iterator[PystacItem]:
4646
...
4747

48+
# pystac 1.0
49+
try:
50+
from pystac import ItemCollection as PystacItemCollection
51+
except ImportError:
52+
class PystacItemCollection:
53+
features: List[PystacItem]
4854

4955
try:
5056
from pystac_client import ItemCollection as PystacClientItemCollection
@@ -113,7 +119,7 @@ class ItemDict(TypedDict):
113119

114120
ItemIsh = Union[SatstacItem, PystacItem, ItemDict]
115121
ItemCollectionIsh = Union[
116-
SatstacItemCollection, PystacCatalog, PystacClientItemCollection, ItemSequence
122+
SatstacItemCollection, PystacCatalog, PystacClientItemCollection, PystacItemCollection, ItemSequence
117123
]
118124

119125

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

156-
if isinstance(items, PystacClientItemCollection):
162+
if isinstance(items, (PystacItemCollection, PystacClientItemCollection)):
157163
return [item.to_dict() for item in items.features]
158164

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

0 commit comments

Comments
 (0)