Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add_item changes explicitly set links to fit the assumed structure #875

Closed
kylemann16 opened this issue Aug 16, 2022 · 1 comment · Fixed by #919
Closed

Add_item changes explicitly set links to fit the assumed structure #875

kylemann16 opened this issue Aug 16, 2022 · 1 comment · Fixed by #919

Comments

@kylemann16
Copy link

kylemann16 commented Aug 16, 2022

When using the add_item method on a catalog, pystac adjusts links for the dependent object to fit the expected STAC structure even if they're explicitly set and the catalog type is ABSOLUTE_PUBLISHED.

Expected: If explicit links are set and ABSOLUTE_PUBLISHED is the catalog type, they should be kept the same throughout all processes.
Actual: Adding items to ABSOLUTE_PUBLISHED catalogs changes explicit links to fit assumed file structure.

Example:

(Pdb) catalog.links
[<Link rel=root target=<Catalog id=Dublin>>, <Link rel=self target=https://{api_endpoint}/product/473/stac_catalog?access_token=>]
(Pdb) item.links
[<Link rel=self target=https://{api_endpoint}/raster/224/stac_item?access_token=>]
(Pdb) catalog.add_item(item)
(Pdb) catalog.links
[<Link rel=root target=<Catalog id=Dublin>>, <Link rel=self target=https://{api_endpoint}/product/473/stac_catalog?access_token=>, <Link rel=item target=<Item id=316000_234500>>]
(Pdb) item.links
[<Link rel=root target=<Catalog id=Dublin>>, <Link rel=parent target=<Catalog id=Dublin>>, <Link rel=self target=https://{api_endpoint}/product/473/316000_234500/316000_234500.json>]
(Pdb) catalog.links[2].href
'https://{api_endpoint}/product/473/316000_234500/316000_234500.json'

The link to the item in the catalog, as well as the self link in the item itself have been changed to mirror the assumed structure despite explicitly setting them to be something else.

The catalog for the above scenario is set as:

        catalog: Catalog = Catalog(
            id=name,
            description=f'{name} Catalog',
            href=href,
            catalog_type='ABSOLUTE_PUBLISHED'
        )

In order to add an explicit link, I have to do

item_link = Link(rel='item', target=item)
parent_link = Link(rel='parent', target=catalog)
root_link = Link(rel='root', target=catalog)

catalog.add_link(item_link)
item.add_link(parent_link)
item.add_link(root_link)
❯ pip show pystac
Name: pystac
Version: 1.6.1
Summary: Python library for working with Spatiotemporal Asset Catalog (STAC).
Home-page: https://github.com/stac-utils/pystac
Author: stac-utils
Author-email: [email protected]
License: Apache Software License 2.0
Location: {location}
Requires: python-dateutil
Required-by: 

Context: I've been implementing some STAC features for a team that wants to avoid writing it to storage for various reasons. What I've had to do is make endpoints on their server's api that generate catalogs and items when hit, and so the self links of items and catalogs needs to be explicitly set to these endpoints and not json files.

@kylemann16 kylemann16 changed the title Add_child, add_parent, and add_item change explicitly set links to fit the assumed structure Add_item changes explicitly set links to fit the assumed structure Aug 16, 2022
@gadomski gadomski mentioned this issue Nov 10, 2022
5 tasks
@gadomski
Copy link
Member

@kylemann16 I've added support for this in #919. From that branch, try:

from pystac.layout import AsIsLayoutStrategy
catalog.add_item(item, strategy=AsIsLayoutStrategy())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants