7
7
import pystac
8
8
from pystac import RelType , STACError , STACObjectType
9
9
from pystac .asset import Asset
10
+ from pystac .band import Band
10
11
from pystac .catalog import Catalog
11
12
from pystac .collection import Collection
12
13
from pystac .errors import DeprecatedWarning , ExtensionNotImplemented
@@ -106,6 +107,8 @@ class Item(STACObject):
106
107
stac_extensions : List [str ]
107
108
"""List of extensions the Item implements."""
108
109
110
+ _bands : Optional [List [Band ]]
111
+
109
112
STAC_OBJECT_TYPE = STACObjectType .ITEM
110
113
111
114
def __init__ (
@@ -122,6 +125,7 @@ def __init__(
122
125
collection : Optional [Union [str , Collection ]] = None ,
123
126
extra_fields : Optional [Dict [str , Any ]] = None ,
124
127
assets : Optional [Dict [str , Asset ]] = None ,
128
+ bands : Optional [List [Band ]] = None ,
125
129
):
126
130
super ().__init__ (stac_extensions or [])
127
131
@@ -167,6 +171,8 @@ def __init__(
167
171
for k , asset in assets .items ():
168
172
self .add_asset (k , asset )
169
173
174
+ self ._bands = bands
175
+
170
176
def __repr__ (self ) -> str :
171
177
return "<Item id={}>" .format (self .id )
172
178
@@ -406,6 +412,16 @@ def get_derived_from(self) -> List[Item]:
406
412
"Link failed to resolve. Use get_links instead."
407
413
) from e
408
414
415
+ @property
416
+ def bands (self ) -> Optional [List [Band ]]:
417
+ """Returns the bands set on this item."""
418
+ return self ._bands
419
+
420
+ @bands .setter
421
+ def bands (self , bands : Optional [List [Band ]]) -> None :
422
+ """Sets the bands on this item."""
423
+ self ._bands = bands
424
+
409
425
def to_dict (
410
426
self , include_self_link : bool = True , transform_hrefs : bool = True
411
427
) -> Dict [str , Any ]:
@@ -442,6 +458,9 @@ def to_dict(
442
458
for key in self .extra_fields :
443
459
d [key ] = self .extra_fields [key ]
444
460
461
+ if self .bands is not None :
462
+ d ["properties" ]["bands" ] = [band .to_dict () for band in self .bands ]
463
+
445
464
return d
446
465
447
466
def clone (self ) -> Item :
@@ -516,13 +535,20 @@ def from_dict(
516
535
if k not in [* pass_through_fields , * parse_fields , * exclude_fields ]
517
536
}
518
537
538
+ bands = properties .pop ("bands" , None )
539
+ if bands is not None :
540
+ deserialized_bands = [Band .from_dict (d ) for d in bands ]
541
+ else :
542
+ deserialized_bands = None
543
+
519
544
item = cls (
520
545
** {k : d .get (k ) for k in pass_through_fields }, # type: ignore
521
546
datetime = datetime ,
522
547
properties = properties ,
523
548
extra_fields = extra_fields ,
524
549
href = href ,
525
550
assets = {k : Asset .from_dict (v ) for k , v in assets .items ()},
551
+ bands = deserialized_bands ,
526
552
)
527
553
528
554
for link in links :
0 commit comments