10
10
11
11
def filter_stac_catalog (catalog : Catalog ,
12
12
bbox : Optional [tuple [float , float , float , float ]] = None ,
13
+ collection_ids : Optional [list [str ]] = None ,
13
14
time_range : Optional [tuple [str , str ]] = None ,
14
15
time_pattern : Optional [str ] = None
15
16
) -> tuple [list [Collection ], Iterable [Item ]]:
@@ -24,6 +25,9 @@ def filter_stac_catalog(catalog: Catalog,
24
25
The STAC Catalog to filter.
25
26
bbox : tuple of float, optional
26
27
The bounding box of the area of interest in the format (minx, miny, maxx, maxy).
28
+ collection_ids : list of str, optional
29
+ A list of collection IDs to filter. If not None, this will override the `bbox`
30
+ option.
27
31
time_range : tuple of str, optional
28
32
Time range to load as a tuple of (start_time, stop_time), where start_time and
29
33
stop_time are strings in the format specified by `time_pattern`. Default is
@@ -39,13 +43,14 @@ def filter_stac_catalog(catalog: Catalog,
39
43
filtered_items : list of Item
40
44
A list of filtered items.
41
45
"""
42
- filtered_collections = filter_collections (catalog , bbox )
46
+ filtered_collections = filter_collections (catalog , bbox , collection_ids )
43
47
filtered_items = filter_items (filtered_collections , time_range , time_pattern )
44
48
return filtered_collections , filtered_items
45
49
46
50
47
51
def filter_collections (catalog : Catalog ,
48
- bbox : Optional [tuple [float , float , float , float ]] = None
52
+ bbox : Optional [tuple [float , float , float , float ]] = None ,
53
+ collection_ids : Optional [list [str ]] = None
49
54
) -> list [Collection ]:
50
55
"""
51
56
Filters the collections in a STAC Catalog based on a bounding box.
@@ -56,21 +61,28 @@ def filter_collections(catalog: Catalog,
56
61
The STAC Catalog to filter.
57
62
bbox : tuple of float, optional
58
63
The bounding box of the area of interest in the format (minx, miny, maxx, maxy).
64
+ collection_ids : list of str, optional
65
+ A list of collection IDs to filter. If not None, this will override the `bbox`
66
+ option.
59
67
60
68
Returns
61
69
-------
62
70
list of Collection
63
71
A list of filtered collections.
64
72
"""
65
- if bbox is None :
73
+ if collection_ids is not None :
66
74
return [collection for collection in catalog .get_children ()
67
- if isinstance (collection , Collection )]
68
- else :
75
+ if isinstance (collection , Collection ) and
76
+ collection .id in collection_ids ]
77
+ elif bbox is not None :
69
78
return [collection for collection in catalog .get_children () if
70
79
isinstance (collection , Collection ) and
71
80
collection .extent .spatial .bboxes is not None and
72
81
any (_bbox_intersection (list (bbox ), b ) is not None
73
82
for b in collection .extent .spatial .bboxes )]
83
+ else :
84
+ return [collection for collection in catalog .get_children ()
85
+ if isinstance (collection , Collection )]
74
86
75
87
76
88
def _bbox_intersection (bbox1 : list [float , float , float , float ],
0 commit comments