def set_collection(self, collection, link_type=None): """Set the collection of this item. This method will replace any existing Collection link and attribute for this item. Args: collection (Collection or None): The collection to set as this item's collection. If None, will clear the collection. link_type (str): the link type to use for the collection link. One of :class:`~pystac.LinkType`. Returns: Item: self """ if not link_type: prev = self.get_single_link('collection') if prev is not None: link_type = prev.link_type else: link_type = LinkType.ABSOLUTE self.remove_links('collection') self.collection_id = None if collection is not None: self.add_link(Link.collection(collection, link_type=link_type)) self.collection_id = collection.id return self
def set_collection(self, collection: Optional[Collection]) -> "Item": """Set the collection of this item. This method will replace any existing Collection link and attribute for this item. Args: collection : The collection to set as this item's collection. If None, will clear the collection. Returns: Item: self """ self.remove_links(pystac.RelType.COLLECTION) self.collection_id = None if collection is not None: self.add_link(Link.collection(collection)) self.collection_id = collection.id return self
def set_collection(self, collection): self.links = [l for l in self.links if l.rel != 'collection'] self.links.append(Link.collection(collection))