|
19 | 19 |
|
20 | 20 | import pystac
|
21 | 21 | from pystac.utils import safe_urlparse
|
22 |
| -import pystac.serialization |
| 22 | +from pystac.serialization import ( |
| 23 | + merge_common_properties, |
| 24 | + identify_stac_object_type, |
| 25 | + identify_stac_object, |
| 26 | + migrate_to_latest, |
| 27 | +) |
23 | 28 |
|
24 | 29 | # Use orjson if available
|
25 | 30 | try:
|
@@ -95,12 +100,31 @@ def stac_object_from_dict(
|
95 | 100 | href: Optional[str] = None,
|
96 | 101 | root: Optional["Catalog_Type"] = None,
|
97 | 102 | ) -> "STACObject_Type":
|
98 |
| - result = pystac.serialization.stac_object_from_dict(d, href, root) |
99 |
| - if isinstance(result, pystac.Catalog): |
100 |
| - # Set the stac_io instance for usage by io operations |
101 |
| - # where this catalog is the root. |
| 103 | + if identify_stac_object_type(d) == pystac.STACObjectType.ITEM: |
| 104 | + collection_cache = None |
| 105 | + if root is not None: |
| 106 | + collection_cache = root._resolved_objects.as_collection_cache() |
| 107 | + |
| 108 | + # Merge common properties in case this is an older STAC object. |
| 109 | + merge_common_properties( |
| 110 | + d, json_href=href, collection_cache=collection_cache |
| 111 | + ) |
| 112 | + |
| 113 | + info = identify_stac_object(d) |
| 114 | + d = migrate_to_latest(d, info) |
| 115 | + |
| 116 | + if info.object_type == pystac.STACObjectType.CATALOG: |
| 117 | + result = pystac.Catalog.from_dict(d, href=href, root=root, migrate=False) |
102 | 118 | result._stac_io = self
|
103 |
| - return result |
| 119 | + return result |
| 120 | + |
| 121 | + if info.object_type == pystac.STACObjectType.COLLECTION: |
| 122 | + return pystac.Collection.from_dict(d, href=href, root=root, migrate=False) |
| 123 | + |
| 124 | + if info.object_type == pystac.STACObjectType.ITEM: |
| 125 | + return pystac.Item.from_dict(d, href=href, root=root, migrate=False) |
| 126 | + |
| 127 | + raise ValueError(f"Unknown STAC object type {info.object_type}") |
104 | 128 |
|
105 | 129 | def read_json(
|
106 | 130 | self, source: Union[str, "Link_Type"], *args: Any, **kwargs: Any
|
@@ -302,7 +326,30 @@ def stac_object_from_dict(
|
302 | 326 | root: Optional["Catalog_Type"] = None,
|
303 | 327 | ) -> "STACObject_Type":
|
304 | 328 | STAC_IO.issue_deprecation_warning()
|
305 |
| - return pystac.serialization.stac_object_from_dict(d, href, root) |
| 329 | + if identify_stac_object_type(d) == pystac.STACObjectType.ITEM: |
| 330 | + collection_cache = None |
| 331 | + if root is not None: |
| 332 | + collection_cache = root._resolved_objects.as_collection_cache() |
| 333 | + |
| 334 | + # Merge common properties in case this is an older STAC object. |
| 335 | + merge_common_properties( |
| 336 | + d, json_href=href, collection_cache=collection_cache |
| 337 | + ) |
| 338 | + |
| 339 | + info = identify_stac_object(d) |
| 340 | + |
| 341 | + d = migrate_to_latest(d, info) |
| 342 | + |
| 343 | + if info.object_type == pystac.STACObjectType.CATALOG: |
| 344 | + return pystac.Catalog.from_dict(d, href=href, root=root, migrate=False) |
| 345 | + |
| 346 | + if info.object_type == pystac.STACObjectType.COLLECTION: |
| 347 | + return pystac.Collection.from_dict(d, href=href, root=root, migrate=False) |
| 348 | + |
| 349 | + if info.object_type == pystac.STACObjectType.ITEM: |
| 350 | + return pystac.Item.from_dict(d, href=href, root=root, migrate=False) |
| 351 | + |
| 352 | + raise ValueError(f"Unknown STAC object type {info.object_type}") |
306 | 353 |
|
307 | 354 | # This is set in __init__.py
|
308 | 355 | _STAC_OBJECT_CLASSES = None
|
|
0 commit comments