2222 SummariesExtension ,
2323)
2424from pystac .extensions .hooks import ExtensionHooks
25+ import pystac .extensions .item_assets as item_assets
2526from pystac .serialization .identify import STACJSONDescription , STACVersionID
2627from pystac .utils import get_required , map_opt
2728
28- T = TypeVar ("T" , pystac .Item , pystac .Asset )
29+ T = TypeVar ("T" , pystac .Item , pystac .Asset , item_assets . AssetDefinition )
2930
3031SCHEMA_URI : str = "https://stac-extensions.github.io/classification/v1.0.0/schema.json"
3132PREFIX : str = "classification:"
@@ -350,6 +351,8 @@ def ext(cls, obj: T, add_if_missing: bool = False) -> ClassificationExtension[T]
350351 elif isinstance (obj , pystac .Collection ):
351352 cls .validate_has_extension (obj , add_if_missing )
352353 return cast (ClassificationExtension [T ], CollectionClassificationExtension (obj ))
354+ elif isinstance (obj , item_assets .AssetDefinition ):
355+ return cast (ClassificationExtension [T ], ItemAssetsClassificationExtension (obj ))
353356 else :
354357 raise pystac .ExtensionTypeError (
355358 f"Classification extension does not apply to type '{ type (obj ).__name__ } '"
@@ -439,6 +442,18 @@ def __repr__(self) -> str:
439442 return f"<AssetClassificationExtension Asset href={ self .asset_href } >"
440443
441444
445+ class ItemAssetsClassificationExtension (ClassificationExtension [item_assets .AssetDefinition ]):
446+ properties : Dict [str , Any ]
447+ asset_defn : item_assets .AssetDefinition
448+
449+ def __init__ (self , item_asset : item_assets .AssetDefinition ):
450+ self .asset_defn = item_asset
451+ self .properties = item_asset .properties
452+
453+ def __repr__ (self ) -> str :
454+ return f"<ItemAssetsClassificationExtension AssetDefinition={ self .asset_defn } "
455+
456+
442457class CollectionClassificationExtension (ClassificationExtension [pystac .Collection ]):
443458 """A concrete implementation of :class:`ClassificationExtension` on a
444459 :class:`~pystac.Collection` that extends the properties of a Collection to
@@ -461,30 +476,30 @@ def _get_classes(self) -> Optional[List[Optional[Classification]]]:
461476 def _get_bitfields (self ) -> Optional [List [Bitfield ]]:
462477 pass
463478
464- class SummariesClassificationExtension (SummariesExtension ):
465- @property
466- def classes (self ) -> Optional [List [Classification ]]:
467- return map_opt (
468- lambda classes : [Classification (c ) for c in classes ],
469- self .summaries .get_list (CLASSES_PROP ),
470- )
471-
472- @classes .setter
473- def classes (self , v : Optional [List [Classification ]]) -> None :
474- self ._set_summary (CLASSES_PROP , map_opt (lambda x : [c .to_dict () for c in x ], v ))
475-
476- @property
477- def bitfields (self ) -> Optional [List [Bitfield ]]:
478- return map_opt (
479- lambda bitfields : [Bitfield (b ) for b in bitfields ],
480- self .summaries .get_list (BITFIELDS_PROP ),
481- )
482-
483- @bitfields .setter
484- def bitfields (self , v : Optional [List [Bitfield ]]) -> None :
485- self ._set_summary (
486- BITFIELDS_PROP , map_opt (lambda x : [b .to_dict () for b in x ], v )
487- )
479+ # class SummariesClassificationExtension(SummariesExtension):
480+ # @property
481+ # def classes(self) -> Optional[List[Classification]]:
482+ # return map_opt(
483+ # lambda classes: [Classification(c) for c in classes],
484+ # self.summaries.get_list(CLASSES_PROP),
485+ # )
486+
487+ # @classes.setter
488+ # def classes(self, v: Optional[List[Classification]]) -> None:
489+ # self._set_summary(CLASSES_PROP, map_opt(lambda x: [c.to_dict() for c in x], v))
490+
491+ # @property
492+ # def bitfields(self) -> Optional[List[Bitfield]]:
493+ # return map_opt(
494+ # lambda bitfields: [Bitfield(b) for b in bitfields],
495+ # self.summaries.get_list(BITFIELDS_PROP),
496+ # )
497+
498+ # @bitfields.setter
499+ # def bitfields(self, v: Optional[List[Bitfield]]) -> None:
500+ # self._set_summary(
501+ # BITFIELDS_PROP, map_opt(lambda x: [b.to_dict() for b in x], v)
502+ # )
488503
489504
490505class ClassificationExtensionHooks (ExtensionHooks ):
0 commit comments