Skip to content

Absolute links in a self contained STAC Catalog Items #657

@pomadchin

Description

@pomadchin

Generation of a SELF_CONTAINED catalog produces all correct relative links in catalogs and collections but not in items.

Code example to reproduce:

import pystac
from datetime import datetime, timezone
from shapely.geometry import box, mapping

def tiny():
    # Create a catalog
    catalog = pystac.Catalog(id="example-catalog-id", description="descr")
    collection = pystac.Collection(
        "example-collection-id",
        "descr",
        pystac.Extent(
            spatial=pystac.SpatialExtent([[-180, -90, 180, 90]]),
            temporal=pystac.TemporalExtent(
                [[datetime(2020,7,3, tzinfo=timezone.utc), None]]
            ),
        ),
        license='proprietary'
    )

    item = pystac.Item(
        id="example-item-id",
        stac_extensions=[],
        geometry=mapping(box(0, 0, 90, 90)),
        bbox=[0, 0, 90, 90],
        datetime=datetime(2021,11,1),
        properties={}
    )

    collection.add_item(item)
    catalog.add_child(collection)
    catalog_path = './data/catalog/example-catalog'
    catalog.normalize_hrefs(catalog_path)
    catalog.validate_all()
    print(f'Saving catalog to {catalog_path}...')
    catalog.save(catalog_type=pystac.CatalogType.SELF_CONTAINED)
    print("Done!")

if __name__ == "__main__":
    tiny()

Item json in this case:

{
  "type": "Feature",
  "stac_version": "1.0.0",
  "id": "example-item-id",
  // ...
  "links": [
    {
      "rel": "root",
      "href": "/fullpath/data/catalog/example-catalog/example-collection-id/collection.json",
      "type": "application/json"
    },
    {
      "rel": "collection",
      "href": "/fullpath/data/catalog/example-catalog/example-collection-id/collection.json",
      "type": "application/json"
    },
    {
      "rel": "parent",
      "href": "/fullpath/data/catalog/example-catalog/example-collection-id/collection.json",
      "type": "application/json"
    }
  ],
  // ...
  "collection": "example-collection-id"
}

Gist with the same code, requirements.txt and the output example: https://gist.github.com/pomadchin/7c4c8365e1d3098956acc974f39a4cb6

I will try to prep a PR with a unit test to cover this case as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions