3
3
https://github.com/stac-extensions/item-assets
4
4
"""
5
5
6
+ from copy import deepcopy
6
7
from typing import Any , Dict , List , Optional
7
8
8
9
import pystac
22
23
23
24
24
25
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
+
25
32
def __init__ (self , properties : Dict [str , Any ]) -> None :
26
33
self .properties = properties
27
34
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
+
28
40
@property
29
41
def title (self ) -> Optional [str ]:
42
+ """Gets or sets the displayed title for clients and users."""
30
43
return self .properties .get (ASSET_TITLE_PROP )
31
44
32
45
@title .setter
@@ -38,6 +51,9 @@ def title(self, v: Optional[str]) -> None:
38
51
39
52
@property
40
53
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."""
41
57
return self .properties .get (ASSET_DESC_PROP )
42
58
43
59
@description .setter
@@ -49,6 +65,9 @@ def description(self, v: Optional[str]) -> None:
49
65
50
66
@property
51
67
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."""
52
71
return self .properties .get (ASSET_TYPE_PROP )
53
72
54
73
@media_type .setter
@@ -60,6 +79,9 @@ def media_type(self, v: Optional[str]) -> None:
60
79
61
80
@property
62
81
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."""
63
85
return self .properties .get (ASSET_ROLES_PROP )
64
86
65
87
@roles .setter
@@ -69,7 +91,13 @@ def roles(self, v: Optional[List[str]]) -> None:
69
91
else :
70
92
self .properties [ASSET_ROLES_PROP ] = v
71
93
94
+ def to_dict (self ) -> Dict [str , Any ]:
95
+ """Returns a JSON-like dictionary representing this ``AssetDefinition``."""
96
+ return deepcopy (self .properties )
97
+
72
98
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``."""
73
101
return pystac .Asset (
74
102
href = href ,
75
103
title = self .title ,
@@ -96,6 +124,8 @@ def __init__(self, collection: pystac.Collection) -> None:
96
124
97
125
@property
98
126
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."""
99
129
result : Dict [str , Any ] = get_required (
100
130
self .collection .extra_fields .get (ITEM_ASSETS_PROP ), self , ITEM_ASSETS_PROP
101
131
)
@@ -118,6 +148,13 @@ def get_schema_uri(cls) -> str:
118
148
def ext (
119
149
cls , obj : pystac .Collection , add_if_missing : bool = False
120
150
) -> "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
+ """
121
158
if isinstance (obj , pystac .Collection ):
122
159
cls .validate_has_extension (obj , add_if_missing )
123
160
return cls (obj )
0 commit comments