4
4
"""
5
5
6
6
import enum
7
- from typing import Any , Dict , Generic , Iterable , List , Optional , TypeVar , cast
7
+ from typing import Any , Dict , Iterable , List , Optional
8
8
9
9
import pystac
10
10
from pystac .extensions .base import (
14
14
)
15
15
from pystac .utils import get_opt , get_required , map_opt
16
16
17
- T = TypeVar ("T" , pystac .Item , pystac .Asset )
18
-
19
17
SCHEMA_URI = "https://stac-extensions.github.io/raster/v1.0.0/schema.json"
20
18
21
19
BANDS_PROP = "raster:bands"
@@ -625,9 +623,7 @@ def to_dict(self) -> Dict[str, Any]:
625
623
return self .properties
626
624
627
625
628
- class RasterExtension (
629
- Generic [T ], PropertiesExtension , ExtensionManagementMixin [pystac .Item ]
630
- ):
626
+ class RasterExtension (PropertiesExtension , ExtensionManagementMixin [pystac .Item ]):
631
627
"""An abstract class that can be used to extend the properties of an
632
628
:class:`~pystac.Item` or :class:`~pystac.Asset` with properties from
633
629
the :stac-ext:`Raster Extension <raster>`. This class is generic over
@@ -639,6 +635,25 @@ class RasterExtension(
639
635
:class:`~ItemRasterExtension` to extend an :class:`~pystac.Item`).
640
636
"""
641
637
638
+ asset_href : str
639
+ """The ``href`` value of the :class:`~pystac.Asset` being extended."""
640
+
641
+ properties : Dict [str , Any ]
642
+ """The :class:`~pystac.Asset` fields, including extension properties."""
643
+
644
+ additional_read_properties : Optional [Iterable [Dict [str , Any ]]] = None
645
+ """If present, this will be a list containing 1 dictionary representing the
646
+ properties of the owning :class:`~pystac.Item`."""
647
+
648
+ def __init__ (self , asset : pystac .Asset ):
649
+ self .asset_href = asset .href
650
+ self .properties = asset .properties
651
+ if asset .owner and isinstance (asset .owner , pystac .Item ):
652
+ self .additional_read_properties = [asset .owner .properties ]
653
+
654
+ def __repr__ (self ) -> str :
655
+ return "<AssetRasterExtension Asset href={}>" .format (self .asset_href )
656
+
642
657
def apply (self , bands : List [RasterBand ]) -> None :
643
658
"""Applies raster extension properties to the extended :class:`pystac.Item` or
644
659
:class:`pystac.Asset`.
@@ -673,10 +688,20 @@ def _get_bands(self) -> Optional[List[RasterBand]]:
673
688
def get_schema_uri (cls ) -> str :
674
689
return SCHEMA_URI
675
690
676
- @staticmethod
677
- def ext (obj : T ) -> "RasterExtension[T]" :
691
+ @classmethod
692
+ def ext (cls , obj : pystac .Asset ) -> "RasterExtension" :
693
+ """Extends the given STAC Object with properties from the :stac-ext:`Raster
694
+ Extension <raster>`.
695
+
696
+ This extension can be applied to instances of :class:`~pystac.Asset`.
697
+
698
+ Raises:
699
+
700
+ pystac.ExtensionTypeError : If an invalid object type is passed.
701
+ """
678
702
if isinstance (obj , pystac .Asset ):
679
- return cast (RasterExtension [T ], AssetRasterExtension (obj ))
703
+ cls .validate_has_extension (obj )
704
+ return cls (obj )
680
705
else :
681
706
raise pystac .ExtensionTypeError (
682
707
f"Raster extension does not apply to type { type (obj )} "
@@ -687,35 +712,6 @@ def summaries(obj: pystac.Collection) -> "SummariesRasterExtension":
687
712
return SummariesRasterExtension (obj )
688
713
689
714
690
- class AssetRasterExtension (RasterExtension [pystac .Asset ]):
691
- """A concrete implementation of :class:`RasterExtension` on an :class:`~pystac.Asset`
692
- that extends the Asset fields to include properties defined in the
693
- :stac-ext:`Raster Extension <raster>`.
694
-
695
- This class should generally not be instantiated directly. Instead, call
696
- :meth:`RasterExtension.ext` on an :class:`~pystac.Asset` to extend it.
697
- """
698
-
699
- asset_href : str
700
- """The ``href`` value of the :class:`~pystac.Asset` being extended."""
701
-
702
- properties : Dict [str , Any ]
703
- """The :class:`~pystac.Asset` fields, including extension properties."""
704
-
705
- additional_read_properties : Optional [Iterable [Dict [str , Any ]]] = None
706
- """If present, this will be a list containing 1 dictionary representing the
707
- properties of the owning :class:`~pystac.Item`."""
708
-
709
- def __init__ (self , asset : pystac .Asset ):
710
- self .asset_href = asset .href
711
- self .properties = asset .properties
712
- if asset .owner and isinstance (asset .owner , pystac .Item ):
713
- self .additional_read_properties = [asset .owner .properties ]
714
-
715
- def __repr__ (self ) -> str :
716
- return "<AssetRasterExtension Asset href={}>" .format (self .asset_href )
717
-
718
-
719
715
class SummariesRasterExtension (SummariesExtension ):
720
716
"""A concrete implementation of :class:`~SummariesExtension` that extends
721
717
the ``summaries`` field of a :class:`~pystac.Collection` to include properties
0 commit comments