|
20 | 20 | from pystac.asset import Asset, Assets |
21 | 21 | from pystac.catalog import Catalog |
22 | 22 | from pystac.errors import DeprecatedWarning, ExtensionNotImplemented, STACTypeError |
| 23 | +from pystac.item_assets import ItemAssetDefinition, _ItemAssets |
23 | 24 | from pystac.layout import HrefLayoutStrategy |
24 | 25 | from pystac.link import Link |
25 | 26 | from pystac.provider import Provider |
@@ -553,6 +554,7 @@ def __init__( |
553 | 554 | self.keywords = keywords |
554 | 555 | self.providers = providers |
555 | 556 | self.summaries = summaries or Summaries.empty() |
| 557 | + self._item_assets: _ItemAssets | None = None |
556 | 558 |
|
557 | 559 | self.assets = {} |
558 | 560 | if assets is not None: |
@@ -731,6 +733,62 @@ def get_item(self, id: str, recursive: bool = False) -> Item | None: |
731 | 733 | return super().get_item(id, recursive=recursive) |
732 | 734 | raise e |
733 | 735 |
|
| 736 | + @property |
| 737 | + def item_assets(self) -> dict[str, ItemAssetDefinition]: |
| 738 | + """Accessor for `item_assets |
| 739 | + <https://github.com/radiantearth/stac-spec/blob/v1.1.0/collection-spec/collection-spec.md#item_assets>`__ |
| 740 | + on this collection. |
| 741 | +
|
| 742 | + Example:: |
| 743 | +
|
| 744 | + .. code-block:: python |
| 745 | +
|
| 746 | + >>> print(collection.item_assets) |
| 747 | + {'thumbnail': <pystac.item_assets.ItemAssetDefinition at 0x72aea0420750>, |
| 748 | + 'metadata': <pystac.item_assets.ItemAssetDefinition at 0x72aea017dc90>, |
| 749 | + 'B5': <pystac.item_assets.ItemAssetDefinition at 0x72aea017efd0>, |
| 750 | + 'B6': <pystac.item_assets.ItemAssetDefinition at 0x72aea016d5d0>, |
| 751 | + 'B7': <pystac.item_assets.ItemAssetDefinition at 0x72aea016e050>, |
| 752 | + 'B8': <pystac.item_assets.ItemAssetDefinition at 0x72aea016da90>} |
| 753 | + >>> collection.item_assets["thumbnail"].title |
| 754 | + 'Thumbnail' |
| 755 | +
|
| 756 | + Set attributes on :class:`~pystac.ItemAssetDefinition` objects |
| 757 | +
|
| 758 | + .. code-block:: python |
| 759 | +
|
| 760 | + >>> collection.item_assets["thumbnail"].title = "New Title" |
| 761 | +
|
| 762 | + Add to the ``item_assets`` dict: |
| 763 | +
|
| 764 | + .. code-block:: python |
| 765 | +
|
| 766 | + >>> collection.item_assets["B4"] = { |
| 767 | + 'type': 'image/tiff; application=geotiff; profile=cloud-optimized', |
| 768 | + 'eo:bands': [{'name': 'B4', 'common_name': 'red'}] |
| 769 | + } |
| 770 | + >>> collection.item_assets["B4"].owner == collection |
| 771 | + True |
| 772 | + """ |
| 773 | + if self._item_assets is None: |
| 774 | + self._item_assets = _ItemAssets(self) |
| 775 | + return self._item_assets |
| 776 | + |
| 777 | + @item_assets.setter |
| 778 | + def item_assets( |
| 779 | + self, item_assets: dict[str, ItemAssetDefinition | dict[str, Any]] | None |
| 780 | + ) -> None: |
| 781 | + # clear out the cached value |
| 782 | + self._item_assets = None |
| 783 | + |
| 784 | + if item_assets is None: |
| 785 | + self.extra_fields.pop("item_assets") |
| 786 | + else: |
| 787 | + self.extra_fields["item_assets"] = { |
| 788 | + k: v if isinstance(v, dict) else v.to_dict() |
| 789 | + for k, v in item_assets.items() |
| 790 | + } |
| 791 | + |
734 | 792 | def update_extent_from_items(self) -> None: |
735 | 793 | """ |
736 | 794 | Update datetime and bbox based on all items to a single bbox and time window. |
|
0 commit comments