def from_dict(cls, d, href=None, root=None): catalog_type = CatalogType.determine_type(d) d = deepcopy(d) id = d.pop('id') description = d.pop('description') title = d.pop('title', None) stac_extensions = d.pop('stac_extensions', None) links = d.pop('links') d.pop('stac_version') cat = Catalog(id=id, description=description, title=title, stac_extensions=stac_extensions, extra_fields=d, href=href, catalog_type=catalog_type) for link in links: if link['rel'] == 'root': # Remove the link that's generated in Catalog's constructor. cat.remove_links('root') if link['rel'] != 'self' or href is None: cat.add_link(Link.from_dict(link)) return cat
def from_dict(cls, d, href=None, root=None): id = d['id'] description = d['description'] license = d['license'] extent = Extent.from_dict(d['extent']) title = d.get('title') stac_extensions = d.get('stac_extensions') keywords = d.get('keywords') version = d.get('version') providers = d.get('providers') if providers is not None: providers = list(map(lambda x: Provider.from_dict(x), providers)) properties = d.get('properties') summaries = d.get('summaries') collection = Collection(id=id, description=description, extent=extent, title=title, license=license, stac_extensions=stac_extensions, keywords=keywords, version=version, providers=providers, properties=properties, summaries=summaries) for l in d['links']: if l['rel'] == 'root': # Remove the link that's generated in Catalog's constructor. collection.remove_links('root') collection.add_link(Link.from_dict(l)) return collection
def from_dict(d): id = d['id'] description = d['description'] license = d['license'] extent = Extent.from_dict(d['extent']) title = d.get('title') stac_extensions = d.get('stac_extensions') keywords = d.get('keywords') version = d.get('version') providers = d.get('providers') if providers is not None: providers = list(map(lambda x: Provider.from_dict(x), providers)) properties = d.get('properties') summaries = d.get('summaries') collection = Collection(id=id, description=description, extent=extent, title=title, license=license, stac_extensions=stac_extensions, keywords=keywords, version=version, providers=providers, properties=properties, summaries=summaries) for l in d['links']: collection.add_link(Link.from_dict(l)) return collection
def from_dict(cls, d, href=None, root=None): id = d['id'] geometry = d['geometry'] bbox = d['bbox'] properties = d['properties'] stac_extensions = d.get('stac_extensions') collection_id = None if 'collection' in d.keys(): collection_id = d['collection'] datetime = properties.get('datetime') if datetime is None: raise STACError('Item dict is missing a "datetime" property in the "properties" field') datetime = dateutil.parser.parse(datetime) item = Item(id=id, geometry=geometry, bbox=bbox, datetime=datetime, properties=properties, stac_extensions=stac_extensions, collection=collection_id) for l in d['links']: item.add_link(Link.from_dict(l)) for k, v in d['assets'].items(): asset = Asset.from_dict(v) asset.set_owner(item) item.assets[k] = asset return item
def from_dict( cls, d: Dict[str, Any], href: Optional[str] = None, root: Optional[Catalog] = None, migrate: bool = False, preserve_dict: bool = True, ) -> "Item": if migrate: info = identify_stac_object(d) d = migrate_to_latest(d, info) if not cls.matches_object_type(d): raise pystac.STACTypeError( f"{d} does not represent a {cls.__name__} instance") if preserve_dict: d = deepcopy(d) id = d.pop("id") geometry = d.pop("geometry") properties = d.pop("properties") bbox = d.pop("bbox", None) stac_extensions = d.get("stac_extensions") collection_id = d.pop("collection", None) datetime = properties.get("datetime") if datetime is not None: datetime = str_to_datetime(datetime) links = d.pop("links") assets = d.pop("assets") d.pop("type") d.pop("stac_version") item = cls( id=id, geometry=geometry, bbox=bbox, datetime=datetime, properties=properties, stac_extensions=stac_extensions, collection=collection_id, extra_fields=d, assets={k: Asset.from_dict(v) for k, v in assets.items()}, ) has_self_link = False for link in links: has_self_link |= link["rel"] == pystac.RelType.SELF item.add_link(Link.from_dict(link)) if not has_self_link and href is not None: item.add_link(Link.self_href(href)) if root: item.set_root(root) return item
def from_dict(cls, d, href=None, root=None): d = deepcopy(d) id = d.pop('id') description = d.pop('description') title = d.pop('title', None) stac_extensions = d.pop('stac_extensions', None) links = d.pop('links') d.pop('stac_version') cat = Catalog(id=id, description=description, title=title, stac_extensions=stac_extensions, extra_fields=d) has_self_link = False for link in links: has_self_link |= link['rel'] == 'self' if link['rel'] == 'root': # Remove the link that's generated in Catalog's constructor. cat.remove_links('root') cat.add_link(Link.from_dict(link)) if not has_self_link and href is not None: cat.add_link(Link.self_href(href)) return cat
def from_dict(d): id = d['id'] geometry = d['geometry'] bbox = d['bbox'] properties = d['properties'] stac_extensions = d.get('stac_extensions') datetime = properties.get('datetime') if datetime is None: raise STACError( 'Item dict is missing a "datetime" property in the "properties" field' ) datetime = dateutil.parser.parse(datetime) item = Item(id=id, geometry=geometry, bbox=bbox, datetime=datetime, properties=properties, stac_extensions=stac_extensions) for l in d['links']: item.add_link(Link.from_dict(l)) for k, v in d['assets'].items(): item.assets[k] = Asset.from_dict(v) return item
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
def from_dict( cls, d: Dict[str, Any], href: Optional[str] = None, root: Optional["Catalog"] = None, migrate: bool = False, preserve_dict: bool = True, ) -> "Catalog": if migrate: info = identify_stac_object(d) d = migrate_to_latest(d, info) if not cls.matches_object_type(d): raise STACTypeError(f"{d} does not represent a {cls.__name__} instance") catalog_type = CatalogType.determine_type(d) if preserve_dict: d = deepcopy(d) id = d.pop("id") description = d.pop("description") title = d.pop("title", None) stac_extensions = d.pop("stac_extensions", None) links = d.pop("links") d.pop("stac_version") cat = cls( id=id, description=description, title=title, stac_extensions=stac_extensions, extra_fields=d, href=href, catalog_type=catalog_type or CatalogType.ABSOLUTE_PUBLISHED, ) for link in links: if link["rel"] == pystac.RelType.ROOT: # Remove the link that's generated in Catalog's constructor. cat.remove_links(pystac.RelType.ROOT) if link["rel"] != pystac.RelType.SELF or href is None: cat.add_link(Link.from_dict(link)) if root: cat.set_root(root) return cat
def from_dict(d): id = d['id'] description = d['description'] title = d.get('title') cat = Catalog(id=id, description=description, title=title) for l in d['links']: if not l['rel'] == 'root': cat.add_link(Link.from_dict(l)) return cat
def from_dict(cls, d, href=None, root=None): id = d['id'] description = d['description'] title = d.get('title') cat = Catalog(id=id, description=description, title=title) for l in d['links']: if l['rel'] == 'root': # Remove the link that's generated in Catalog's constructor. cat.remove_links('root') cat.add_link(Link.from_dict(l)) return cat
def from_dict(cls, d, href=None, root=None): d = deepcopy(d) id = d.pop('id') description = d.pop('description') license = d.pop('license') extent = Extent.from_dict(d.pop('extent')) title = d.get('title') stac_extensions = d.get('stac_extensions') keywords = d.get('keywords') providers = d.get('providers') if providers is not None: providers = list(map(lambda x: Provider.from_dict(x), providers)) properties = d.get('properties') summaries = d.get('summaries') links = d.pop('links') d.pop('stac_version') collection = Collection(id=id, description=description, extent=extent, title=title, stac_extensions=stac_extensions, extra_fields=d, license=license, keywords=keywords, providers=providers, properties=properties, summaries=summaries) has_self_link = False for link in links: has_self_link |= link['rel'] == 'self' if link['rel'] == 'root': # Remove the link that's generated in Catalog's constructor. collection.remove_links('root') collection.add_link(Link.from_dict(link)) if not has_self_link and href is not None: collection.add_link(Link.self_href(href)) return collection
def from_dict(cls, d, href=None, root=None): id = d['id'] description = d['description'] title = d.get('title') cat = Catalog(id=id, description=description, title=title) has_self_link = False for link in d['links']: has_self_link |= link['rel'] == 'self' if link['rel'] == 'root': # Remove the link that's generated in Catalog's constructor. cat.remove_links('root') cat.add_link(Link.from_dict(link)) if not has_self_link and href is not None: cat.add_link(Link.self_href(href)) return cat
def from_dict(cls, d, href=None, root=None): d = deepcopy(d) id = d.pop('id') geometry = d.pop('geometry') properties = d.pop('properties') bbox = d.pop('bbox', None) stac_extensions = d.get('stac_extensions') collection_id = d.pop('collection', None) datetime = properties.get('datetime') if datetime is not None: datetime = dateutil.parser.parse(datetime) links = d.pop('links') assets = d.pop('assets') d.pop('type') d.pop('stac_version') item = Item(id=id, geometry=geometry, bbox=bbox, datetime=datetime, properties=properties, stac_extensions=stac_extensions, collection=collection_id, extra_fields=d) has_self_link = False for link in links: has_self_link |= link['rel'] == 'self' item.add_link(Link.from_dict(link)) if not has_self_link and href is not None: item.add_link(Link.self_href(href)) for k, v in assets.items(): asset = Asset.from_dict(v) asset.set_owner(item) item.assets[k] = asset return item
def from_dict( cls, d: Dict[str, Any], href: Optional[str] = None, root: Optional[Catalog] = None, migrate: bool = False, preserve_dict: bool = True, ) -> "Collection": if migrate: info = identify_stac_object(d) d = migrate_to_latest(d, info) if not cls.matches_object_type(d): raise STACTypeError( f"{d} does not represent a {cls.__name__} instance") catalog_type = CatalogType.determine_type(d) if preserve_dict: d = deepcopy(d) id = d.pop("id") description = d.pop("description") license = d.pop("license") extent = Extent.from_dict(d.pop("extent")) title = d.get("title") stac_extensions = d.get("stac_extensions") keywords = d.get("keywords") providers = d.get("providers") if providers is not None: providers = list( map(lambda x: pystac.Provider.from_dict(x), providers)) summaries = d.get("summaries") if summaries is not None: summaries = Summaries(summaries) assets: Optional[Dict[str, Any]] = { k: Asset.from_dict(v) for k, v in d.get("assets", {}).items() } links = d.pop("links") d.pop("stac_version") collection = cls( id=id, description=description, extent=extent, title=title, stac_extensions=stac_extensions, extra_fields=d, license=license, keywords=keywords, providers=providers, summaries=summaries, href=href, catalog_type=catalog_type, assets=assets, ) for link in links: if link["rel"] == pystac.RelType.ROOT: # Remove the link that's generated in Catalog's constructor. collection.remove_links(pystac.RelType.ROOT) if link["rel"] != pystac.RelType.SELF or href is None: collection.add_link(Link.from_dict(link)) if root: collection.set_root(root) return collection
def from_dict(cls, d, href=None, root=None): id = d['id'] geometry = d['geometry'] bbox = d['bbox'] properties = d['properties'] stac_extensions = d.get('stac_extensions') collection_id = None if 'collection' in d.keys(): collection_id = d['collection'] datetime = properties.get('datetime') if datetime is None: raise STACError( 'Item dict is missing a "datetime" property in the "properties" field' ) datetime = dateutil.parser.parse(datetime) item = Item(id=id, geometry=geometry, bbox=bbox, datetime=datetime, properties=properties, stac_extensions=stac_extensions, collection=collection_id) for l in d['links']: item.add_link(Link.from_dict(l)) for k, v in d['assets'].items(): item.assets[k] = Asset.from_dict(v) # Find the collection, merge properties if there are # common properties to merge. collection_to_merge = None if collection_id is not None and root is not None: collection_to_merge = root._resolved_objects.get_by_id( collection_id) else: collection_link = item.get_single_link('collection') if collection_link is not None: # If there's a relative collection link, and we have an href passed # in, we can resolve the collection from the link. If not, # we'll skip merging in collection properties. if collection_link.link_type == LinkType.RELATIVE and \ not collection_link.is_resolved(): if href is not None: collection_link = collection_link.clone() collection_link.target = make_absolute_href( collection_link.target, href) else: collection_link = None if collection_link is not None: collection_to_merge = collection_link.resolve_stac_object( root=root).target if item.collection_id is None: item.collection_id = collection_to_merge.id if collection_to_merge is not None: if collection_to_merge.properties is not None: item.properties = dict( ChainMap(item.properties, collection_to_merge.properties)) return item