How to use the pystac.item.Item.from_dict 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 / pystac / single_file_stac.py View on Github external
def from_dict(d):
        """Constructs an SingleFileSTAC from a dict.

        Returns:
            SingleFileSTAC: The SingleFileSTAC deserialized from the JSON dict.
        """
        features = [Item.from_dict(feature) for feature in d['features']]
        collections = [Collection.from_dict(c) for c in d['collections']]

        # Tie together items to their collections
        collection_dict = dict([(c.id, c) for c in collections])
        for item in features:
            if item.collection_id is not None:
                if item.collection_id not in collection_dict:
                    raise STACError('Collection with id {} is referenced '
                                    'by item {}, but is not in the collections '
                                    'of this SingleFileSTAC'.format(item.collection_id, item.id))
                item.set_collection(collection_dict[item.collection_id])

        search_obj = None
        if 'search' in d.keys():
            sd = d['search']
            search_obj = Search(sd.get('endpoint'), sd.get('parameters'))
github azavea / pystac / pystac / eo.py View on Github external
def from_dict(cls, d, href=None, root=None):
        item = Item.from_dict(d, href=href, root=root)
        return cls.from_item(item)
github azavea / pystac / pystac / __init__.py View on Github external
# TODO: Transorm older versions to newest version (pystac.serialization.migrate)

    if info.object_type == STACObjectType.CATALOG:
        return Catalog.from_dict(d, href=href, root=root)
    if info.object_type == STACObjectType.COLLECTION:
        return Collection.from_dict(d, href=href, root=root)
    if info.object_type == STACObjectType.ITEMCOLLECTION:
        if 'single-file-stac' in info.common_extensions:
            return SingleFileSTAC.from_dict(d, href=href, root=root)
        return ItemCollection.from_dict(d, href=href, root=root)
    if info.object_type == STACObjectType.ITEM:
        if 'eo' in info.common_extensions:
            return EOItem.from_dict(d, href=href, root=root)
        if 'label' in info.common_extensions:
            return LabelItem.from_dict(d, href=href, root=root)
        return Item.from_dict(d, href=href, root=root)
github azavea / pystac / pystac / item_collection.py View on Github external
def from_dict(d):
        """Constructs an ItemCollection from a dict.

        Returns:
            ItemCollection: The ItemCollection deserialized from the JSON dict.
        """
        features = [Item.from_dict(feature) for feature in d['features']]
        ic = ItemCollection(features)
        if 'links' in d.keys():
            for link in d['links']:
                ic.add_link(Link.from_dict(link))
        return ic