Skip to content

Commit 3dff1b6

Browse files
author
Jon Duckworth
authored
Merge pull request #564 from duckontheweb/update/item-assets-extension
Update Item Assets Extension
2 parents e45af8e + bb5042c commit 3dff1b6

File tree

5 files changed

+454
-0
lines changed

5 files changed

+454
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
valid values of `type` in [Point Cloud Schema
1818
Objects](https://github.com/stac-extensions/pointcloud#schema-object)
1919
([#548](https://github.com/stac-utils/pystac/pull/548))
20+
- `to_dict` and equality definition for `extensions.item_asset.AssetDefinition` ([#564](https://github.com/stac-utils/pystac/pull/564))
2021

2122
### Removed
2223

docs/api.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,27 @@ FileExtension
365365
:show-inheritance:
366366
:undoc-members:
367367

368+
Item Assets Extension
369+
---------------------
370+
371+
These classes are representations of the :stac-ext:`Item Assets Extension Spec
372+
<item-assets>`.
373+
374+
AssetDefinition
375+
~~~~~~~~~~~~~~~
376+
377+
.. autoclass:: pystac.extensions.item_assets.AssetDefinition
378+
:members:
379+
:undoc-members:
380+
:show-inheritance:
381+
382+
ItemAssetsExtension
383+
~~~~~~~~~~~~~~~~~~~
384+
385+
.. autoclass:: pystac.extensions.item_assets.ItemAssetsExtension
386+
:members:
387+
:show-inheritance:
388+
368389
Label Extension
369390
---------------
370391

pystac/extensions/item_assets.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
https://github.com/stac-extensions/item-assets
44
"""
55

6+
from copy import deepcopy
67
from typing import Any, Dict, List, Optional
78

89
import pystac
@@ -22,11 +23,23 @@
2223

2324

2425
class AssetDefinition:
26+
"""Object that contains details about the datafiles that will be included in member
27+
Items for this Collection.
28+
29+
See the :stac-ext:`Asset Object <item-assets#asset-object>` for details.
30+
"""
31+
2532
def __init__(self, properties: Dict[str, Any]) -> None:
2633
self.properties = properties
2734

35+
def __eq__(self, o: object) -> bool:
36+
if not isinstance(o, AssetDefinition):
37+
return NotImplemented
38+
return self.to_dict() == o.to_dict()
39+
2840
@property
2941
def title(self) -> Optional[str]:
42+
"""Gets or sets the displayed title for clients and users."""
3043
return self.properties.get(ASSET_TITLE_PROP)
3144

3245
@title.setter
@@ -38,6 +51,9 @@ def title(self, v: Optional[str]) -> None:
3851

3952
@property
4053
def description(self) -> Optional[str]:
54+
"""Gets or sets a description of the Asset providing additional details, such as
55+
how it was processed or created. `CommonMark 0.29 <http://commonmark.org/`__
56+
syntax MAY be used for rich text representation."""
4157
return self.properties.get(ASSET_DESC_PROP)
4258

4359
@description.setter
@@ -49,6 +65,9 @@ def description(self, v: Optional[str]) -> None:
4965

5066
@property
5167
def media_type(self) -> Optional[str]:
68+
"""Gets or sets the `media type
69+
<https://github.com/radiantearth/stac-spec/tree/v1.0.0-rc.1/catalog-spec/catalog-spec.md#media-types>`__
70+
of the asset."""
5271
return self.properties.get(ASSET_TYPE_PROP)
5372

5473
@media_type.setter
@@ -60,6 +79,9 @@ def media_type(self, v: Optional[str]) -> None:
6079

6180
@property
6281
def roles(self) -> Optional[List[str]]:
82+
"""Gets or sets the `semantic roles
83+
<https://github.com/radiantearth/stac-spec/tree/v1.0.0-rc.1/item-spec/item-spec.md#asset-role-types>`__
84+
of the asset, similar to the use of rel in links."""
6385
return self.properties.get(ASSET_ROLES_PROP)
6486

6587
@roles.setter
@@ -69,7 +91,13 @@ def roles(self, v: Optional[List[str]]) -> None:
6991
else:
7092
self.properties[ASSET_ROLES_PROP] = v
7193

94+
def to_dict(self) -> Dict[str, Any]:
95+
"""Returns a JSON-like dictionary representing this ``AssetDefinition``."""
96+
return deepcopy(self.properties)
97+
7298
def create_asset(self, href: str) -> pystac.Asset:
99+
"""Creates a new :class:`~pystac.Asset` instance using the fields from this
100+
``AssetDefinition`` and the given ``href``."""
73101
return pystac.Asset(
74102
href=href,
75103
title=self.title,
@@ -96,6 +124,8 @@ def __init__(self, collection: pystac.Collection) -> None:
96124

97125
@property
98126
def item_assets(self) -> Dict[str, AssetDefinition]:
127+
"""Gets or sets a dictionary of assets that can be found in member Items. Maps
128+
the asset key to an :class:`AssetDefinition` instance."""
99129
result: Dict[str, Any] = get_required(
100130
self.collection.extra_fields.get(ITEM_ASSETS_PROP), self, ITEM_ASSETS_PROP
101131
)
@@ -118,6 +148,13 @@ def get_schema_uri(cls) -> str:
118148
def ext(
119149
cls, obj: pystac.Collection, add_if_missing: bool = False
120150
) -> "ItemAssetsExtension":
151+
"""Extends the given :class:`~pystac.Collection` with properties from the
152+
:stac-ext:`Item Assets Extension <item-assets>`.
153+
154+
Raises:
155+
156+
pystac.ExtensionTypeError : If an invalid object type is passed.
157+
"""
121158
if isinstance(obj, pystac.Collection):
122159
cls.validate_has_extension(obj, add_if_missing)
123160
return cls(obj)

0 commit comments

Comments
 (0)