Example #1
0
    def add_child(
        self,
        child: Union["Catalog", "Collection_Type"],
        title: Optional[str] = None,
        strategy: Optional[HrefLayoutStrategy] = None,
    ) -> None:
        """Adds a link to a child :class:`~pystac.Catalog` or
        :class:`~pystac.Collection`. This method will set the child's parent to this
        object, and its root to this Catalog's root.

        Args:
            child : The child to add.
            title : Optional title to give to the :class:`~pystac.Link`
            strategy : The layout strategy to use for setting the
                self href of the child.
        """

        # Prevent typo confusion
        if isinstance(child, pystac.Item):
            raise pystac.STACError("Cannot add item as child. Use add_item instead.")

        if strategy is None:
            strategy = BestPracticesLayoutStrategy()

        child.set_root(self.get_root())
        child.set_parent(self)

        # set self link
        self_href = self.get_self_href()
        if self_href:
            child_href = strategy.get_href(child, os.path.dirname(self_href))
            child.set_self_href(child_href)

        self.add_link(Link.child(child, title=title))
Example #2
0
    def add_child(self, child, title=None):
        """Adds a link to a child :class:`~pystac.Catalog` or :class:`~pystac.Collection`.
        This method will set the child's parent to this object, and its root to
        this Catalog's root.

        Args:
            child (Catalog or Collection): The child to add.
            title (str): Optional title to give to the :class:`~pystac.Link`
        """

        # Prevent typo confusion
        if isinstance(child, pystac.Item):
            raise STACError('Cannot add item as child. Use add_item instead.')

        child.set_root(self.get_root())
        child.set_parent(self)
        self.add_link(Link.child(child, title=title))
Example #3
0
 def add_child(self, child, title=None):
     child.set_root(self.get_root())
     child.set_parent(self)
     self.add_link(Link.child(child, title=title))