Пример #1
0
def write_file(
    obj: STACObject,
    include_self_link: bool = True,
    dest_href: Optional[HREF] = None,
    stac_io: Optional[StacIO] = None,
) -> None:
    """Writes a STACObject to a file.

    This will write only the Catalog, Collection or Item ``obj``. It will not attempt
    to write any other objects that are linked to ``obj``; if you'd like functionality
    to save off catalogs recursively see :meth:`Catalog.save <pystac.Catalog.save>`.

    This method will write the JSON of the object to the object's assigned "self" link
    or to the dest_href if provided. To set the self link, see
    :meth:`STACObject.set_self_href <pystac.STACObject.set_self_href>`.

    Convenience method for :meth:`STACObject.from_file <pystac.STACObject.from_file>`

    Args:
        obj : The STACObject to save.
        include_self_link : If ``True``, include the ``"self"`` link with this object.
            Otherwise, leave out the self link.
        dest_href : Optional HREF to save the file to. If ``None``, the object will be
            saved to the object's ``"self"`` href.
        stac_io: Optional :class:`~StacIO` instance to use for I/O operations. If not
            provided, will use :meth:`StacIO.default` to create an instance.
    """
    if stac_io is None:
        stac_io = StacIO.default()
    dest_href = None if dest_href is None else str(os.fspath(dest_href))
    obj.save_object(include_self_link=include_self_link,
                    dest_href=dest_href,
                    stac_io=stac_io)
Пример #2
0
    def set_root(self, root, recursive=False):
        STACObject.set_root(self, root)
        root._resolved_objects = ResolvedObjectCache.merge(root._resolved_objects,
                                                           self._resolved_objects)

        if recursive:
            for child in self.get_children():
                child.set_root(root, recurive=True)
            for item in self.get_items():
                item.set_root(root)
Пример #3
0
    def set_root(self, root: Optional["Catalog"]) -> None:
        STACObject.set_root(self, root)
        if root is not None:
            root._resolved_objects = ResolvedObjectCache.merge(
                root._resolved_objects, self._resolved_objects
            )

            # Walk through resolved object links and update the root
            for link in self.links:
                if link.rel == pystac.RelType.CHILD or link.rel == pystac.RelType.ITEM:
                    target = link.target
                    if isinstance(target, STACObject):
                        target.set_root(root)
Пример #4
0
def read_file(href):
    """Reads a STAC object from a file.

    This method will return either a Catalog, a Collection, or an Item based on what the
    file contains.

    This is a convenience method for :meth:`STACObject.from_file <pystac.STACObject.from_file>`

    Args:
        href (str): The HREF to read the object from.

    Returns:
        The specific STACObject implementation class that is represented
        by the JSON read from the file located at HREF.
    """
    return STACObject.from_file(href)
Пример #5
0
 def set_root(self, root, link_type=LinkType.ABSOLUTE):
     STACObject.set_root(self, root, link_type)
     if root is not None:
         root._resolved_objects = ResolvedObjectCache.merge(
             root._resolved_objects, self._resolved_objects)