How to use the pystac.extensions.ExtensionError function in pystac

To help you get started, we’ve selected a few pystac examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github azavea / pystac / tests / extensions / test_view.py View on Github external
def test_apply(self):
        item = next(TestCases.test_case_2().get_all_items())
        with self.assertRaises(ExtensionError):
            item.ext.view

        item.ext.enable(Extensions.VIEW)
        item.ext.view.apply(off_nadir=1.0,
                            incidence_angle=2.0,
                            azimuth=3.0,
                            sun_azimuth=2.0,
                            sun_elevation=1.0)
github azavea / pystac / pystac / extensions / base.py View on Github external
def extend_object(self, extension_id, stac_object):
        """Returns the extension object for the given STACObject and the given
        extension_id
        """
        ext_class = self.get_extension_class(extension_id, type(stac_object))

        if ext_class is None:
            raise ExtensionError("Extension '{}' does not extend objects of type {}".format(
                extension_id, type(stac_object)))

        return ext_class._from_object(stac_object)
github azavea / pystac / pystac / stac_object.py View on Github external
def __getitem__(self, extension_id):
        """Gets the extension object for the given extension.

        Returns:
            CatalogExtension or CollectionExtension or ItemExtension: The extension object
            through which you can access the extension functionality for the extension represented
            by the extension_id.
        """
        # Check to make sure this is a registered extension.
        if not pystac.STAC_EXTENSIONS.is_registered_extension(extension_id):
            raise ExtensionError("'{}' is not an extension "
                                 "registered with PySTAC".format(extension_id))

        if not self.implements(extension_id):
            raise ExtensionError("{} does not implement the {} extension. "
                                 "Use the 'ext.enable' method to enable this extension "
                                 "first.".format(self.stac_object, extension_id))

        return pystac.STAC_EXTENSIONS.extend_object(extension_id, self.stac_object)
github azavea / pystac / pystac / extensions / base.py View on Github external
def get_extension_class(self, extension_id, stac_object_class):
        """Gets the extension class for a given stac object class if one exists, otherwise
        returns None
        """
        ext = self.extensions.get(extension_id)
        if ext is None:
            raise ExtensionError("No ExtensionDefinition registered with id '{}'. "
                                 "Is the extension ID correct, or are you forgetting to call "
                                 "'add_extension' for a custom extension?".format(extension_id))

        ext_classes = [
            e.extension_class for e in ext.extended_objects
            if issubclass(stac_object_class, e.stac_object_class)
        ]

        ext_class = None
        if len(ext_classes) == 0:
            return None
        elif len(ext_classes) == 1:
            ext_class = ext_classes[0]
        else:
            # Need to check collection extensions before catalogs.
            sort_key = {}
github azavea / pystac / pystac / extensions / base.py View on Github external
def remove_extension(self, extension_id):
        """Remove an extension from PySTAC."""
        if extension_id not in self.extensions:
            raise ExtensionError(
                "ExtensionDefinition with id '{}' is not registered.".format(extension_id))
        del self.extensions[extension_id]
github azavea / pystac / pystac / extensions / base.py View on Github external
def __init__(self, stac_object_class, extension_class):
        if stac_object_class is Catalog:
            if not issubclass(extension_class, CatalogExtension):
                raise ExtensionError(
                    "Classes extending catalogs must inheret from CatalogExtension")
        if stac_object_class is Collection:
            if not issubclass(extension_class, CollectionExtension):
                raise ExtensionError(
                    "Classes extending collections must inheret from CollectionExtension")
        if stac_object_class is Item:
            if not issubclass(extension_class, ItemExtension):
                raise ExtensionError("Classes extending item must inheret from ItemExtension")

        self.stac_object_class = stac_object_class
        self.extension_class = extension_class
github azavea / pystac / pystac / extensions / base.py View on Github external
def __init__(self, stac_object_class, extension_class):
        if stac_object_class is Catalog:
            if not issubclass(extension_class, CatalogExtension):
                raise ExtensionError(
                    "Classes extending catalogs must inheret from CatalogExtension")
        if stac_object_class is Collection:
            if not issubclass(extension_class, CollectionExtension):
                raise ExtensionError(
                    "Classes extending collections must inheret from CollectionExtension")
        if stac_object_class is Item:
            if not issubclass(extension_class, ItemExtension):
                raise ExtensionError("Classes extending item must inheret from ItemExtension")

        self.stac_object_class = stac_object_class
        self.extension_class = extension_class
github azavea / pystac / pystac / extensions / base.py View on Github external
def __init__(self, stac_object_class, extension_class):
        if stac_object_class is Catalog:
            if not issubclass(extension_class, CatalogExtension):
                raise ExtensionError(
                    "Classes extending catalogs must inheret from CatalogExtension")
        if stac_object_class is Collection:
            if not issubclass(extension_class, CollectionExtension):
                raise ExtensionError(
                    "Classes extending collections must inheret from CollectionExtension")
        if stac_object_class is Item:
            if not issubclass(extension_class, ItemExtension):
                raise ExtensionError("Classes extending item must inheret from ItemExtension")

        self.stac_object_class = stac_object_class
        self.extension_class = extension_class
github azavea / pystac / pystac / extensions / base.py View on Github external
"""Returns True if the extension can extend the given object type.

        Args:
            extension_id (str): The extension ID to check.
            stac_object_class: the class of the object to check. Will check against subclasses,
                so will return the correct result even if the object is a subclass of Catalog,
                Collection or Item.

        Returns:
            bool
        """
        ext = self.extensions.get(extension_id)

        # Check to make sure this is a registered extension.
        if ext is None:
            raise ExtensionError("'{}' is not a registered extension".format(extension_id))

        return any([
            e.extension_class for e in ext.extended_objects
            if issubclass(stac_object_class, e.stac_object_class)
        ])