def from_file(cls, href: str, stac_io: Optional[pystac.StacIO] = None) -> "Collection": result = super().from_file(href, stac_io) if not isinstance(result, Collection): raise pystac.STACTypeError(f"{result} is not a {Collection}.") return result
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_file(cls, href: str, stac_io: Optional[pystac.StacIO] = None) -> "Catalog": if stac_io is None: stac_io = pystac.StacIO.default() result = super().from_file(href, stac_io) if not isinstance(result, Catalog): raise pystac.STACTypeError(f"{result} is not a {Catalog}.") result._stac_io = stac_io return result
def identify_stac_object(json_dict: Dict[str, Any]) -> STACJSONDescription: """Determines the STACJSONDescription of the provided JSON dict. Args: json_dict : The dict of STAC JSON to identify. Returns: STACJSONDescription: The description of the STAC object serialized in the given dict. """ object_type = identify_stac_object_type(json_dict) if object_type is None: raise pystac.STACTypeError("JSON does not represent a STAC object.") version_range = STACVersionRange() stac_version = json_dict.get("stac_version") stac_extensions = json_dict.get("stac_extensions", None) if stac_version is None: version_range.set_min(STACVersionID("0.8.0")) else: version_range.set_to_single(stac_version) if stac_extensions is not None: version_range.set_min(STACVersionID("0.8.0")) if stac_extensions is None: stac_extensions = [] # Between 1.0.0-beta.2 and 1.0.0-RC1, STAC extensions changed from # being split between 'common' and custom extensions, with common # extensions having short names that were used in the stac_extensions # property list, to being mostly externalized from the core spec and # always identified with the schema URI as the identifier. This # code translates the short name IDs used pre-1.0.0-RC1 to the # relevant extension schema uri identifier. return STACJSONDescription(object_type, version_range, set(stac_extensions))