|
8 | 8 | Optional,
|
9 | 9 | )
|
10 | 10 |
|
11 |
| -from pystac import Collection, TemporalExtent |
| 11 | +from pystac import Collection, Extent |
12 | 12 |
|
13 | 13 | from pystac_client._utils import Modifiable, call_modifier
|
14 | 14 | from pystac_client.conformance import ConformanceClasses
|
|
26 | 26 | SortbyLike,
|
27 | 27 | )
|
28 | 28 | from pystac_client.stac_api_io import StacApiIO
|
29 |
| -from pystac_client.warnings import DoesNotConformTo |
| 29 | +from pystac_client.warnings import DoesNotConformTo, PystacClientWarning |
30 | 30 |
|
31 | 31 | if TYPE_CHECKING:
|
32 | 32 | from pystac_client import client as _client
|
@@ -54,26 +54,21 @@ def bboxes_overlap(bbox1: BBox, bbox2: BBox) -> bool:
|
54 | 54 | return xmin1 <= xmax2 and xmin2 <= xmax1 and ymin1 <= ymax2 and ymin2 <= ymax1
|
55 | 55 |
|
56 | 56 |
|
57 |
| -def collection_matches( |
58 |
| - collection_dict: dict[str, Any], |
| 57 | +def _extent_matches( |
| 58 | + extent: Extent, |
59 | 59 | bbox: BBox | None = None,
|
60 | 60 | temporal_interval_str: Datetime | None = None,
|
61 |
| - q: str | None = None, |
62 |
| -) -> bool: |
63 |
| - # check for overlap between provided bbox and the collection's spatial extent |
64 |
| - collection_bboxes = collection_dict["extent"]["spatial"]["bbox"] |
| 61 | +) -> tuple[bool, bool]: |
65 | 62 | bbox_overlaps = not bbox or (
|
66 | 63 | any(
|
67 |
| - bboxes_overlap(bbox, collection_bbox) |
68 |
| - for collection_bbox in collection_bboxes |
| 64 | + bboxes_overlap(bbox, tuple(collection_bbox)) |
| 65 | + for collection_bbox in extent.spatial.bboxes |
69 | 66 | )
|
70 | 67 | )
|
71 | 68 |
|
72 | 69 | # check for overlap between the provided temporal interval and the collection's
|
73 | 70 | # temporal extent
|
74 |
| - collection_temporal_extent = TemporalExtent.from_dict( |
75 |
| - collection_dict["extent"]["temporal"] |
76 |
| - ) |
| 71 | + collection_temporal_extent = extent.temporal |
77 | 72 |
|
78 | 73 | # process the user-provided temporal interval
|
79 | 74 | search_temporal_interval = (
|
@@ -110,6 +105,29 @@ def collection_matches(
|
110 | 105 | for collection_temporal_interval in collection_temporal_extent.intervals
|
111 | 106 | )
|
112 | 107 | )
|
| 108 | + return bbox_overlaps, datetime_overlaps |
| 109 | + |
| 110 | + |
| 111 | +def collection_matches( |
| 112 | + collection_dict: dict[str, Any], |
| 113 | + bbox: BBox | None = None, |
| 114 | + temporal_interval_str: Datetime | None = None, |
| 115 | + q: str | None = None, |
| 116 | +) -> bool: |
| 117 | + # check for overlap between provided bbox and the collection's spatial extent |
| 118 | + try: |
| 119 | + extent = Extent.from_dict(collection_dict.get("extent", {})) |
| 120 | + except Exception: |
| 121 | + warnings.warn( |
| 122 | + f"Unable to parse extent from collection={collection_dict.get('id', None)}", |
| 123 | + PystacClientWarning, |
| 124 | + ) |
| 125 | + bbox_overlaps = True |
| 126 | + datetime_overlaps = True |
| 127 | + else: |
| 128 | + bbox_overlaps, datetime_overlaps = _extent_matches( |
| 129 | + extent, bbox, temporal_interval_str |
| 130 | + ) |
113 | 131 |
|
114 | 132 | # check for overlap between the provided free-text search query (q) and the
|
115 | 133 | # collection's title, description, and keywords
|
|
0 commit comments