Skip to content

Commit b94896b

Browse files
committed
Add Catalog.get_collections method
1 parent ec67d34 commit b94896b

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

pystac/catalog.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,14 @@ def get_children(self) -> Iterable[Union["Catalog", "Collection_Type"]]:
320320
self.get_stac_objects(pystac.RelType.CHILD),
321321
)
322322

323+
def get_collections(self) -> Iterable["Collection_Type"]:
324+
"""Return all children of this catalog that are :class:`~pystac.Collection`
325+
instances."""
326+
return map(
327+
lambda x: cast(pystac.Collection, x),
328+
self.get_stac_objects(pystac.RelType.CHILD, pystac.Collection),
329+
)
330+
323331
def get_child_links(self) -> List[Link]:
324332
"""Return all child links of this catalog.
325333

tests/test_catalog.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,13 @@ def testfrom_invalid_dict_raises_exception(self) -> None:
996996
with self.assertRaises(pystac.STACTypeError):
997997
_ = pystac.Catalog.from_dict(collection_dict)
998998

999+
def test_get_collections(self) -> None:
1000+
catalog = TestCases.test_case_2()
1001+
collections = list(catalog.get_collections())
1002+
1003+
self.assertGreater(len(collections), 0)
1004+
self.assertTrue(all(isinstance(c, pystac.Collection) for c in collections))
1005+
9991006

10001007
class FullCopyTest(unittest.TestCase):
10011008
def check_link(self, link: pystac.Link, tag: str) -> None:

0 commit comments

Comments
 (0)