Get Items from static Collection
clausmichele opened this issue · comments
Dear all,
I am trying to get all the items from a static STAC Collection
https://github.com/openEOPlatform/architecture-docs/issues/327#issuecomment-1663961413
It doesn't seem to work, does it require the /items
endpoint? Would it make sense trying to add this functionality?
Code to reproduce the issue:
import pystac_client
import json
url = "https://gist.githubusercontent.com/clausmichele/cfbb823aeac0f39036b7627c1b6c7eee/raw/d1361cadf7257871436b67c73f491c4a79650cf0/vito_STAC_1_1.json"
stac_api = pystac_client.stac_api_io.StacApiIO()
stac_dict = json.loads(stac_api.read_text(url))
collection = stac_api.stac_object_from_dict(stac_dict)
items = collection.get_items()
def get_ten_items(items):
for i, item in enumerate(items):
print(f"{i}: {item}", flush=True)
if i == 9:
return
get_ten_items(items)
File ~\Miniconda3\envs\stacenv\lib\site-packages\pystac_client\collection_client.py:127, in CollectionClient.get_items(self)
117 def get_items(self) -> Iterator["Item_Type"]:
118 """Return all items in this Collection.
119
120 If the Collection contains a link of with a `rel` value of `items`,
(...)
125 Iterator[Item]: Iterator of items whose parent is this catalog.
126 """
--> 127 root = self.get_root()
128 if root.conforms_to(ConformanceClasses.ITEM_SEARCH):
129 search = ItemSearch(
130 url=self._items_href(),
131 method="GET",
(...)
134 modifier=self.modifier,
135 )
File ~\Miniconda3\envs\stacenv\lib\site-packages\pystac_client\collection_client.py:108, in CollectionClient.get_root(self)
106 root = super().get_root()
107 if root is None or not isinstance(root, Client):
--> 108 raise ValueError(
109 "`CollectionClient.root` is not have a valid `Client` object."
110 )
111 return root
ValueError: `CollectionClient.root` is not have a valid `Client` object.
Hi! Yeah we can probably expand that error message, but my understanding is that for a static catalog you can just use pystac directly. So you would do:
import pystac
url = "https://gist.githubusercontent.com/clausmichele/cfbb823aeac0f39036b7627c1b6c7eee/raw/d1361cadf7257871436b67c73f491c4a79650cf0/vito_STAC_1_1.json"
collection = pystac.read_file(url)
items = collection.get_items()
Thanks @jsignell, that works fine!