Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def child(c, title=None, link_type=LinkType.ABSOLUTE):
"""Creates a link to a child Catalog or Collection."""
return Link('child',
c,
title=title,
media_type='application/json',
link_type=link_type)
"""Adds a link to an :class:`~pystac.Item`.
This method will set the item's parent to this object, and its root to
this Catalog's root.
Args:
item (Item): The item to add.
title (str): Optional title to give to the :class:`~pystac.Link`
"""
# Prevent typo confusion
if isinstance(item, pystac.Catalog):
raise STACError('Cannot add catalog as item. Use add_child instead.')
item.set_root(self.get_root())
item.set_parent(self)
self.add_link(Link.item(item, title=title))
def add_source(self, source_item, title=None, assets=None):
"""Adds a link to a source item.
Args:
source_item (Item): Source imagery that the LabelItem applys to.
title (str): Optional title for the link.
assets (List[str]): Optional list of assets that deterime what
assets in the source item this label item data appliees to.
"""
properties = None
if assets is not None:
properties = {'label:assets': assets}
link = Link('source',
source_item,
title=title,
media_type='application/json',
properties=properties)
self.item.add_link(link)
version=version,
providers=providers,
properties=properties,
summaries=summaries)
has_self_link = False
for l in d['links']:
has_self_link |= l['rel'] == 'self'
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))
if not has_self_link and href is not None:
collection.add_link(Link.self_href(href))
return collection
def __init__(self, id, description, title=None, stac_extensions=None, href=None):
self.id = id
self.description = description
self.title = title
self.stac_extensions = stac_extensions
self.links = []
self.add_link(Link.root(self))
if href is not None:
self.set_self_href(href)
self._resolved_objects = ResolvedObjectCache()
self._resolved_objects.cache(self)
item = Item(id=id,
geometry=geometry,
bbox=bbox,
datetime=datetime,
properties=properties,
stac_extensions=stac_extensions,
collection=collection_id)
has_self_link = False
for l in d['links']:
has_self_link |= l['rel'] == 'self'
item.add_link(Link.from_dict(l))
if not has_self_link and href is not None:
item.add_link(Link.self_href(href))
for k, v in d['assets'].items():
asset = Asset.from_dict(v)
asset.set_owner(item)
item.assets[k] = asset
return item
d = copy(d)
rel = d.pop('rel')
href = d.pop('href')
media_type = d.pop('type', None)
title = d.pop('title', None)
properties = None
if any(d):
properties = d
if rel == 'self' or is_absolute_href(href):
link_type = LinkType.ABSOLUTE
else:
link_type = LinkType.RELATIVE
return Link(rel=rel,
target=href,
media_type=media_type,
title=title,
properties=properties,
link_type=link_type)
def set_self_href(self, href):
"""Sets the absolute HREF that is represented by the ``rel == 'self'``
:class:`~pystac.Link`.
Args:
str: The absolute HREF of this object. If the given HREF
is not absolute, it will be transformed to an absolute
HREF based on the current working directory.
"""
self.remove_links('self')
self.add_link(Link.self_href(href))
return self
Args:
collection (Collection): The collection to set as this item's 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.add_link(Link.collection(collection, link_type=link_type))
self.collection_id = collection.id
return self